-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): init cli upload moe resources
- Loading branch information
Showing
6 changed files
with
94 additions
and
41 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'node:path'; | ||
|
||
import type { FetchedResource } from 'animegarden'; | ||
|
||
export async function readResources(root: string) { | ||
const map = new Map<string, FetchedResource>(); | ||
const traverse = async (folder: string): Promise<void> => { | ||
const files = await fs.readdir(folder); | ||
await Promise.all( | ||
files.map(async (file) => { | ||
const stat = await fs.stat(path.join(folder, file)); | ||
if (stat.isDirectory()) { | ||
await traverse(path.join(folder, file)); | ||
} else if (stat.isFile() && file.endsWith('.json')) { | ||
const p = path.join(folder, file); | ||
const content = JSON.parse(await fs.readFile(p, 'utf-8')) as FetchedResource[]; | ||
for (const r of content) { | ||
if (!map.has(r.href)) { | ||
map.set(r.href, r); | ||
} | ||
} | ||
} | ||
}) | ||
); | ||
}; | ||
|
||
await traverse(root); | ||
return [...map.values()].sort((lhs, rhs) => rhs.createdAt.localeCompare(lhs.createdAt)); | ||
} |
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
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 |
---|---|---|
|
@@ -16,4 +16,5 @@ export async function insertMoeResources( | |
fetchedResources: FetchedResource[] | ||
) { | ||
// TODO | ||
return []; | ||
} |