mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-24 09:00:06 +08:00
* feat: pnpm new * Refactor build and release workflows, update dependencies Switch build scripts and workflows from npm to pnpm, update build and artifact paths, and simplify release workflow by removing version detection and changelog steps. Add new dependencies (silk-wasm, express, ws, node-pty-prebuilt-multiarch), update exports in package.json files, and add vite config for napcat-framework. Also, rename manifest.json for framework package and fix static asset copying in shell build config.
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { OneBotRequestToolkit } from '@/napcat-onebot/action/OneBotAction';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
|
|
import { StreamPacket, StreamStatus } from './StreamBasic';
|
|
import fs from 'fs';
|
|
import { BaseDownloadStream, DownloadResult } from './BaseDownloadStream';
|
|
const SchemaData = Type.Object({
|
|
file: Type.Optional(Type.String()),
|
|
file_id: Type.Optional(Type.String()),
|
|
chunk_size: Type.Optional(Type.Number({ default: 64 * 1024 })), // 默认64KB分块
|
|
});
|
|
|
|
type Payload = Static<typeof SchemaData>;
|
|
|
|
export class DownloadFileStream extends BaseDownloadStream<Payload, DownloadResult> {
|
|
override actionName = ActionName.DownloadFileStream;
|
|
override payloadSchema = SchemaData;
|
|
override useStream = true;
|
|
|
|
async _handle (payload: Payload, _adaptername: string, _config: NetworkAdapterConfig, req: OneBotRequestToolkit): Promise<StreamPacket<DownloadResult>> {
|
|
try {
|
|
payload.file ||= payload.file_id || '';
|
|
const chunkSize = payload.chunk_size || 64 * 1024;
|
|
|
|
const { downloadPath, fileName, fileSize } = await this.resolveDownload(payload.file);
|
|
|
|
const stats = await fs.promises.stat(downloadPath);
|
|
const totalSize = fileSize || stats.size;
|
|
|
|
await req.send({
|
|
type: StreamStatus.Stream,
|
|
data_type: 'file_info',
|
|
file_name: fileName,
|
|
file_size: totalSize,
|
|
chunk_size: chunkSize,
|
|
});
|
|
|
|
const { totalChunks, totalBytes } = await this.streamFileChunks(req, downloadPath, chunkSize, 'file_chunk');
|
|
|
|
return {
|
|
type: StreamStatus.Response,
|
|
data_type: 'file_complete',
|
|
total_chunks: totalChunks,
|
|
total_bytes: totalBytes,
|
|
message: 'Download completed',
|
|
};
|
|
} catch (error) {
|
|
throw new Error(`Download failed: ${(error as Error).message}`);
|
|
}
|
|
}
|
|
}
|