@secret-momo/utils 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/download/aria2.d.ts
CHANGED
|
@@ -3,12 +3,13 @@ import type { DownloadOptions, DownloadResult } from './types';
|
|
|
3
3
|
* 使用 aria2c 下载视频资源到指定目录。
|
|
4
4
|
*
|
|
5
5
|
* 下载前会检查本机是否安装 `aria2c`;若不存在会抛出异常,并提示通过
|
|
6
|
-
* `brew install aria2` 安装。下载时使用 `aria2c -x8 -s8 -k1M`
|
|
7
|
-
* referer,并根据 URL 或响应 `Content-Type` 推断视频扩展名。
|
|
6
|
+
* `brew install aria2` 安装。下载时使用 `aria2c -x8 -s8 -k1M` 参数;如提供
|
|
7
|
+
* referer,则将其传给 aria2c,并根据 URL 或响应 `Content-Type` 推断视频扩展名。
|
|
8
8
|
*
|
|
9
9
|
* @param options 下载配置
|
|
10
10
|
* @param options.url 视频资源 URL
|
|
11
11
|
* @param options.dir 资源保存目录,不存在时会自动创建
|
|
12
|
+
* @param options.referer 可选的请求 Referer
|
|
12
13
|
* @returns 下载成功后的文件路径,下载过程失败时返回 `null`
|
|
13
14
|
*/
|
|
14
|
-
export declare function aria2DownloadVideo({ url, dir }: DownloadOptions): Promise<DownloadResult>;
|
|
15
|
+
export declare function aria2DownloadVideo({ url, dir, referer, }: DownloadOptions): Promise<DownloadResult>;
|
package/lib/download/aria2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mkdirSync as
|
|
1
|
+
import{mkdirSync as m,existsSync as f}from"node:fs";import{rm as l}from"node:fs/promises";import{join as d,basename as p}from"node:path";import{execFile as w}from"node:child_process";import{promisify as E}from"node:util";import{dateTimeToNow as h}from"../date-time.js";import{fetch as y}from"../fetch.js";import{logger as D}from"../pino.js";import{pickVideoExtension as S}from"./extension.js";import{fileSize as g}from"../file.js";const u=E(w),c=D.child({name:"aria2DownloadVideo"});async function F(r,t){const o=[r,`${r}.aria2`].filter(a=>!t.has(a)),e=(await Promise.allSettled(o.map(a=>l(a,{force:!0})))).flatMap(a=>a.status==="rejected"?[a.reason]:[]);e.length>0&&c.error(new AggregateError(e,"\u6E05\u7406 aria2 \u4E0B\u8F7D\u4E2D\u95F4\u4EA7\u7269\u5931\u8D25"))}async function x(){try{await u("aria2c",["--version"])}catch(r){throw r.code==="ENOENT"?new Error("\u672A\u627E\u5230 aria2c \u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u5148\u4F7F\u7528 brew install aria2 \u5B89\u88C5\u3002",{cause:r}):r}}async function A(r){try{return(await y(r,{method:"HEAD"})).headers.get("content-type")}catch{return null}}async function M({url:r,dir:t,referer:o}){await x();let e;const a=new Set;try{m(t,{recursive:!0});const i=S(r,await A(r));e=d(t,`${h("YYYYMMDD_HHmmss")}.${i}`);for(const n of[e,`${e}.aria2`])f(n)&&a.add(n);const s=["-x8","-s8","-k1M","--auto-file-renaming=false",...o?["--referer",o]:[],"-d",t,"-o",p(e),r];return await u("aria2c",s),{isSuccess:!0,filePath:e,fileSize:await g(e)}}catch(i){return e&&await F(e,a),c.error(i),{isSuccess:!1,error:i}}}export{M as aria2DownloadVideo};
|
package/lib/download/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secret-momo/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"module": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"@eslint/config-helpers": "0.7.0",
|
|
39
39
|
"@eslint/js": "10.0.1",
|
|
40
40
|
"@types/bun": "1.4.0",
|
|
41
|
-
"eslint": "10.9.
|
|
41
|
+
"eslint": "10.9.1",
|
|
42
42
|
"eslint-plugin-import-x": "4.17.1",
|
|
43
43
|
"eslint-plugin-react": "7.37.5",
|
|
44
44
|
"eslint-plugin-react-hooks": "7.1.1",
|
|
45
45
|
"eslint-plugin-unused-imports": "4.4.1",
|
|
46
46
|
"husky": "9.1.7",
|
|
47
47
|
"jiti": "2.7.0",
|
|
48
|
-
"lint-staged": "17.
|
|
48
|
+
"lint-staged": "17.4.1",
|
|
49
49
|
"prettier": "3.9.6",
|
|
50
|
-
"rollup": "4.
|
|
50
|
+
"rollup": "4.63.1",
|
|
51
51
|
"rollup-plugin-esbuild": "6.2.1",
|
|
52
52
|
"typescript": "6.0.3",
|
|
53
|
-
"typescript-eslint": "8.
|
|
53
|
+
"typescript-eslint": "8.69.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"dayjs": "1.11.23",
|