update
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { clientStates, ClientState } from '../websocket'; // +++ 导入 ClientState +++
|
import { clientStates, ClientState } from '../websocket'; // +++ 导入 ClientState +++
|
||||||
import archiver from 'archiver'; // +++ 引入 archiver +++
|
import * as archiver from 'archiver'; // +++ 引入 archiver +++ (尝试修复 TS2349)
|
||||||
import { SFTPWrapper, Stats } from 'ssh2'; // +++ 移除 Dirent 导入 +++
|
import { SFTPWrapper, Stats } from 'ssh2'; // +++ 移除 Dirent 导入 +++
|
||||||
// 移除 ssh2-streams 导入
|
// 移除 ssh2-streams 导入
|
||||||
|
|
||||||
@@ -190,15 +190,15 @@ export const downloadDirectory = async (req: Request, res: Response): Promise<vo
|
|||||||
res.setHeader('Content-Disposition', `attachment; filename="${archiveName}"`); // 使用修正后的名称
|
res.setHeader('Content-Disposition', `attachment; filename="${archiveName}"`); // 使用修正后的名称
|
||||||
|
|
||||||
// 3. 创建 Archiver 实例
|
// 3. 创建 Archiver 实例
|
||||||
const archive = archiver('zip', {
|
const archive = archiver.create('zip', {
|
||||||
zlib: { level: 9 } // 设置压缩级别 (可选)
|
zlib: { level: 9 } // 设置压缩级别 (可选)
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听错误事件
|
// 监听错误事件
|
||||||
archive.on('warning', (err) => {
|
archive.on('warning', (err: Error) => {
|
||||||
console.warn(`Archiver warning (用户 ${userId}, 路径 ${remotePath}):`, err);
|
console.warn(`Archiver warning (用户 ${userId}, 路径 ${remotePath}):`, err);
|
||||||
});
|
});
|
||||||
archive.on('error', (err) => {
|
archive.on('error', (err: Error) => {
|
||||||
console.error(`Archiver error (用户 ${userId}, 路径 ${remotePath}):`, err);
|
console.error(`Archiver error (用户 ${userId}, 路径 ${remotePath}):`, err);
|
||||||
// 尝试发送错误响应,如果头还没发送
|
// 尝试发送错误响应,如果头还没发送
|
||||||
if (!res.headersSent) {
|
if (!res.headersSent) {
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ declare module 'archiver' {
|
|||||||
interface Archiver extends NodeJS.EventEmitter {
|
interface Archiver extends NodeJS.EventEmitter {
|
||||||
on(event: 'data', listener: (data: Buffer) => void): this;
|
on(event: 'data', listener: (data: Buffer) => void): this;
|
||||||
on(event: 'error', listener: (err: Error) => void): this;
|
on(event: 'error', listener: (err: Error) => void): this;
|
||||||
|
on(event: 'warning', listener: (err: Error) => void): this; // 添加 'warning' 事件
|
||||||
|
pipe(destination: NodeJS.WritableStream): NodeJS.WritableStream; // 添加 pipe 方法
|
||||||
append(data: any, options: { name: string }): void;
|
append(data: any, options: { name: string }): void;
|
||||||
finalize(): Promise<void>;
|
finalize(): Promise<void>;
|
||||||
|
destroyed?: boolean; // 添加 destroyed 属性
|
||||||
|
abort(): this; // 添加 abort 方法
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user