feat(onebot): upload_file_stream + clean_stream_temp_file (#163 phase 2)
NapCat-compatible chunked upload: a client pushes a file in base64 chunks across repeated upload_file_stream calls keyed by stream_id; the bot reassembles them into a local temp file and returns its path for a normal send. Sidesteps the 2 MB HTTP body cap and the shared-filesystem assumption of file:// sends. Reassembly streams chunk-by-chunk to disk (no whole-file Buffer.concat) so an arbitrarily large upload won't OOM. clean_stream_temp_file wipes only the stream temp dirs. Hardened well past the NapCat original (which has all of these holes), per two adversarial review passes: - stream_id is allowlist-validated + every derived path fenced inside the upload dir — no path traversal (the original lets stream_id write/delete arbitrary paths). - total_chunks / concurrent streams / per-chunk + per-stream bytes are all bounded — no single-request OOM or disk/fd exhaustion. - chunk indices are claimed synchronously and only counted complete once flushed — no double-count race, no truncated-read-on-concurrent-complete. - state + temp dirs are namespaced per account. 494 onebot tests green.
This commit is contained in:
3 files changed
+554
No files matched your search
@@ -11,6 +11,7 @@ import { register as registerInfo } from './actions/info';
|
||||
import { register as registerMessage } from './actions/message';
|
||||
import { register as registerQzone } from './actions/qzone';
|
||||
import { register as registerRequest } from './actions/request';
|
||||
import { register as registerStreamFile } from './actions/stream-file';
|
||||
import type { ForwardPreviewMeta } from './modules/message-actions';
|
||||
import type { JsonObject, JsonValue, MessageMeta } from './types';
|
||||
import { RETCODE, failedResponse } from './types';
|
||||
@@ -120,6 +121,7 @@ export class ApiHandler {
|
||||
registerExtended(this, context);
|
||||
registerGroupAlbum(this, context);
|
||||
registerQzone(this, context);
|
||||
registerStreamFile(this, context);
|
||||
}
|
||||
|
||||
registerAction(action: string, handler: ActionHandler): void {
|
||||
|
||||
Reference in new issue
Block a user