feat: add configurable parallel video uploads

Allow up to four video upload connections while keeping one connection as the default. Preserve existing messaging interfaces and add configuration controls, reliable failure handling, and upload diagnostics.

Closes #569
This commit is contained in:
DrSmoothl committed 2026-10-24 22:58:46 +08:00
1 parent 3bd74acb60
commit 5c9328206f
18 files changed
+1182 -217

No files matched your search

+45 -2
View File
@@ -29,8 +29,13 @@ describe('global-config (config/snowluma.json)', () => {
expect(defaultGlobalSettings()).toEqual({
rkey: { fallbackServers: [] },
musicSignUrl: '',
videoUploadConcurrency: 1,
});
expect(loadGlobalSettings()).toEqual({
rkey: { fallbackServers: [] },
musicSignUrl: '',
videoUploadConcurrency: 1,
});
expect(loadGlobalSettings()).toEqual({ rkey: { fallbackServers: [] }, musicSignUrl: '' });
});
it('keeps only well-formed http(s) URLs, trims, and dedupes', () => {
@@ -55,10 +60,12 @@ describe('global-config (config/snowluma.json)', () => {
expect(normalizeGlobalSettings({ rkey: 'nope' })).toEqual({
rkey: { fallbackServers: [] },
musicSignUrl: '',
videoUploadConcurrency: 1,
});
expect(normalizeGlobalSettings(null)).toEqual({
rkey: { fallbackServers: [] },
musicSignUrl: '',
videoUploadConcurrency: 1,
});
});
@@ -74,6 +81,7 @@ describe('global-config (config/snowluma.json)', () => {
expect(onDisk).toEqual({
rkey: { fallbackServers: ['https://r.example/rkey'] },
musicSignUrl: '',
videoUploadConcurrency: 1,
});
expect(loadGlobalSettings().rkey.fallbackServers).toEqual(['https://r.example/rkey']);
@@ -100,6 +108,37 @@ describe('global-config (config/snowluma.json)', () => {
expect(loadGlobalSettings().musicSignUrl).toBe('https://s.example/c');
});
it.each([1, 2, 3, 4])('persists %i video connections and preserves partial saves', (value) => {
expect(saveGlobalSettings({ videoUploadConcurrency: value }).videoUploadConcurrency).toBe(
value,
);
saveGlobalSettings({ musicSignUrl: 'https://sign.example/card' });
expect(loadGlobalSettings().videoUploadConcurrency).toBe(value);
});
it.each([0, 5, -1, 1.5, '2', null, false])(
'rejects invalid video concurrency %j without writing',
(value) => {
saveGlobalSettings({ videoUploadConcurrency: 3 });
const file = path.join(tempDir, 'config', 'snowluma.json');
const before = fs.readFileSync(file, 'utf8');
expect(() => saveGlobalSettings({ videoUploadConcurrency: value })).toThrow(
/integer from 1 to 4/,
);
expect(fs.readFileSync(file, 'utf8')).toBe(before);
expect(() => normalizeGlobalSettings({ videoUploadConcurrency: value })).toThrow();
},
);
it('reports an invalid persisted concurrency instead of silently ignoring it', () => {
fs.mkdirSync(path.join(tempDir, 'config'), { recursive: true });
fs.writeFileSync(
path.join(tempDir, 'config', 'snowluma.json'),
JSON.stringify({ videoUploadConcurrency: 99 }),
);
expect(() => loadGlobalSettings()).toThrow(/videoUploadConcurrency/);
});
describe('migrateGlobalSettings (musicSignUrl copy-up)', () => {
function writeOnebot(file: string, body: unknown) {
const dir = path.join(tempDir, 'config');
@@ -167,6 +206,10 @@ describe('global-config (config/snowluma.json)', () => {
it('falls back to defaults when the file is corrupt', () => {
fs.mkdirSync(path.join(tempDir, 'config'), { recursive: true });
fs.writeFileSync(path.join(tempDir, 'config', 'snowluma.json'), '{ not json', 'utf8');
expect(loadGlobalSettings()).toEqual({ rkey: { fallbackServers: [] }, musicSignUrl: '' });
expect(loadGlobalSettings()).toEqual({
rkey: { fallbackServers: [] },
musicSignUrl: '',
videoUploadConcurrency: 1,
});
});
});