Skip to content

Commit

Permalink
perf: upload zips downloaded to file.io
Browse files Browse the repository at this point in the history
  • Loading branch information
justorez committed Jan 31, 2024
1 parent fa122fa commit 605cf57
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 16 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
PICA_DL_SEARCH_KEYWORDS:
description: '搜索关键字,多个用 # 隔开'
type: string
OUTPUT_ZIP:
description: '每个章节打成独立压缩包'
type: boolean
default: true
PICA_DL_CONCURRENCY:
description: '下载并发数'
required: true
Expand Down Expand Up @@ -52,18 +56,24 @@ jobs:
node-version: 20
cache: 'pnpm'

- name: install deps
run: pnpm install
- name: install and build
run: |
pnpm install
pnpm run build
- name: download
run: pnpm run dev
run: pnpm start

- name: compress
run: pnpm run dev:zip
- if: inputs.OUTPUT_ZIP
name: compress
run: pnpm start:zip

- name: upload
- name: upload to github
uses: actions/upload-artifact@v4
with:
name: pica-comics
path: comics-zip/
retention-days: 10
path: ${{ inputs.OUTPUT_ZIP && 'comics-zip/' || 'comics/' }}
retention-days: 7

- name: upload to file.io
run: node scripts/upload.js
6 changes: 4 additions & 2 deletions package.json
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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
- 如果没有相关环境变量,则启动交互命令界面;若有则直接执行
- 通过 `pica-zip` 命令分章节批量压缩,配合支持 zip 包的漫画阅读软件使用,比如 [Perfect Viewer](https://play.google.com/store/apps/details?id=com.rookiestudio.perfectviewer)
不限于 `pica-cli` 下载的漫画使用,只要符合 [cmoics/漫画标题/漫画章节/漫画图片](#) 的目录结构即可。
- 借助 github action 实现飞速下载,同时将下好的漫画包上传到 github artifact 和 file.io(无需注册和科学上网)

如果用的开心,希望给个 star 支持一下,比心 ~ ❤️
如果用的开心,求个 star 支持一下,比心 ~ ❤️

## 用法

### 方式一:GitHub Actions(推荐)
### 方式一:GitHub Action(推荐)

利用 GitHub 的免费服务器下载,最关键的是不用科学上网,网速飞快,孩子用了都说好。
利用 github 的免费服务器下载,最关键的是不用科学上网,网速飞快,孩子用了都说好。

```bash
# 必填,固定值,不要修改
Expand All @@ -47,7 +48,7 @@ fork 一份本仓库,将上面三个环境变量,设置为仓库密钥:

![artifact](https://s2.loli.net/2024/01/30/MJBxVe9UtszNmiv.png)

如果你想自定义过程,比如不想把每个章节打成压缩包,请自行修改 [.github/workflows/task.yaml](.github/workflows/task.yaml)
如果你想自定义过程,请自行修改 [.github/workflows/task.yaml](.github/workflows/task.yaml)

### 方式二:直接安装

Expand Down Expand Up @@ -106,7 +107,8 @@ pnpm dev:zip

## 更新日志

- 2024/01/30 提供 GitHub Actions 的下载方式
- 2024/01/31 github action 同时将漫画包上传到 file.io
- 2024/01/30 提供 github action 的下载方式
- 2024/01/29 下载完成后,提供命令把漫画按章节批量压缩
- 2024/01/28 完成基本功能

Expand Down
54 changes: 54 additions & 0 deletions scripts/upload.js
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()
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"src/*": ["./src/*"]
}
},
"include": ["src/*.ts"]
"include": ["src/*.ts", "scripts/upload.ts"]
}

0 comments on commit 605cf57

Please sign in to comment.