dsh-bilibili-upload 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +51 -2
- package/client.js +116 -0
- package/cordis.patch.yml +6 -0
- package/index.js +171 -0
- package/lib/args.mjs +50 -0
- package/lib/config.mjs +30 -0
- package/lib/edit.mjs +90 -0
- package/lib/upload.mjs +56 -0
- package/package.json +54 -4
- package/ui-route.js +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fubai-fenzhi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-bilibili-upload
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
鎶婅棰戜粠 DSH 涓婁紶/缂栬緫鍒?B 绔欙紝搴曞眰鐢?[biliup](https://github.com/biliup/biliup) CLI銆?
|
|
4
|
+
## 鍓嶆彁
|
|
5
|
+
|
|
6
|
+
1. 瀹夎 biliup锛圵indows 鐢?`biliupR-*-x86_64-windows.zip`锛岃В鍘嬪嵆鐢級
|
|
7
|
+
2. 鍦?biliup 鐩綍杩愯涓€娆?`biliup login`锛屾墜鏈烘壂鐮佺櫥褰曪紙鐢熸垚 `cookies.json`锛?3. 鎻掍欢榛樿鎸囧悜宸茶璺緞锛坄biliupPath` 鍙敼锛?
|
|
8
|
+
## 宸ュ叿
|
|
9
|
+
|
|
10
|
+
### `bili_upload`
|
|
11
|
+
|
|
12
|
+
| 鍙傛暟 | 璇存槑 |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `video` | 瑙嗛缁濆璺緞锛堝繀濉級 |
|
|
15
|
+
| `title` | 鏍囬锛堝繀濉紝绾?80 瀛楀唴锛?|
|
|
16
|
+
| `desc` | 绠€浠?|
|
|
17
|
+
| `tags` | 鏍囩鏁扮粍锛岄粯璁ょ敤閰嶇疆 |
|
|
18
|
+
| `cover` | 灏侀潰鍥剧粷瀵硅矾寰勶紙4:3 鎴?16:9锛?|
|
|
19
|
+
| `tid` | 鍒嗗尯锛岄粯璁?188锛堢鎶€鈫掕绠楁満鎶€鏈級 |
|
|
20
|
+
| `submit` | 鎻愪氦鎺ュ彛锛岄粯璁?**web**锛堝垎鍖烘槧灏勬洿鍑嗭紱app 浼氭妸 188 鍙樻垚 21锛?|
|
|
21
|
+
| `onlySelf` | `true`锛堥粯璁わ級= 浠呰嚜宸卞彲瑙侊紱`false` = 鍏紑 |
|
|
22
|
+
| `dryRun` | 鍙洖鏄惧懡浠わ紝涓嶄笂浼?|
|
|
23
|
+
|
|
24
|
+
### `bili_edit`
|
|
25
|
+
|
|
26
|
+
鏀瑰凡涓婁紶绋夸欢鐨勬爣棰?鍒嗗尯/鏍囩/绠€浠?鍙鎬э紙璧?B 绔欏畼鏂圭紪杈戞帴鍙o紝闇€瑕佹湰鏈?cookies锛夈€?
|
|
27
|
+
- 瀹℃牳涓紙state -50锛変細鎷掔粷骞舵彁绀虹◢鍚庨噸璇?- 鏀瑰畬鑷姩鍥炶鐘舵€?
|
|
28
|
+
### `bili_check`
|
|
29
|
+
|
|
30
|
+
妫€鏌?biliup 璺緞銆佺櫥褰?cookie锛涘彲閫変紶 BV 鍙风湅绋夸欢銆?
|
|
31
|
+
## 闈㈡澘
|
|
32
|
+
|
|
33
|
+
璁剧疆 鈫?鎻掍欢 鈫?**B 绔欎笂浼?*锛氬~瑙嗛/鏍囬/绠€浠?鏍囩/灏侀潰/鍒嗗尯锛屽嬀閫夊彲瑙佹€э紝涓€閿笂浼狅紱涓嬫柟鍙敼宸叉湁 BV 鐨勬爣棰?鍙鎬с€?
|
|
34
|
+
璺敱锛歚/bili-upload/state`銆乣/bili-upload/upload`銆乣/bili-upload/edit`銆?
|
|
35
|
+
## 閰嶇疆
|
|
36
|
+
|
|
37
|
+
```yaml
|
|
38
|
+
- id: bili-upload
|
|
39
|
+
name: dsh-bilibili-upload
|
|
40
|
+
config:
|
|
41
|
+
biliupPath: 'E:\Tools\biliup\biliupR-v1.3.5-x86_64-windows\biliup.exe'
|
|
42
|
+
defaultTid: 188
|
|
43
|
+
defaultTags: [DeepSeek Harness, DSH, 鎻掍欢]
|
|
44
|
+
defaultOnlySelf: true
|
|
45
|
+
defaultSubmit: web
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 瀹夊叏
|
|
49
|
+
|
|
50
|
+
- cookie 鍙瓨鏈満锛坆iliup 鐩綍锛夛紝涓嶈繘浠撳簱
|
|
51
|
+
- 榛樿浠呰嚜宸卞彲瑙侊紝閬垮厤璇叕寮€
|
|
52
|
+
- 鍙敤浜庝綘鑷繁鐨勮处鍙凤紝閬靛畧 B 绔欐姇绋胯鑼?
|
package/client.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-bilibili-upload',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
|
|
7
|
+
const fieldStyle = { display: 'grid', gap: '2px', fontSize: '12px' };
|
|
8
|
+
const inputStyle = { padding: '4px 6px', fontSize: '12px', width: '100%', boxSizing: 'border-box' };
|
|
9
|
+
const mono = { fontFamily: 'monospace', fontSize: '12px', whiteSpace: 'pre-wrap' };
|
|
10
|
+
|
|
11
|
+
function Panel() {
|
|
12
|
+
const [state, setState] = React.useState(null);
|
|
13
|
+
const [video, setVideo] = React.useState('');
|
|
14
|
+
const [title, setTitle] = React.useState('');
|
|
15
|
+
const [desc, setDesc] = React.useState('');
|
|
16
|
+
const [tags, setTags] = React.useState('');
|
|
17
|
+
const [cover, setCover] = React.useState('');
|
|
18
|
+
const [tid, setTid] = React.useState('188');
|
|
19
|
+
const [submit, setSubmit] = React.useState('web');
|
|
20
|
+
const [onlySelf, setOnlySelf] = React.useState(true);
|
|
21
|
+
const [busy, setBusy] = React.useState(false);
|
|
22
|
+
const [result, setResult] = React.useState('');
|
|
23
|
+
|
|
24
|
+
const [bvid, setBvid] = React.useState('');
|
|
25
|
+
const [editTitle, setEditTitle] = React.useState('');
|
|
26
|
+
const [editOnlySelf, setEditOnlySelf] = React.useState(false);
|
|
27
|
+
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
fetch('/bili-upload/state')
|
|
30
|
+
.then((response) => response.json())
|
|
31
|
+
.then(setState)
|
|
32
|
+
.catch(() => setState({ biliup: false, cookies: false }));
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
async function post(url, body) {
|
|
36
|
+
setBusy(true);
|
|
37
|
+
setResult('');
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(url, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify(body),
|
|
43
|
+
});
|
|
44
|
+
const data = await response.json();
|
|
45
|
+
setResult(JSON.stringify(data, null, 2));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
setResult(String(error));
|
|
48
|
+
} finally {
|
|
49
|
+
setBusy(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const upload = () => post('/bili-upload/upload', {
|
|
54
|
+
video,
|
|
55
|
+
title,
|
|
56
|
+
desc,
|
|
57
|
+
tags: tags.split(',').map((item) => item.trim()).filter(Boolean),
|
|
58
|
+
cover,
|
|
59
|
+
tid: Number.parseInt(tid, 10) || 188,
|
|
60
|
+
submit,
|
|
61
|
+
onlySelf,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const edit = () => post('/bili-upload/edit', {
|
|
65
|
+
bvid,
|
|
66
|
+
title: editTitle || undefined,
|
|
67
|
+
onlySelf: editOnlySelf,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return h('div', { style: { padding: '16px', display: 'grid', gap: '10px', fontSize: '13px' } },
|
|
71
|
+
h('h3', { style: { margin: 0 } }, 'B 绔欎笂浼?路 dsh-bili-upload'),
|
|
72
|
+
h('div', { style: { fontSize: '12px', opacity: 0.75 } },
|
|
73
|
+
state
|
|
74
|
+
? `biliup ${state.biliup ? '鉁? : '鉂?鏈壘鍒?}銆€cookies ${state.cookies ? '鉁?宸茬櫥褰? : '鉂?鏈櫥褰?}`
|
|
75
|
+
: '妫€鏌ョ姸鎬佷腑鈥?),
|
|
76
|
+
h('div', { style: fieldStyle }, h('span', null, '瑙嗛璺緞'), h('input', { style: inputStyle, value: video, onChange: (e) => setVideo(e.target.value), placeholder: 'E:\\...\\video.mp4' })),
|
|
77
|
+
h('div', { style: fieldStyle }, h('span', null, '鏍囬'), h('input', { style: inputStyle, value: title, onChange: (e) => setTitle(e.target.value) })),
|
|
78
|
+
h('div', { style: fieldStyle }, h('span', null, '绠€浠?), h('textarea', { style: { ...inputStyle, minHeight: '60px' }, value: desc, onChange: (e) => setDesc(e.target.value) })),
|
|
79
|
+
h('div', { style: fieldStyle }, h('span', null, '鏍囩锛堥€楀彿鍒嗛殧锛?), h('input', { style: inputStyle, value: tags, onChange: (e) => setTags(e.target.value), placeholder: 'DeepSeek Harness,DSH,鎻掍欢' })),
|
|
80
|
+
h('div', { style: fieldStyle }, h('span', null, '灏侀潰璺緞锛堝彲閫夛級'), h('input', { style: inputStyle, value: cover, onChange: (e) => setCover(e.target.value) })),
|
|
81
|
+
h('div', { style: { display: 'flex', gap: '12px', alignItems: 'end' } },
|
|
82
|
+
h('div', { style: { ...fieldStyle, flex: '1' } }, h('span', null, '鍒嗗尯 tid'), h('input', { style: inputStyle, value: tid, onChange: (e) => setTid(e.target.value) })),
|
|
83
|
+
h('div', { style: { ...fieldStyle, flex: '1' } }, h('span', null, '鎻愪氦鎺ュ彛'), h('select', { style: inputStyle, value: submit, onChange: (e) => setSubmit(e.target.value) },
|
|
84
|
+
h('option', { value: 'app' }, 'app'),
|
|
85
|
+
h('option', { value: 'web' }, 'web'))),
|
|
86
|
+
h('label', { style: { display: 'flex', gap: '4px', alignItems: 'center', fontSize: '12px' } },
|
|
87
|
+
h('input', { type: 'checkbox', checked: onlySelf, onChange: (e) => setOnlySelf(e.target.checked) }),
|
|
88
|
+
'浠呰嚜宸卞彲瑙?)),
|
|
89
|
+
h('div', null, h('button', { onClick: upload, disabled: busy }, busy ? '澶勭悊涓€? : '涓婁紶瑙嗛')),
|
|
90
|
+
h('hr', { style: { borderColor: 'rgba(127,127,127,.3)' } }),
|
|
91
|
+
h('div', { style: { display: 'flex', gap: '10px' } },
|
|
92
|
+
h('div', { style: { ...fieldStyle, flex: '1' } }, h('span', null, 'BV 鍙凤紙缂栬緫锛?), h('input', { style: inputStyle, value: bvid, onChange: (e) => setBvid(e.target.value), placeholder: 'BV...' })),
|
|
93
|
+
h('div', { style: { ...fieldStyle, flex: '1' } }, h('span', null, '鏂版爣棰橈紙鍙€夛級'), h('input', { style: inputStyle, value: editTitle, onChange: (e) => setEditTitle(e.target.value) }))),
|
|
94
|
+
h('div', { style: { display: 'flex', gap: '12px', alignItems: 'center' } },
|
|
95
|
+
h('label', { style: { display: 'flex', gap: '4px', alignItems: 'center', fontSize: '12px' } },
|
|
96
|
+
h('input', { type: 'checkbox', checked: editOnlySelf, onChange: (e) => setEditOnlySelf(e.target.checked) }),
|
|
97
|
+
'璁句负浠呰嚜宸卞彲瑙侊紙涓嶅嬀=鍏紑锛?),
|
|
98
|
+
h('button', { onClick: edit, disabled: busy }, '缂栬緫绋夸欢')),
|
|
99
|
+
result ? h('pre', { style: { ...mono, maxHeight: '220px', overflow: 'auto', background: 'rgba(127,127,127,.1)', padding: '8px', borderRadius: '6px' } }, result) : null,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
inject: ['slots'],
|
|
105
|
+
apply(ctx) {
|
|
106
|
+
ctx.slots.inject('settings.plugins.tab', () => ctx.slots.register({
|
|
107
|
+
name: 'settings.plugins.tab',
|
|
108
|
+
id: 'bili-upload',
|
|
109
|
+
order: 52,
|
|
110
|
+
label: 'B 绔欎笂浼?,
|
|
111
|
+
}, Panel));
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
package/cordis.patch.yml
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
import { normalizeTags } from './lib/args.mjs';
|
|
4
|
+
import { normalizeConfig } from './lib/config.mjs';
|
|
5
|
+
import { editArchive, showArchive } from './lib/edit.mjs';
|
|
6
|
+
import { runBiliup, uploadVideo } from './lib/upload.mjs';
|
|
7
|
+
|
|
8
|
+
export const name = 'dsh-bilibili-upload';
|
|
9
|
+
export const inject = ['tools'];
|
|
10
|
+
|
|
11
|
+
const textOutput = {
|
|
12
|
+
schema: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
required: ['text'],
|
|
16
|
+
properties: { text: { type: 'string' } },
|
|
17
|
+
},
|
|
18
|
+
render: (_args, value) => [{ type: 'text', text: value.text }],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const present = (title) => (args) => ({ card: 'generic', title, kind: 'other', rawInput: args });
|
|
22
|
+
|
|
23
|
+
function objectSchema(properties, required = []) {
|
|
24
|
+
return { type: 'object', additionalProperties: false, properties, required };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function tail(text, lines = 30) {
|
|
28
|
+
return String(text ?? '').trimEnd().split('\n').slice(-lines).join('\n');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function apply(ctx, config) {
|
|
32
|
+
const cfg = normalizeConfig(config);
|
|
33
|
+
|
|
34
|
+
ctx.tools.register({
|
|
35
|
+
name: 'bili_upload',
|
|
36
|
+
description: 'Upload a video to Bilibili through biliup (requires a one-time `biliup login`). Defaults to private (浠呰嚜宸卞彲瑙? for safety; pass onlySelf=false to publish publicly. Returns BV id on success.',
|
|
37
|
+
parameters: objectSchema({
|
|
38
|
+
video: { type: 'string', description: 'Absolute path to the video file.' },
|
|
39
|
+
title: { type: 'string', description: 'Video title (Bilibili limit about 80 chars).' },
|
|
40
|
+
desc: { type: 'string', description: 'Video description.' },
|
|
41
|
+
tags: { type: 'array', items: { type: 'string' }, description: 'Tags; defaults to the configured defaultTags.' },
|
|
42
|
+
cover: { type: 'string', description: 'Optional absolute cover image path (4:3 or 16:9).' },
|
|
43
|
+
tid: { type: 'integer', description: 'Partition id; default 188 (绉戞妧 鈫?璁$畻鏈烘妧鏈?.' },
|
|
44
|
+
submit: { type: 'string', enum: ['app', 'web', 'b-cut-android'], description: 'Submission API; default web (web keeps the requested partition, app maps 188 to 21).' },
|
|
45
|
+
onlySelf: { type: 'boolean', description: 'true (default) keeps it private (浠呰嚜宸卞彲瑙?; false publishes publicly.' },
|
|
46
|
+
dryRun: { type: 'boolean', description: 'Only return the biliup command; do not upload.' },
|
|
47
|
+
}, ['video', 'title']),
|
|
48
|
+
output: textOutput,
|
|
49
|
+
async execute(args) {
|
|
50
|
+
const video = typeof args.video === 'string' ? args.video.trim() : '';
|
|
51
|
+
if (!video) throw new Error('video 涓嶈兘涓虹┖');
|
|
52
|
+
if (!existsSync(video)) throw new Error(`瑙嗛涓嶅瓨鍦細${video}`);
|
|
53
|
+
const cover = typeof args.cover === 'string' && args.cover.trim() ? args.cover.trim() : '';
|
|
54
|
+
if (cover && !existsSync(cover)) throw new Error(`灏侀潰涓嶅瓨鍦細${cover}`);
|
|
55
|
+
if (!cfg.biliupPath) throw new Error('鏈厤缃?biliupPath锛氳鍦ㄦ彃浠堕厤缃噷濉啓 biliup 鍙墽琛屾枃浠惰矾寰勶紝鎴栬缃?BILIUP_PATH 鐜鍙橀噺');
|
|
56
|
+
if (!existsSync(cfg.biliupPath)) throw new Error(`鎵句笉鍒?biliup锛?{cfg.biliupPath}`);
|
|
57
|
+
if (!existsSync(cfg.cookiePath)) throw new Error(`鏈櫥褰曪細鎵句笉鍒?${cfg.cookiePath}銆傝鍏堝湪 biliup 鐩綍杩愯 login.bat锛坆iliup login锛夋壂鐮乣);
|
|
58
|
+
|
|
59
|
+
const onlySelf = args.onlySelf ?? cfg.defaultOnlySelf;
|
|
60
|
+
const tags = normalizeTags(args.tags && args.tags.length ? args.tags : cfg.defaultTags);
|
|
61
|
+
const submit = args.submit ?? cfg.defaultSubmit;
|
|
62
|
+
|
|
63
|
+
if (args.dryRun) {
|
|
64
|
+
return { text: `dry-run:\n${cfg.biliupPath} upload ${video} --title ${args.title} --desc ${args.desc ?? ''} --tag ${tags} --tid ${args.tid ?? cfg.defaultTid} --copyright 1 --submit ${submit}${cover ? ` --cover ${cover}` : ''}${onlySelf ? ' --is-only-self 1' : ''}` };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const result = await uploadVideo({
|
|
68
|
+
biliupPath: cfg.biliupPath,
|
|
69
|
+
video,
|
|
70
|
+
title: args.title,
|
|
71
|
+
desc: args.desc ?? '',
|
|
72
|
+
tags,
|
|
73
|
+
cover,
|
|
74
|
+
tid: args.tid ?? cfg.defaultTid,
|
|
75
|
+
onlySelf,
|
|
76
|
+
submit,
|
|
77
|
+
timeoutMs: cfg.timeoutMs,
|
|
78
|
+
});
|
|
79
|
+
const lines = [
|
|
80
|
+
result.ok ? `涓婁紶鎴愬姛锛?{result.bvid}${result.aid ? `锛坅id ${result.aid}锛塦 : ''}` : `涓婁紶澶辫触锛坋xit ${result.code}锛塦,
|
|
81
|
+
`鍙鎬э細${onlySelf ? '浠呰嚜宸卞彲瑙侊紙鍘诲垱浣滀腑蹇冩敼鍏紑锛屾垨鐢?bili_edit锛? : '鍏紑'}`,
|
|
82
|
+
];
|
|
83
|
+
if (!result.ok) lines.push('--- stdout ---', tail(result.stdout), '--- stderr ---', tail(result.stderr));
|
|
84
|
+
return { text: lines.join('\n') };
|
|
85
|
+
},
|
|
86
|
+
presentCall: present('涓婁紶瑙嗛鍒?B 绔?),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
ctx.tools.register({
|
|
90
|
+
name: 'bili_edit',
|
|
91
|
+
description: 'Edit an uploaded video\'s title, partition, tags, description or visibility through the Bilibili web API (requires biliup login cookies). Refuses when the submission is still under review.',
|
|
92
|
+
parameters: objectSchema({
|
|
93
|
+
bvid: { type: 'string', description: 'BV id of the archive to edit.' },
|
|
94
|
+
title: { type: 'string', description: 'New title; omit to keep.' },
|
|
95
|
+
tid: { type: 'integer', description: 'New partition id; omit to keep.' },
|
|
96
|
+
tag: { type: 'string', description: 'New comma-separated tags; omit to keep.' },
|
|
97
|
+
desc: { type: 'string', description: 'New description; omit to keep.' },
|
|
98
|
+
onlySelf: { type: 'boolean', description: 'true = 浠呰嚜宸卞彲瑙? false = 鍏紑; omit to keep current.' },
|
|
99
|
+
dryRun: { type: 'boolean', description: 'Only report current state and planned changes.' },
|
|
100
|
+
}, ['bvid']),
|
|
101
|
+
output: textOutput,
|
|
102
|
+
async execute(args) {
|
|
103
|
+
const bvid = typeof args.bvid === 'string' ? args.bvid.trim() : '';
|
|
104
|
+
if (!bvid) throw new Error('bvid 涓嶈兘涓虹┖');
|
|
105
|
+
if (!cfg.biliupPath) throw new Error('鏈厤缃?biliupPath锛氳鍦ㄦ彃浠堕厤缃噷濉啓 biliup 鍙墽琛屾枃浠惰矾寰勶紝鎴栬缃?BILIUP_PATH 鐜鍙橀噺');
|
|
106
|
+
if (!existsSync(cfg.biliupPath)) throw new Error(`鎵句笉鍒?biliup锛?{cfg.biliupPath}`);
|
|
107
|
+
if (!existsSync(cfg.cookiePath)) throw new Error(`鏈櫥褰曪細鎵句笉鍒?${cfg.cookiePath}`);
|
|
108
|
+
|
|
109
|
+
const overrides = {};
|
|
110
|
+
if (typeof args.title === 'string') overrides.title = args.title;
|
|
111
|
+
if (Number.isInteger(args.tid)) overrides.tid = args.tid;
|
|
112
|
+
if (typeof args.tag === 'string') overrides.tag = args.tag;
|
|
113
|
+
if (typeof args.desc === 'string') overrides.desc = args.desc;
|
|
114
|
+
if (typeof args.onlySelf === 'boolean') overrides.onlySelf = args.onlySelf;
|
|
115
|
+
|
|
116
|
+
if (args.dryRun) {
|
|
117
|
+
const data = await showArchive({ biliupPath: cfg.biliupPath, bvid });
|
|
118
|
+
const archive = data.archive ?? {};
|
|
119
|
+
return {
|
|
120
|
+
text: [
|
|
121
|
+
`褰撳墠锛歴tate=${archive.state} title=${archive.title} tid=${archive.tid} is_only_self=${archive.is_only_self}`,
|
|
122
|
+
`璁″垝锛?{Object.entries(overrides).map(([key, value]) => `${key}=${value}`).join(' ') || '锛堟棤鍙樻洿锛?}`,
|
|
123
|
+
].join('\n'),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const result = await editArchive({ biliupPath: cfg.biliupPath, cookiePath: cfg.cookiePath, bvid, overrides });
|
|
128
|
+
if (result.state === 'reviewing') return { text: `${bvid} 杩樺湪瀹℃牳涓紙-50锛夛紝B 绔欎笉鍏佽缂栬緫锛涘鏍搁€氳繃鍚庡啀璇曘€俙 };
|
|
129
|
+
if (result.state === 'rejected') return { text: `${bvid} 宸茶閫€鍥烇紙-30锛夛紝璇峰厛鍦ㄥ垱浣滀腑蹇冩煡鐪嬮€€鍥炲師鍥犮€俙 };
|
|
130
|
+
|
|
131
|
+
const ok = result.code === 0;
|
|
132
|
+
const lines = [ok ? `${bvid} 淇敼鎴愬姛` : `${bvid} 淇敼澶辫触锛坈ode ${result.code}锛?{result.message ?? ''}锛塦];
|
|
133
|
+
if (ok) {
|
|
134
|
+
try {
|
|
135
|
+
const after = await showArchive({ biliupPath: cfg.biliupPath, bvid });
|
|
136
|
+
const archive = after.archive ?? {};
|
|
137
|
+
lines.push(`鏀瑰悗锛歴tate=${archive.state} title=${archive.title} tid=${archive.tid} is_only_self=${archive.is_only_self}`);
|
|
138
|
+
} catch {
|
|
139
|
+
lines.push('淇敼宸叉彁浜わ紝鍥炶鐘舵€佸け璐ワ紙绋嶇瓑鍑犵鍐嶇湅锛?);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { text: lines.join('\n') };
|
|
143
|
+
},
|
|
144
|
+
presentCall: present('缂栬緫 B 绔欑浠?),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
ctx.tools.register({
|
|
148
|
+
name: 'bili_check',
|
|
149
|
+
description: 'Check biliup binary and login state (cookies.json). Optionally pass a BV id to print that video via `biliup show`.',
|
|
150
|
+
parameters: objectSchema({
|
|
151
|
+
bvid: { type: 'string', description: 'Optional BV id to query with biliup show.' },
|
|
152
|
+
}, []),
|
|
153
|
+
output: textOutput,
|
|
154
|
+
async execute(args) {
|
|
155
|
+
const lines = [
|
|
156
|
+
`biliup: ${cfg.biliupPath ? (existsSync(cfg.biliupPath) ? cfg.biliupPath : `MISSING锛?{cfg.biliupPath}锛塦) : '鏈厤缃紙璇疯缃?biliupPath 鎴?BILIUP_PATH锛?}`,
|
|
157
|
+
`cookies: ${cfg.cookiePath ? (existsSync(cfg.cookiePath) ? cfg.cookiePath : `MISSING锛?{cfg.cookiePath}锛塦) : '鏈厤缃?}`,
|
|
158
|
+
];
|
|
159
|
+
if (args.bvid) {
|
|
160
|
+
const result = await runBiliup(cfg.biliupPath, ['show', args.bvid], {
|
|
161
|
+
cwd: cfg.biliupPath.replace(/[\\/][^\\/]+$/, ''),
|
|
162
|
+
timeoutMs: 120000,
|
|
163
|
+
});
|
|
164
|
+
lines.push(`--- biliup show ${args.bvid}锛坋xit ${result.code}锛?---`, tail(result.stdout, 40), tail(result.stderr, 15));
|
|
165
|
+
}
|
|
166
|
+
return { text: lines.join('\n') };
|
|
167
|
+
},
|
|
168
|
+
presentCall: present('妫€鏌?biliup 鐘舵€?),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
package/lib/args.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const DEFAULT_TID = 188;
|
|
2
|
+
|
|
3
|
+
/** Normalize tags: accept array or comma separated string, trim, drop empty, dedupe. */
|
|
4
|
+
export function normalizeTags(tags) {
|
|
5
|
+
const list = Array.isArray(tags)
|
|
6
|
+
? tags
|
|
7
|
+
: typeof tags === 'string'
|
|
8
|
+
? tags.split(',')
|
|
9
|
+
: [];
|
|
10
|
+
const seen = new Set();
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const item of list) {
|
|
13
|
+
const tag = String(item ?? '').trim();
|
|
14
|
+
if (!tag) continue;
|
|
15
|
+
const key = tag.toLowerCase();
|
|
16
|
+
if (seen.has(key)) continue;
|
|
17
|
+
seen.add(key);
|
|
18
|
+
out.push(tag);
|
|
19
|
+
}
|
|
20
|
+
return out.join(',');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Build `biliup upload` arguments. Keep this pure so it is unit-testable. */
|
|
24
|
+
export function buildUploadArgs({ video, title, desc = '', tags = [], tid = DEFAULT_TID, cover = '', onlySelf = true, submit = 'app' }) {
|
|
25
|
+
if (!video) throw new Error('video is required');
|
|
26
|
+
if (!title) throw new Error('title is required');
|
|
27
|
+
const args = [
|
|
28
|
+
'upload', video,
|
|
29
|
+
'--title', String(title),
|
|
30
|
+
'--desc', String(desc),
|
|
31
|
+
'--tag', normalizeTags(tags),
|
|
32
|
+
'--tid', String(tid),
|
|
33
|
+
'--copyright', '1',
|
|
34
|
+
'--submit', String(submit),
|
|
35
|
+
];
|
|
36
|
+
if (cover) args.push('--cover', String(cover));
|
|
37
|
+
if (onlySelf) args.push('--is-only-self', '1');
|
|
38
|
+
return args;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Parse bvid/aid from biliup output. */
|
|
42
|
+
export function parseUploadResult(output) {
|
|
43
|
+
const text = String(output ?? '');
|
|
44
|
+
const bvid =
|
|
45
|
+
/"bvid"\s*:\s*(?:String\()?"([^"]+)"/.exec(text)?.[1] ??
|
|
46
|
+
/\b(BV[0-9A-Za-z]{10})\b/.exec(text)?.[1] ??
|
|
47
|
+
null;
|
|
48
|
+
const aidRaw = /"aid"\s*:\s*(?:Number\()?(\d+)/.exec(text)?.[1] ?? null;
|
|
49
|
+
return { bvid, aid: aidRaw ? Number(aidRaw) : null };
|
|
50
|
+
}
|
package/lib/config.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_TAGS = ['DeepSeek Harness', 'DSH', '插件', 'AI编程', '效率工具', '开源'];
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the biliup binary. No absolute path is baked in: use the plugin
|
|
7
|
+
* config `biliupPath` or the BILIUP_PATH environment variable. When neither is
|
|
8
|
+
* set the tools fail with a configuration hint.
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeConfig(raw) {
|
|
11
|
+
const source = raw && typeof raw === 'object' ? raw : {};
|
|
12
|
+
const biliupPath = (typeof source.biliupPath === 'string' && source.biliupPath.trim())
|
|
13
|
+
? source.biliupPath.trim()
|
|
14
|
+
: (process.env.BILIUP_PATH ?? '').trim();
|
|
15
|
+
return {
|
|
16
|
+
biliupPath,
|
|
17
|
+
cookiePath: typeof source.cookiePath === 'string' && source.cookiePath.trim()
|
|
18
|
+
? source.cookiePath.trim()
|
|
19
|
+
: (biliupPath ? join(dirname(biliupPath), 'cookies.json') : ''),
|
|
20
|
+
defaultTid: Number.isInteger(source.defaultTid) ? source.defaultTid : 188,
|
|
21
|
+
defaultTags: Array.isArray(source.defaultTags) && source.defaultTags.length
|
|
22
|
+
? source.defaultTags.map(String)
|
|
23
|
+
: DEFAULT_TAGS,
|
|
24
|
+
defaultOnlySelf: source.defaultOnlySelf !== false,
|
|
25
|
+
defaultSubmit: typeof source.defaultSubmit === 'string' && ['app', 'web', 'b-cut-android'].includes(source.defaultSubmit)
|
|
26
|
+
? source.defaultSubmit
|
|
27
|
+
: 'web',
|
|
28
|
+
timeoutMs: Number.isInteger(source.timeoutMs) ? source.timeoutMs : 1800000,
|
|
29
|
+
};
|
|
30
|
+
}
|
package/lib/edit.mjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
|
|
4
|
+
/** Parse biliup cookies.json into a cookie header and the csrf token. */
|
|
5
|
+
export function parseCookies(cookiePath) {
|
|
6
|
+
const raw = JSON.parse(readFileSync(cookiePath, 'utf8'));
|
|
7
|
+
const list = raw.cookie_info?.cookies ?? [];
|
|
8
|
+
const header = list.map((cookie) => `${cookie.name}=${cookie.value}`).join('; ');
|
|
9
|
+
const jar = Object.fromEntries(list.map((cookie) => [cookie.name, cookie.value]));
|
|
10
|
+
return { header, csrf: jar.bili_jct ?? '', hasSession: Boolean(jar.SESSDATA) };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** `biliup show` prints one log line before the pretty JSON. */
|
|
14
|
+
export function parseShowOutput(output) {
|
|
15
|
+
const text = String(output ?? '');
|
|
16
|
+
const start = text.indexOf('{');
|
|
17
|
+
if (start < 0) throw new Error('biliup show 输出里没有 JSON');
|
|
18
|
+
return JSON.parse(text.slice(start));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Build the archive edit payload; keep every field the API requires. */
|
|
22
|
+
export function buildEditPayload(archive, videos, overrides = {}) {
|
|
23
|
+
const payload = {
|
|
24
|
+
copyright: archive.copyright ?? 1,
|
|
25
|
+
videos: (videos ?? []).map((video) => ({
|
|
26
|
+
filename: video.filename,
|
|
27
|
+
title: video.title,
|
|
28
|
+
cid: video.cid,
|
|
29
|
+
desc: video.desc ?? '',
|
|
30
|
+
})),
|
|
31
|
+
cover: archive.cover ?? '',
|
|
32
|
+
title: overrides.title ?? archive.title,
|
|
33
|
+
tid: overrides.tid ?? archive.tid,
|
|
34
|
+
tag: overrides.tag ?? archive.tag ?? '',
|
|
35
|
+
desc: overrides.desc ?? archive.desc ?? '',
|
|
36
|
+
desc_format_id: archive.desc_format_id ?? 9999,
|
|
37
|
+
no_reprint: archive.no_reprint ?? 0,
|
|
38
|
+
open_elec: archive.open_elec ?? 0,
|
|
39
|
+
source: archive.source ?? '',
|
|
40
|
+
is_only_self:
|
|
41
|
+
overrides.onlySelf === true
|
|
42
|
+
? 1
|
|
43
|
+
: overrides.onlySelf === false
|
|
44
|
+
? 0
|
|
45
|
+
: (archive.is_only_self ?? 1),
|
|
46
|
+
};
|
|
47
|
+
return payload;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function showArchive({ biliupPath, bvid, timeoutMs = 120000 }) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
execFile(
|
|
53
|
+
biliupPath,
|
|
54
|
+
['show', bvid],
|
|
55
|
+
{ cwd: biliupPath.replace(/[\\/][^\\/]+$/, ''), maxBuffer: 10 * 1024 * 1024, timeout: timeoutMs },
|
|
56
|
+
(error, stdout, stderr) => {
|
|
57
|
+
if (error) reject(new Error(`biliup show 失败: ${stderr || error.message}`));
|
|
58
|
+
else resolve(parseShowOutput(stdout));
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Edit an archive's metadata/visibility through the Bilibili web endpoint.
|
|
66
|
+
* Returns { state: 'reviewing' } when the submission is still under review.
|
|
67
|
+
*/
|
|
68
|
+
export async function editArchive({ biliupPath, cookiePath, bvid, overrides, fetchImpl = fetch }) {
|
|
69
|
+
const cookies = parseCookies(cookiePath);
|
|
70
|
+
if (!cookies.hasSession || !cookies.csrf) throw new Error('cookies.json 缺少 SESSDATA 或 bili_jct');
|
|
71
|
+
|
|
72
|
+
const data = await showArchive({ biliupPath, bvid });
|
|
73
|
+
const state = String(data.archive?.state);
|
|
74
|
+
if (state === '-50') return { state: 'reviewing', archive: data.archive };
|
|
75
|
+
if (state === '-30') return { state: 'rejected', archive: data.archive };
|
|
76
|
+
|
|
77
|
+
const payload = buildEditPayload(data.archive, data.videos, overrides);
|
|
78
|
+
const response = await fetchImpl(`https://member.bilibili.com/x/vu/web/edit?csrf=${cookies.csrf}`, {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
headers: {
|
|
81
|
+
Cookie: cookies.header,
|
|
82
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36',
|
|
83
|
+
Referer: 'https://member.bilibili.com/platform/upload-manager/article',
|
|
84
|
+
'Content-Type': 'application/json',
|
|
85
|
+
},
|
|
86
|
+
body: JSON.stringify(payload),
|
|
87
|
+
});
|
|
88
|
+
const result = await response.json();
|
|
89
|
+
return { state: 'edited', code: result.code, message: result.message, payload };
|
|
90
|
+
}
|
package/lib/upload.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { buildUploadArgs, parseUploadResult } from './args.mjs';
|
|
5
|
+
|
|
6
|
+
export function runBiliup(command, args, { cwd, timeoutMs = 1800000 } = {}) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
let child;
|
|
9
|
+
try {
|
|
10
|
+
child = spawn(command, args, { cwd, shell: false, windowsHide: true });
|
|
11
|
+
} catch (error) {
|
|
12
|
+
resolve({ code: -1, stdout: '', stderr: String(error) });
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let stdout = '';
|
|
16
|
+
let stderr = '';
|
|
17
|
+
child.stdout?.on('data', (chunk) => { stdout += chunk; });
|
|
18
|
+
child.stderr?.on('data', (chunk) => { stderr += chunk; });
|
|
19
|
+
const timer = setTimeout(() => child.kill(), timeoutMs);
|
|
20
|
+
child.on('close', (code) => {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
resolve({ code, stdout, stderr });
|
|
23
|
+
});
|
|
24
|
+
child.on('error', (error) => {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
resolve({ code: -1, stdout, stderr: `${stderr}${error}` });
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Upload one video and return the parsed BV/aid plus raw output. */
|
|
32
|
+
export async function uploadVideo({
|
|
33
|
+
biliupPath,
|
|
34
|
+
video,
|
|
35
|
+
title,
|
|
36
|
+
desc = '',
|
|
37
|
+
tags = [],
|
|
38
|
+
cover = '',
|
|
39
|
+
tid = 188,
|
|
40
|
+
onlySelf = true,
|
|
41
|
+
submit = 'app',
|
|
42
|
+
timeoutMs,
|
|
43
|
+
}) {
|
|
44
|
+
const args = buildUploadArgs({ video, title, desc, tags, cover, tid, onlySelf, submit });
|
|
45
|
+
const result = await runBiliup(biliupPath, args, { cwd: dirname(biliupPath), timeoutMs });
|
|
46
|
+
const parsed = parseUploadResult(`${result.stdout}\n${result.stderr}`);
|
|
47
|
+
return {
|
|
48
|
+
ok: result.code === 0 && Boolean(parsed.bvid),
|
|
49
|
+
code: result.code,
|
|
50
|
+
bvid: parsed.bvid,
|
|
51
|
+
aid: parsed.aid,
|
|
52
|
+
stdout: result.stdout,
|
|
53
|
+
stderr: result.stderr,
|
|
54
|
+
args,
|
|
55
|
+
};
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-bilibili-upload",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Upload and edit videos on Bilibili from DSH through biliup: title, description, tags, cover, partition, visibility, plus a settings panel.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "fubai-fenzhi",
|
|
8
|
+
"homepage": "https://github.com/fubai-fenzhi/dsh-bilibili-upload#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/fubai-fenzhi/dsh-bilibili-upload.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"dsh",
|
|
15
|
+
"dsh-plugin",
|
|
16
|
+
"deepseek-harness",
|
|
17
|
+
"bilibili",
|
|
18
|
+
"biliup",
|
|
19
|
+
"upload",
|
|
20
|
+
"video"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18",
|
|
24
|
+
"dsh": ">=0.2.1-rc.3"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./index.js",
|
|
31
|
+
"./client": "./client.js",
|
|
32
|
+
"./ui-route": "./ui-route.js"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"index.js",
|
|
36
|
+
"client.js",
|
|
37
|
+
"ui-route.js",
|
|
38
|
+
"lib/*.mjs",
|
|
39
|
+
"cordis.patch.yml",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"dsh": {
|
|
44
|
+
"bundle": {
|
|
45
|
+
"patch": "./cordis.patch.yml"
|
|
46
|
+
},
|
|
47
|
+
"client": {
|
|
48
|
+
"platform": "web",
|
|
49
|
+
"immediately": true,
|
|
50
|
+
"inject": [
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
package/ui-route.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
import { normalizeConfig } from './lib/config.mjs';
|
|
4
|
+
import { editArchive } from './lib/edit.mjs';
|
|
5
|
+
import { uploadVideo } from './lib/upload.mjs';
|
|
6
|
+
|
|
7
|
+
export const name = 'dsh-bilibili-upload-ui';
|
|
8
|
+
export const inject = ['webServer'];
|
|
9
|
+
|
|
10
|
+
export function apply(ctx) {
|
|
11
|
+
const cfg = normalizeConfig();
|
|
12
|
+
|
|
13
|
+
ctx.effect(() => ctx.webServer.register({
|
|
14
|
+
kind: 'exact',
|
|
15
|
+
path: '/bili-upload/state',
|
|
16
|
+
resource: async () => Response.json({
|
|
17
|
+
biliup: existsSync(cfg.biliupPath),
|
|
18
|
+
cookies: existsSync(cfg.cookiePath),
|
|
19
|
+
biliupPath: cfg.biliupPath,
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
ctx.effect(() => ctx.webServer.register({
|
|
24
|
+
kind: 'exact',
|
|
25
|
+
path: '/bili-upload/upload',
|
|
26
|
+
resource: async (request) => {
|
|
27
|
+
if (request.method !== 'POST') return Response.json({ error: 'POST only' }, { status: 405 });
|
|
28
|
+
try {
|
|
29
|
+
const body = await request.json();
|
|
30
|
+
if (!body.video || !body.title) return Response.json({ error: 'video/title required' }, { status: 400 });
|
|
31
|
+
if (!cfg.biliupPath) return Response.json({ error: '鏈厤缃?biliupPath锛堟彃浠堕厤缃垨 BILIUP_PATH锛? }, { status: 400 });
|
|
32
|
+
if (!existsSync(body.video)) return Response.json({ error: `瑙嗛涓嶅瓨鍦細${body.video}` }, { status: 400 });
|
|
33
|
+
if (body.cover && !existsSync(body.cover)) return Response.json({ error: `灏侀潰涓嶅瓨鍦細${body.cover}` }, { status: 400 });
|
|
34
|
+
const result = await uploadVideo({
|
|
35
|
+
biliupPath: cfg.biliupPath,
|
|
36
|
+
video: body.video,
|
|
37
|
+
title: body.title,
|
|
38
|
+
desc: body.desc ?? '',
|
|
39
|
+
tags: body.tags ?? cfg.defaultTags,
|
|
40
|
+
cover: body.cover ?? '',
|
|
41
|
+
tid: Number.isInteger(body.tid) ? body.tid : cfg.defaultTid,
|
|
42
|
+
onlySelf: typeof body.onlySelf === 'boolean' ? body.onlySelf : cfg.defaultOnlySelf,
|
|
43
|
+
submit: body.submit ?? cfg.defaultSubmit,
|
|
44
|
+
timeoutMs: cfg.timeoutMs,
|
|
45
|
+
});
|
|
46
|
+
return Response.json({
|
|
47
|
+
ok: result.ok,
|
|
48
|
+
bvid: result.bvid,
|
|
49
|
+
aid: result.aid,
|
|
50
|
+
code: result.code,
|
|
51
|
+
stderr: result.stderr.slice(-600),
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return Response.json({ error: String(error) }, { status: 500 });
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
ctx.effect(() => ctx.webServer.register({
|
|
60
|
+
kind: 'exact',
|
|
61
|
+
path: '/bili-upload/edit',
|
|
62
|
+
resource: async (request) => {
|
|
63
|
+
if (request.method !== 'POST') return Response.json({ error: 'POST only' }, { status: 405 });
|
|
64
|
+
try {
|
|
65
|
+
const body = await request.json();
|
|
66
|
+
if (!body.bvid) return Response.json({ error: 'bvid required' }, { status: 400 });
|
|
67
|
+
const overrides = {};
|
|
68
|
+
for (const key of ['title', 'tid', 'tag', 'desc']) {
|
|
69
|
+
if (body[key] !== undefined) overrides[key] = body[key];
|
|
70
|
+
}
|
|
71
|
+
if (typeof body.onlySelf === 'boolean') overrides.onlySelf = body.onlySelf;
|
|
72
|
+
const result = await editArchive({
|
|
73
|
+
biliupPath: cfg.biliupPath,
|
|
74
|
+
cookiePath: cfg.cookiePath,
|
|
75
|
+
bvid: body.bvid,
|
|
76
|
+
overrides,
|
|
77
|
+
});
|
|
78
|
+
return Response.json(result);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return Response.json({ error: String(error) }, { status: 500 });
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
|