Skip to content

Commit ab0c221

Browse files
committed
add Anime-Girls-Holding-Programming-Books-710px-width-to-json
1 parent ddd9a97 commit ab0c221

File tree

4 files changed

+401
-0
lines changed

4 files changed

+401
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Update Anime-Girls-Holding-Programming-Books-710px-width.json to Gist
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
update-gist:
8+
runs-on: ubuntu-latest
9+
10+
env:
11+
TOKEN_OF_GITHUB_GIST: ${{ secrets.TOKEN_OF_GITHUB_GIST }}
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
cache: 'npm'
22+
cache-dependency-path: 'scripts/Anime-Girls-Holding-Programming-Books-710px-width-to-json/package-lock.json'
23+
24+
- name: Install dependencies
25+
run: npm install --prefix scripts/Anime-Girls-Holding-Programming-Books-710px-width-to-json
26+
27+
- name: Run update gist script
28+
run: node scripts/Anime-Girls-Holding-Programming-Books-710px-width-to-json/index.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import axios from "axios";
2+
3+
const GITHUB_REPOS_API_URL =
4+
"https://api.github.com/repos/tangjan/Anime-Girls-Holding-Programming-Books-710px-width/contents";
5+
const GITHUB_GIST_API_URL =
6+
"https://api.github.com/gists/ceb852425be20b772ee2625d9b5ee606";
7+
8+
const githubApiUrl = axios.create({
9+
headers: {
10+
Authorization: `token ${process.env.TOKEN_OF_GITHUB_GIST}`,
11+
},
12+
});
13+
14+
async function getRepoContents(path = "", images = []) {
15+
try {
16+
const encodedPath = path ? encodeURIComponent(path) : "";
17+
const url = encodedPath
18+
? `${GITHUB_REPOS_API_URL}/${encodedPath}`
19+
: GITHUB_REPOS_API_URL;
20+
21+
console.log(`正在请求: ${url}`);
22+
const { data } = await githubApiUrl.get(url);
23+
24+
if (Array.isArray(data)) {
25+
for (const item of data) {
26+
if (item.type === "dir") {
27+
await getRepoContents(item.path, images); // 递归
28+
} else if (
29+
item.type === "file" &&
30+
/\.(jpg|jpeg|png|gif)$/i.test(item.name)
31+
) {
32+
images.push(item.download_url);
33+
}
34+
}
35+
}
36+
} catch (error) {
37+
console.error(`获取路径 ${path} 的内容时出错:`, error.message);
38+
}
39+
}
40+
41+
async function updateGist(content) {
42+
try {
43+
await githubApiUrl.patch(GITHUB_GIST_API_URL, {
44+
files: {
45+
"Anime-Girls-Holding-Programming-Books-710px-width.json": {
46+
content: JSON.stringify(content, null, 2),
47+
},
48+
},
49+
});
50+
console.log("🎉 处理完成,数据已更新到 GitHub Gist:", GITHUB_GIST_API_URL);
51+
} catch (error) {
52+
console.error("更新 Gist 时出错:", error.message);
53+
throw error;
54+
}
55+
}
56+
57+
async function main() {
58+
try {
59+
const images = [];
60+
await getRepoContents("", images);
61+
62+
const result = {
63+
last_updated: new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString(), // UTC+8
64+
source:
65+
"https://github.com/tangjan/Anime-Girls-Holding-Programming-Books-710px-width",
66+
count: images.length,
67+
images: images,
68+
};
69+
70+
await updateGist(result);
71+
} catch (error) {
72+
console.error(error.message);
73+
}
74+
}
75+
76+
main();

scripts/Anime-Girls-Holding-Programming-Books-710px-width-to-json/package-lock.json

+282
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)