forked from liruifengv/we-drawing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a310bd8
commit 0c33e9e
Showing
38 changed files
with
885 additions
and
1,178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
name: ci | ||
|
||
on: | ||
schedule: | ||
- cron: "0 23 * * *" | ||
schedule: | ||
- cron: "0 23 * * *" | ||
|
||
jobs: | ||
CreateImage: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
strategy: | ||
matrix: | ||
node-version: [18] | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false | ||
CreateImage: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
strategy: | ||
matrix: | ||
node-version: [18] | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install PNPM | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: ^7.0 | ||
- name: Install PNPM | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: ^7.0 | ||
|
||
- name: Install Deps | ||
run: pnpm install --no-frozen-lockfile | ||
- name: Install Deps | ||
run: pnpm install --no-frozen-lockfile | ||
|
||
- name: Build | ||
run: pnpm run build | ||
- name: Build | ||
run: pnpm run build | ||
|
||
- name: Create Image | ||
run: pnpm run start --cookie "${{ secrets.BING_COOKIE }}" | ||
- name: Create Image | ||
run: pnpm run start --cookie "${{ secrets.BING_COOKIE }}" | ||
|
||
- name: Push New Pic | ||
run: | | ||
git config --local user.email "liruifeng1024@gmail.com" | ||
git config --local user.name "${{ github.actor }}" | ||
git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | ||
git add . | ||
git commit -m "generated today pic" || echo "no need to commit " | ||
git push -f || echo "no file change" | ||
- name: Push New Pic | ||
run: | | ||
git config --local user.email "liruifeng1024@gmail.com" | ||
git config --local user.name "${{ github.actor }}" | ||
git remote set-url origin https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | ||
git add . | ||
git commit -m "generated today pic" || echo "no need to commit " | ||
git push -f || echo "no file change" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.DS_Store | ||
node_modules | ||
/build | ||
/dist | ||
/package | ||
.env | ||
.env.* | ||
!.env.example | ||
|
||
# Ignore files for PNPM, NPM and YARN | ||
pnpm-lock.yaml | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/prettierrc.json", | ||
"semi": true, | ||
"trailingComma": "all", | ||
"singleQuote": false, | ||
"tabWidth": 4, | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,76 @@ | ||
|
||
import { getImageBySentence } from '../src/get-up'; | ||
import type { Response } from '../src/types'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import stream from 'stream'; | ||
import { promisify } from 'util'; | ||
import { getImageBySentence } from "../src/get-up"; | ||
import type { Response } from "../src/types"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
import stream from "stream"; | ||
import { promisify } from "util"; | ||
|
||
const pipeline = promisify(stream.pipeline); | ||
|
||
async function init() { | ||
const cwd = process.cwd(); | ||
const cwd = process.cwd(); | ||
|
||
const argv = require("minimist")(process.argv.slice(2)); | ||
|
||
if (argv.cookie) { | ||
try { | ||
const res: Response = await getImageBySentence(argv.cookie); | ||
console.log("Create Successful: ", res); | ||
|
||
const argv = require('minimist')(process.argv.slice(2)); | ||
|
||
if (argv.cookie) { | ||
try { | ||
const res: Response = await getImageBySentence(argv.cookie); | ||
console.log("Create Successful: ", res); | ||
|
||
const outputPath = path.join(cwd, 'website/public'); | ||
const outputPath = path.join(cwd, "website/public"); | ||
|
||
const imagesPath = path.join(outputPath, 'images'); | ||
if (!fs.existsSync(imagesPath)) { | ||
fs.mkdirSync(imagesPath); | ||
} | ||
const imagesPath = path.join(outputPath, "images"); | ||
if (!fs.existsSync(imagesPath)) { | ||
fs.mkdirSync(imagesPath); | ||
} | ||
|
||
// 在 images 目录下,创建一个以时间戳命名的文件夹,将图片放入其中 | ||
const imagesFolderName = Date.now().toString(); | ||
const imagesFolderPath = path.join(imagesPath, imagesFolderName); | ||
if (!fs.existsSync(imagesFolderPath)) { | ||
fs.mkdirSync(imagesFolderPath); | ||
} | ||
// 在 images 目录下,创建一个以时间戳命名的文件夹,将图片放入其中 | ||
const imagesFolderName = Date.now().toString(); | ||
const imagesFolderPath = path.join(imagesPath, imagesFolderName); | ||
if (!fs.existsSync(imagesFolderPath)) { | ||
fs.mkdirSync(imagesFolderPath); | ||
} | ||
|
||
// 将图片放入 images 目录下的文件夹中 | ||
res.images.forEach((image, index) => { | ||
// images 中是网络url,请求图片,将图片保存到 images 目录下的文件夹中 | ||
const imageFileName = `${index}.jpg`; | ||
const imageFilePath = path.join(imagesFolderPath, imageFileName); | ||
// 将图片放入 images 目录下的文件夹中 | ||
res.images.forEach((image, index) => { | ||
// images 中是网络url,请求图片,将图片保存到 images 目录下的文件夹中 | ||
const imageFileName = `${index}.jpg`; | ||
const imageFilePath = path.join(imagesFolderPath, imageFileName); | ||
|
||
// 下载图片 | ||
fetch(image).then(res => { | ||
if (!res.ok) throw new Error(`unexpected response ${res.statusText}`); | ||
// @ts-ignore | ||
pipeline(res.body, fs.createWriteStream(imageFilePath)) | ||
.catch(e => { | ||
console.error('Something went wrong while saving the image', e); | ||
// 下载图片 | ||
fetch(image).then((res) => { | ||
if (!res.ok) throw new Error(`unexpected response ${res.statusText}`); | ||
// @ts-ignore | ||
pipeline(res.body, fs.createWriteStream(imageFilePath)).catch((e) => { | ||
console.error("Something went wrong while saving the image", e); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
const options = { timeZone: 'Asia/Shanghai', hour12: false }; | ||
const outputData = { | ||
...res, | ||
date: new Date().toLocaleString("zh-CN", options), | ||
localImagesPath: imagesFolderName, | ||
} | ||
const options = { timeZone: "Asia/Shanghai", hour12: false }; | ||
const outputData = { | ||
...res, | ||
date: new Date().toLocaleString("zh-CN", options), | ||
localImagesPath: imagesFolderName, | ||
}; | ||
|
||
const contentPath = path.join(cwd, 'website/src/content/images'); | ||
const contentPath = path.join(cwd, "website/src/content/images"); | ||
|
||
const contentFile = path.join(contentPath, `${imagesFolderName}.json`); | ||
const contentFile = path.join(contentPath, `${imagesFolderName}.json`); | ||
|
||
fs.writeFileSync(contentFile, JSON.stringify(outputData)); | ||
fs.writeFileSync(contentFile, JSON.stringify(outputData)); | ||
|
||
setTimeout(() => { // 为了让图片下载完毕,再退出进程 | ||
process.exit(0); | ||
}, 5000); | ||
} catch (e) { | ||
throw e | ||
setTimeout(() => { | ||
// 为了让图片下载完毕,再退出进程 | ||
process.exit(0); | ||
}, 5000); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} else { | ||
throw new Error("Please provide a cookie using the --cookie argument"); | ||
} | ||
} else { | ||
throw new Error('Please provide a cookie using the --cookie argument'); | ||
} | ||
} | ||
|
||
init().catch((e) => { | ||
console.error(e); | ||
}); | ||
console.error(e); | ||
}); |
Oops, something went wrong.