Skip to content

Commit

Permalink
Update doujin-meta source
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Feb 1, 2023
1 parent 9bc775d commit 4fab4e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "touhou-tagger",
"version": "1.5.3",
"version": "1.5.4",
"description": "从 THBWiki 自动填写东方 Project CD 曲目信息.",
"main": "dist/core/index.js",
"bin": {
Expand Down
31 changes: 22 additions & 9 deletions src/core/metadata/doujin-meta/doujin-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,32 @@ interface BlobResponse {
encoding: string
}

const goToFolder = async (path: string) => {
const mainTreeApi = `https://api.github.com/repos/${owner}/${repo}/git/trees/main`
const { data: mainTree } = await githubApi.get<TreeResponse>(mainTreeApi)
const segments = path.split('/')
let currentTree = mainTree
for (let index = 0; index < segments.length; index++) {
const segment = segments[index]
if (!segment) {
continue
}
const nextFolder = currentTree.tree.find(it => it.path === segment)
if (!nextFolder) {
throw new Error(`获取 ${segment} 文件夹失败`)
}
const { data: nextTree } = await githubApi.get<TreeResponse>(nextFolder.url)
currentTree = nextTree
}
return currentTree
}

export class DoujinMeta extends MetadataSource {
private dataTree: Promise<TreeResponse>
private fuse: Promise<Fuse<GitTreeNode>>

private async getDataTree() {
const mainTreeApi = `https://api.github.com/repos/${owner}/${repo}/git/trees/main`
const { data: mainTree } = await githubApi.get<TreeResponse>(mainTreeApi)
const dataFolder = mainTree.tree.find(it => it.path === 'data')
if (!dataFolder) {
throw new Error('获取 data 文件夹失败')
}
const { data: dataTree } = await githubApi.get<TreeResponse>(dataFolder.url)
return dataTree
private getDataTree() {
return goToFolder('public/data')
}

private init() {
Expand Down

0 comments on commit 4fab4e7

Please sign in to comment.