add src folder
This commit is contained in:
1 parent
79673e55fe
commit
16f3e28690
9 files changed
+232
-204
No files matched your search
+27
-27
@@ -1,54 +1,54 @@
|
||||
import path from 'path'
|
||||
import path from 'path';
|
||||
|
||||
import axios from 'axios'
|
||||
import fs from 'fs/promises'
|
||||
import { nanoid } from 'nanoid'
|
||||
import axios from 'axios';
|
||||
import fs from 'fs/promises';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
const ROOTDIR = 'docs/assets'
|
||||
const ROOTDIR = 'docs/assets';
|
||||
|
||||
const log = {
|
||||
data: {} as Record<string, string>,
|
||||
filename: path.join(ROOTDIR, 'download-radical.json'),
|
||||
async load() {
|
||||
this.data = JSON.parse(await fs.readFile(this.filename, 'utf-8'))
|
||||
return this.data
|
||||
this.data = JSON.parse(await fs.readFile(this.filename, 'utf-8'));
|
||||
return this.data;
|
||||
},
|
||||
async dump() {
|
||||
await fs.writeFile(this.filename, JSON.stringify(this.data, null, 2))
|
||||
}
|
||||
}
|
||||
await fs.writeFile(this.filename, JSON.stringify(this.data, null, 2));
|
||||
},
|
||||
};
|
||||
|
||||
async function doDownloadRadical(url: string, note?: string) {
|
||||
const r = await axios.get(url, {
|
||||
responseType: 'arraybuffer'
|
||||
})
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
const filename = `${nanoid()}.png`
|
||||
await fs.writeFile(path.join(ROOTDIR, filename), r.data)
|
||||
const filename = `${nanoid()}.png`;
|
||||
await fs.writeFile(path.join(ROOTDIR, filename), r.data);
|
||||
|
||||
console.info(filename)
|
||||
console.info(filename);
|
||||
|
||||
if (note) {
|
||||
log.data[filename] = note
|
||||
log.data[filename] = note;
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadFromList(toBeDownloaded: Record<string, string>) {
|
||||
const chunkSize = 50
|
||||
const entries = Object.entries(toBeDownloaded)
|
||||
const chunkSize = 50;
|
||||
const entries = Object.entries(toBeDownloaded);
|
||||
for (let i = 0; i < entries.length; i += chunkSize) {
|
||||
await Promise.all(
|
||||
entries.slice(i, i + chunkSize).map(([k, v]) => doDownloadRadical(k, v))
|
||||
)
|
||||
entries.slice(i, i + chunkSize).map(([k, v]) => doDownloadRadical(k, v)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await log.load()
|
||||
await log.load();
|
||||
|
||||
const [, , url, ...parts] = process.argv
|
||||
const [, , url, ...parts] = process.argv;
|
||||
if (url) {
|
||||
await doDownloadRadical(url, parts.join(' '))
|
||||
await doDownloadRadical(url, parts.join(' '));
|
||||
} else {
|
||||
await downloadFromList({
|
||||
'https://git.polv.cc/attachments/d76f268a-8b40-4bba-ab24-e10de2e69f78':
|
||||
@@ -120,13 +120,13 @@ async function main() {
|
||||
'https://aws1.discourse-cdn.com/wanikanicommunity/original/4X/4/3/9/43978d49ccdc893a5ddd768790a9a84e0ad8c965.png':
|
||||
'Safety roof',
|
||||
'https://aws1.discourse-cdn.com/wanikanicommunity/original/4X/d/2/d/d2d27d66900c320ad70ee40a0985ee355a757f1e.png':
|
||||
'I have a scooter (Have scooter)'
|
||||
})
|
||||
'I have a scooter (Have scooter)',
|
||||
});
|
||||
}
|
||||
|
||||
await log.dump()
|
||||
await log.dump();
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main()
|
||||
main();
|
||||
}
|
||||
Reference in new issue
Block a user