-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: upload zips downloaded to file.io
- Loading branch information
Showing
6 changed files
with
93 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "pica-cli", | ||
"author": "justorez", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "😉 哔咔漫画下载器", | ||
"packageManager": "[email protected]", | ||
"type": "module", | ||
|
@@ -13,7 +13,8 @@ | |
"postinstall": "simple-git-hooks", | ||
"dev": "tsx src/index.ts", | ||
"dev:zip": "tsx src/zip.ts", | ||
"start": "pnpm build && node dist/index.js", | ||
"start": "node dist/index.js", | ||
"start:zip": "node dist/zip.js", | ||
"build": "rimraf dist && rollup --config rollup.config.js", | ||
"test": "vitest", | ||
"pub": "pnpm build && pnpm publish", | ||
|
@@ -86,6 +87,7 @@ | |
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"lint-staged": "^15.2.0", | ||
"mime": "^4.0.1", | ||
"ora": "^8.0.1", | ||
"p-limit": "^5.0.0", | ||
"picocolors": "^1.0.0", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,54 @@ | ||
import fs from 'node:fs/promises' | ||
import { existsSync } from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import axios from 'axios' | ||
import mime from 'mime' | ||
import AdmZip from 'adm-zip' | ||
import pico from 'picocolors' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
const MAX_SIZE = 2 * 1024 * 1024 * 1024 // 2GB | ||
|
||
// https://file.io/ | ||
async function main() { | ||
let root = path.resolve(__dirname, '../comics-zip') | ||
|
||
if (!existsSync(root)) { | ||
root = path.resolve(__dirname, '../comics') | ||
if (!existsSync(root)) { | ||
console.log(pico.yellow('没有发现已下载的漫画')) | ||
return | ||
} | ||
} | ||
|
||
const comics = await fs.readdir(root) | ||
const task = comics.map(async (comic) => { | ||
try { | ||
const zip = new AdmZip() | ||
await zip.addLocalFolderPromise(path.join(root, comic)) | ||
const zipBuffer = await zip.toBufferPromise() | ||
|
||
if (zipBuffer.byteLength < MAX_SIZE) { | ||
const filename = `${comic}.zip` | ||
const file = new File([zipBuffer], filename, { | ||
type: mime.getType('zip') | ||
}) | ||
const form = new FormData() | ||
form.append('file', file) | ||
const { data } = await axios.post( | ||
`https://file.io?title=${filename}`, | ||
form | ||
) | ||
console.log( | ||
`${pico.cyan(comic)} 已上传到 file.io. 下载地址:${pico.green(data.link)}` | ||
) | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
}) | ||
return Promise.allSettled(task) | ||
} | ||
|
||
main() |
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,5 +16,5 @@ | |
"src/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["src/*.ts"] | ||
"include": ["src/*.ts", "scripts/upload.ts"] | ||
} |