feat(video): raise video-path size limit to 1.5 GiB (#145)
The 100 MB cap that re-routed larger videos to the file-upload pipeline was a workaround for the width/height=0 → 已过期 bug (fixed in the prior commit), not a real QQ size limit. Real-machine verified on tempserver: 88 MB / 149 MB / 299 MB / 497 MB videos all upload, render and play as normal videos in a group. Raise MAX_VIDEO_SIZE to 1.5 GiB (matching the file-upload ceiling); only videos above that still fall back to the file path. Collapse the redundant MAX_VIDEO_SIZE_HARD (was also 1.5 GiB) into the single constant and drop the now-dead 100 MB warn branches. Note: the whole video is buffered in RAM for the Highway upload, so a 1.5 GiB send costs ~1.5 GiB+ of process memory — that, not a QQ limit, is what bounds the ceiling.
This commit is contained in:
3 files changed
+27
-24
No files matched your search
@@ -620,11 +620,12 @@ export async function sendPrivateMessage(
|
||||
let allFileElements = elements.filter(e => e.type === 'file');
|
||||
let nonFileElements = elements.filter(e => e.type !== 'file');
|
||||
|
||||
// [#145] A video above QQ's ~100 MB video-resource cap (MAX_VIDEO_SIZE)
|
||||
// uploads "successfully" but renders as 视频已过期 on the receiver — the
|
||||
// server accepts the bytes yet never produces a valid video resource. The
|
||||
// on-error fallback below can't catch it (the oversized upload doesn't
|
||||
// throw), so route known-oversized videos to the file path up front.
|
||||
// [#145] Videos up to MAX_VIDEO_SIZE (1.5 GiB) send as real videos; only
|
||||
// above that do we route to the file pipeline (the whole video is buffered
|
||||
// in RAM for the Highway upload, so this bounds memory). The earlier
|
||||
// 100 MB cap was a workaround for the width/height=0 → 已过期 bug (now
|
||||
// fixed) and has been lifted. Route known-oversized videos up front —
|
||||
// the on-error fallback below can't catch them (the upload doesn't throw).
|
||||
{
|
||||
const pre = splitVideoFileFallback(nonFileElements, false);
|
||||
if (pre.fileEls.length > 0) {
|
||||
@@ -723,8 +724,8 @@ export async function sendGroupMessage(
|
||||
let allFileElements = elements.filter(e => e.type === 'file');
|
||||
let nonFileElements = elements.filter(e => e.type !== 'file');
|
||||
|
||||
// [#145] Route known-oversized videos (> MAX_VIDEO_SIZE) to the file path
|
||||
// up front — they upload as a video without error but render expired.
|
||||
// [#145] Route videos above MAX_VIDEO_SIZE (1.5 GiB) to the file path up
|
||||
// front; everything at or below sends as a real video (see sendPrivate).
|
||||
{
|
||||
const pre = splitVideoFileFallback(nonFileElements, false);
|
||||
if (pre.fileEls.length > 0) {
|
||||
|
||||
@@ -96,15 +96,17 @@ describe('send_group_msg large-video fallback', () => {
|
||||
|
||||
describe('videoNeedsFileFallback', () => {
|
||||
it('triggers on a known oversize source regardless of the error message', () => {
|
||||
// The real-bot case: a local 1.4 GB video whose Highway upload fails
|
||||
// with a cryptic `error_code=323` (not size-worded). Source size is
|
||||
// known, so the file fallback must still fire.
|
||||
const big = { type: 'video', fileSize: 1400 * MB } as MessageElement;
|
||||
// Above MAX_VIDEO_SIZE (1.5 GiB) the video is re-routed to the file
|
||||
// pipeline even when the error isn't size-worded. Source size is known,
|
||||
// so the fallback fires from the size alone.
|
||||
const big = { type: 'video', fileSize: 1700 * MB } as MessageElement;
|
||||
expect(videoNeedsFileFallback(big, /* isSizeErr */ false)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not trigger for a known under-limit source', () => {
|
||||
const small = { type: 'video', fileSize: 50 * MB } as MessageElement;
|
||||
it('does not trigger for a known under-limit source (now covers large videos)', () => {
|
||||
// 500 MB used to route to file under the old 100 MB cap; it now sends as
|
||||
// a real video (verified on tempserver up to ~500 MB).
|
||||
const small = { type: 'video', fileSize: 500 * MB } as MessageElement;
|
||||
expect(videoNeedsFileFallback(small, true)).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -33,8 +33,14 @@ export const PRIVATE_VIDEO_THUMB_CMD_ID = 1002;
|
||||
export const GROUP_VIDEO_CMD_ID = 1005;
|
||||
export const GROUP_VIDEO_THUMB_CMD_ID = 1006;
|
||||
|
||||
export const MAX_VIDEO_SIZE = 100 * 1024 * 1024;
|
||||
const MAX_VIDEO_SIZE_HARD = 1536 * 1024 * 1024;
|
||||
// Videos up to 1.5 GiB send through the Highway video path (matches the
|
||||
// file-upload ceiling). Real-machine verified up to ~500 MB rendering and
|
||||
// playing fine as a video; the old 100 MB cap existed only to dodge the
|
||||
// width/height=0 → 已过期 bug (fixed above), not any real QQ size limit.
|
||||
// Above this the OneBot layer re-routes to the file pipeline. NOTE: the
|
||||
// whole video is buffered in RAM here (fs.readFileSync), so a 1.5 GiB send
|
||||
// costs ~1.5 GiB+ of process memory.
|
||||
export const MAX_VIDEO_SIZE = 1536 * 1024 * 1024;
|
||||
const SHA1_STREAM_BLOCK_SIZE = 1024 * 1024;
|
||||
const SHA1_BLOCK_SIZE = 64;
|
||||
|
||||
@@ -174,11 +180,8 @@ async function stageVideoSource(element: MessageElement, tempDir: string, cleanu
|
||||
const local = resolveLocalFilePath(source);
|
||||
if (local && fs.existsSync(local)) {
|
||||
const stat = fs.statSync(local);
|
||||
if (stat.size > MAX_VIDEO_SIZE_HARD) {
|
||||
throw new Error(`video file too large: ${(stat.size / (1024 * 1024)).toFixed(2)} MB > ${MAX_VIDEO_SIZE_HARD / (1024 * 1024)} MB`);
|
||||
}
|
||||
if (stat.size > MAX_VIDEO_SIZE) {
|
||||
moduleLog.warn('video exceeds 100 MB (%d MB), trying Highway upload', stat.size / (1024 * 1024));
|
||||
throw new Error(`video file too large: ${(stat.size / (1024 * 1024)).toFixed(2)} MB > ${MAX_VIDEO_SIZE / (1024 * 1024)} MB`);
|
||||
}
|
||||
return {
|
||||
bytes: new Uint8Array(fs.readFileSync(local)),
|
||||
@@ -187,7 +190,7 @@ async function stageVideoSource(element: MessageElement, tempDir: string, cleanu
|
||||
};
|
||||
}
|
||||
|
||||
const loaded = await loadBinarySource(source, 'video', MAX_VIDEO_SIZE_HARD);
|
||||
const loaded = await loadBinarySource(source, 'video', MAX_VIDEO_SIZE);
|
||||
const fileName = element.fileName || loaded.fileName || '';
|
||||
const stagedPath = path.join(tempDir, `snowluma-video-in-${crypto.randomUUID()}${sourceExtension(fileName, source)}`);
|
||||
fs.writeFileSync(stagedPath, Buffer.from(loaded.bytes));
|
||||
@@ -274,11 +277,8 @@ async function loadVideo(element: MessageElement): Promise<VideoPayload> {
|
||||
try {
|
||||
const staged = await stageVideoSource(element, tempDir, cleanups);
|
||||
if (staged.bytes.length === 0) throw new Error('video file is empty');
|
||||
if (staged.bytes.length > MAX_VIDEO_SIZE_HARD) {
|
||||
throw new Error(`video file too large: ${(staged.bytes.length / (1024 * 1024)).toFixed(2)} MB > ${MAX_VIDEO_SIZE_HARD / (1024 * 1024)} MB`);
|
||||
}
|
||||
if (staged.bytes.length > MAX_VIDEO_SIZE) {
|
||||
moduleLog.warn('video bytes exceed 100 MB (%d MB), Highway upload may fail', staged.bytes.length / (1024 * 1024));
|
||||
throw new Error(`video file too large: ${(staged.bytes.length / (1024 * 1024)).toFixed(2)} MB > ${MAX_VIDEO_SIZE / (1024 * 1024)} MB`);
|
||||
}
|
||||
|
||||
const hashes = computeHashes(staged.bytes);
|
||||
|
||||
Reference in new issue
Block a user