@filebox/core 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +599 -0
- package/dist/index.browser.js +29 -0
- package/dist/index.cjs +33 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.mjs +29 -0
- package/dist/src/cache/cache.d.ts +104 -0
- package/dist/src/cache/dependencies.d.ts +60 -0
- package/dist/src/cache/index.d.ts +8 -0
- package/dist/src/cache/operations.d.ts +52 -0
- package/dist/src/cache/strategies/index.d.ts +1 -0
- package/dist/src/cache/strategies/lru.d.ts +15 -0
- package/dist/src/cache/types.d.ts +79 -0
- package/dist/src/cache1.d.ts +230 -0
- package/dist/src/constant.d.ts +2 -0
- package/dist/src/crypt/eme-cipher.d.ts +37 -0
- package/dist/src/crypt/file-encryptor.d.ts +168 -0
- package/dist/src/crypt/fs-crypt.d.ts +24 -0
- package/dist/src/crypt/index.d.ts +9 -0
- package/dist/src/crypt/protocol.d.ts +27 -0
- package/dist/src/crypt/utils.d.ts +7 -0
- package/dist/src/crypt.d.ts +2 -0
- package/dist/src/crypto-shim.d.ts +2 -0
- package/dist/src/debug.d.ts +9 -0
- package/dist/src/enums/index.d.ts +8 -0
- package/dist/src/error.d.ts +6 -0
- package/dist/src/filter.d.ts +12 -0
- package/dist/src/fs/http_fs.d.ts +40 -0
- package/dist/src/fs/index.d.ts +95 -0
- package/dist/src/index.d.ts +51 -0
- package/dist/src/lock.d.ts +9 -0
- package/dist/src/path.d.ts +65 -0
- package/dist/src/plugin.d.ts +16 -0
- package/dist/src/stat.d.ts +64 -0
- package/dist/src/type.d.ts +47 -0
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/volume.d.ts +48 -0
- package/package.json +59 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 支持的加密算法类型
|
|
3
|
+
*
|
|
4
|
+
* 推荐算法(生产环境):
|
|
5
|
+
* - AES-CTR: ⭐⭐⭐ 最推荐!流加密,适合大文件,支持随机访问,跨平台兼容
|
|
6
|
+
* - ChaCha20: ⭐⭐ 现代流加密,性能好,安全可靠
|
|
7
|
+
*
|
|
8
|
+
* 特殊场景:
|
|
9
|
+
* - AES-GCM: ⭐ 带认证标签,防篡改。⚠️ 不支持分块加密,大文件会消耗大量内存!
|
|
10
|
+
*
|
|
11
|
+
* 不推荐(仅用于兼容):
|
|
12
|
+
* - RC4: ⚠️ 已被认为不安全,仅用于演示和兼容旧系统
|
|
13
|
+
*/
|
|
14
|
+
export type EncryptionAlgorithm = "AES-CTR" | "AES-GCM" | "RC4" | "ChaCha20";
|
|
15
|
+
export declare function normalizeEncryptionAlgorithm(algorithm?: string): EncryptionAlgorithm;
|
|
16
|
+
/**
|
|
17
|
+
* 部分加密配置
|
|
18
|
+
*/
|
|
19
|
+
export interface PartialEncryptionConfig {
|
|
20
|
+
/** 加密类型: 'percentage' 百分比 | 'size' 固定大小 | 'full' 完整加密 */
|
|
21
|
+
type: "percentage" | "size" | "full";
|
|
22
|
+
/** 当 type='percentage' 时,表示加密的百分比 (0-100) */
|
|
23
|
+
percentage?: number;
|
|
24
|
+
/** 当 type='size' 时,表示加密的字节数 */
|
|
25
|
+
bytes?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 文件流加密类
|
|
29
|
+
* 支持多种流加密算法:AES-CTR、AES-GCM、RC4、ChaCha20
|
|
30
|
+
* 优先考虑性能,适合大文件处理
|
|
31
|
+
* 支持部分加密:可以只加密文件的前面部分
|
|
32
|
+
*/
|
|
33
|
+
export declare class FileEncryptor {
|
|
34
|
+
private password;
|
|
35
|
+
private salt;
|
|
36
|
+
private _initialized;
|
|
37
|
+
private fileKey;
|
|
38
|
+
private iv;
|
|
39
|
+
private cryptoKey;
|
|
40
|
+
private algorithm;
|
|
41
|
+
chunkSize: number;
|
|
42
|
+
private partialEncryption;
|
|
43
|
+
constructor(password: string, salt: Uint8Array, algorithm?: EncryptionAlgorithm);
|
|
44
|
+
init(): Promise<FileEncryptor>;
|
|
45
|
+
/**
|
|
46
|
+
* 加密单个数据块
|
|
47
|
+
* @param chunk 要加密的数据块
|
|
48
|
+
* @param offset 当前块在文件中的偏移量(用于计算counter)
|
|
49
|
+
*/
|
|
50
|
+
encryptChunk(chunk: Uint8Array, offset?: number): Promise<Uint8Array>;
|
|
51
|
+
/**
|
|
52
|
+
* 解密单个数据块
|
|
53
|
+
* @param chunk 要解密的数据块
|
|
54
|
+
* @param offset 当前块在文件中的偏移量(用于计算counter)
|
|
55
|
+
*/
|
|
56
|
+
decryptChunk(chunk: Uint8Array, offset?: number): Promise<Uint8Array>;
|
|
57
|
+
/**
|
|
58
|
+
* 流式加密(适用于 ReadableStream,支持部分加密)
|
|
59
|
+
* @param stream 输入流
|
|
60
|
+
* @param totalSize 文件总大小(用于计算部分加密)
|
|
61
|
+
* @returns 加密后的流
|
|
62
|
+
*/
|
|
63
|
+
createEncryptStream(stream: ReadableStream<Uint8Array>, totalSize?: number): ReadableStream<Uint8Array>;
|
|
64
|
+
/**
|
|
65
|
+
* 流式解密(适用于 ReadableStream,支持部分加密的文件)
|
|
66
|
+
* @param stream 加密的输入流
|
|
67
|
+
* @param totalSize 文件总大小(用于计算部分解密)
|
|
68
|
+
* @returns 解密后的流
|
|
69
|
+
*/
|
|
70
|
+
createDecryptStream(stream: ReadableStream<Uint8Array>, totalSize?: number): ReadableStream<Uint8Array>;
|
|
71
|
+
/**
|
|
72
|
+
* 加密整个 Blob/File(支持部分加密)
|
|
73
|
+
* @param blob 要加密的 Blob 或 File
|
|
74
|
+
* @returns 加密后的 Blob
|
|
75
|
+
*/
|
|
76
|
+
encryptBlob(blob: Blob): Promise<Blob>;
|
|
77
|
+
/**
|
|
78
|
+
* 解密整个 Blob(支持部分加密的文件)
|
|
79
|
+
* @param blob 加密的 Blob
|
|
80
|
+
* @returns 解密后的 Blob
|
|
81
|
+
*/
|
|
82
|
+
decryptBlob(blob: Blob): Promise<Blob>;
|
|
83
|
+
/**
|
|
84
|
+
* 根据偏移量计算 counter
|
|
85
|
+
* AES-CTR 需要每个块有不同的 counter
|
|
86
|
+
*/
|
|
87
|
+
private _getCounter;
|
|
88
|
+
/**
|
|
89
|
+
* AES-CTR 加密
|
|
90
|
+
*/
|
|
91
|
+
private _encryptAesCtr;
|
|
92
|
+
/**
|
|
93
|
+
* AES-CTR 解密
|
|
94
|
+
*/
|
|
95
|
+
private _decryptAesCtr;
|
|
96
|
+
/**
|
|
97
|
+
* AES-GCM 加密(带认证)
|
|
98
|
+
*/
|
|
99
|
+
private _encryptAesGcm;
|
|
100
|
+
/**
|
|
101
|
+
* AES-GCM 解密
|
|
102
|
+
*/
|
|
103
|
+
private _decryptAesGcm;
|
|
104
|
+
/**
|
|
105
|
+
* RC4 加密(手写实现,支持流式加密和偏移量)
|
|
106
|
+
*
|
|
107
|
+
* ⚠️ 安全警告:RC4 已被认为不安全,存在多个已知漏洞
|
|
108
|
+
* - 不应用于生产环境
|
|
109
|
+
* - 仅用于演示和兼容旧系统
|
|
110
|
+
* - 建议使用 AES-CTR 或 ChaCha20 代替
|
|
111
|
+
*
|
|
112
|
+
* 注意:crypto-js 的 RC4 不支持偏移量,所以这里使用手写实现
|
|
113
|
+
*/
|
|
114
|
+
private _encryptRc4;
|
|
115
|
+
/**
|
|
116
|
+
* RC4 解密(与加密相同)
|
|
117
|
+
*/
|
|
118
|
+
private _decryptRc4;
|
|
119
|
+
/**
|
|
120
|
+
* ChaCha20 QuarterRound 函数
|
|
121
|
+
*/
|
|
122
|
+
private _chacha20QuarterRound;
|
|
123
|
+
/**
|
|
124
|
+
* ChaCha20 核心块函数
|
|
125
|
+
*/
|
|
126
|
+
private _chacha20Block;
|
|
127
|
+
/**
|
|
128
|
+
* ChaCha20 加密(手写实现,无第三方依赖)
|
|
129
|
+
*/
|
|
130
|
+
private _encryptChaCha20;
|
|
131
|
+
/**
|
|
132
|
+
* ChaCha20 解密(与加密相同)
|
|
133
|
+
*/
|
|
134
|
+
private _decryptChaCha20;
|
|
135
|
+
/**
|
|
136
|
+
* 设置块大小(用于性能优化)
|
|
137
|
+
* @param size 块大小(字节)
|
|
138
|
+
*/
|
|
139
|
+
setChunkSize(size: number): void;
|
|
140
|
+
/**
|
|
141
|
+
* 获取当前使用的算法
|
|
142
|
+
*/
|
|
143
|
+
getAlgorithm(): EncryptionAlgorithm;
|
|
144
|
+
/**
|
|
145
|
+
* 设置部分加密配置
|
|
146
|
+
* @param config 部分加密配置
|
|
147
|
+
* @example
|
|
148
|
+
* // 加密前 10%
|
|
149
|
+
* encryptor.setPartialEncryption({ type: 'percentage', percentage: 10 });
|
|
150
|
+
*
|
|
151
|
+
* // 加密前 5MB
|
|
152
|
+
* encryptor.setPartialEncryption({ type: 'size', bytes: 5 * 1024 * 1024 });
|
|
153
|
+
*
|
|
154
|
+
* // 加密整个文件
|
|
155
|
+
* encryptor.setPartialEncryption({ type: 'full' });
|
|
156
|
+
*/
|
|
157
|
+
setPartialEncryption(config: PartialEncryptionConfig): void;
|
|
158
|
+
/**
|
|
159
|
+
* 获取部分加密配置
|
|
160
|
+
*/
|
|
161
|
+
getPartialEncryption(): PartialEncryptionConfig;
|
|
162
|
+
/**
|
|
163
|
+
* 计算需要加密的字节数
|
|
164
|
+
* @param totalSize 文件总大小
|
|
165
|
+
* @returns 需要加密的字节数
|
|
166
|
+
*/
|
|
167
|
+
private _calculateEncryptBytes;
|
|
168
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件名/字符串加密类
|
|
3
|
+
* 提供可逆的文件名加密功能
|
|
4
|
+
* 使用 AES-CTR 模式产生短密文(流密码,输入多长输出多长)
|
|
5
|
+
*/
|
|
6
|
+
export declare class FsCrypt {
|
|
7
|
+
private static readonly FILENAME_MARKER_DELIMITER;
|
|
8
|
+
private password;
|
|
9
|
+
private salt;
|
|
10
|
+
private _initialized;
|
|
11
|
+
private reversibleKey;
|
|
12
|
+
private iv;
|
|
13
|
+
private filenameMarker;
|
|
14
|
+
constructor(password: string, salt: Uint8Array);
|
|
15
|
+
init(): Promise<FsCrypt>;
|
|
16
|
+
private createFilenameMarker;
|
|
17
|
+
private hasCurrentMarker;
|
|
18
|
+
private stripCurrentMarker;
|
|
19
|
+
reversibleEncrypt(filename: string): Promise<string>;
|
|
20
|
+
reversibleDecrypt(encryptedName: string): Promise<string>;
|
|
21
|
+
encryptFilename(filename: string): Promise<string>;
|
|
22
|
+
decryptFilename(encryptedFilename: string): Promise<string>;
|
|
23
|
+
isEncrypted(filename: string): Promise<boolean>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 加密模块
|
|
3
|
+
* 提供文件名加密和文件流加密功能
|
|
4
|
+
* 支持部分加密:可以只加密文件的前面部分
|
|
5
|
+
*/
|
|
6
|
+
export { FsCrypt } from "./fs-crypt";
|
|
7
|
+
export { FileEncryptor, type EncryptionAlgorithm, type PartialEncryptionConfig, normalizeEncryptionAlgorithm, } from "./file-encryptor";
|
|
8
|
+
export { hexToUint8Array, arrayBufferToBase64Url, base64UrlToArrayBuffer, deriveKey, } from "./utils";
|
|
9
|
+
export { DEFAULT_ENCRYPTION_SALT_HEX, CONTENT_ENCRYPTION_EXTENSION, normalizeEncryptionFeatureEnabled, isFilenameEncryptionEnabled, isContentEncryptionEnabled, addContentEncryptionSuffix, stripContentEncryptionSuffix, isContentEncryptedName, calculateEncryptedBytes, normalizeEncryptionSaltHex, normalizePartialEncryption, resolveEncryptionProfile, applyEncryptionQueryParams, parseEncryptionQueryParams, type EncryptionProfile, } from "./protocol";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type EncryptionAlgorithm, type PartialEncryptionConfig } from "./file-encryptor";
|
|
2
|
+
export declare const DEFAULT_ENCRYPTION_SALT_HEX = "66697865642d73616c742d656d652d636f7272656374";
|
|
3
|
+
export declare const CONTENT_ENCRYPTION_EXTENSION = ".enc";
|
|
4
|
+
export interface EncryptionProfile {
|
|
5
|
+
password: string;
|
|
6
|
+
saltHex: string;
|
|
7
|
+
salt: Uint8Array;
|
|
8
|
+
algorithm: EncryptionAlgorithm;
|
|
9
|
+
partialEncryption: PartialEncryptionConfig;
|
|
10
|
+
}
|
|
11
|
+
export declare function normalizeEncryptionFeatureEnabled(value: unknown, fallback?: boolean): boolean;
|
|
12
|
+
export declare function isFilenameEncryptionEnabled(config?: Record<string, any>): boolean;
|
|
13
|
+
export declare function isContentEncryptionEnabled(config?: Record<string, any>): boolean;
|
|
14
|
+
export declare function normalizeEncryptionSaltHex(value?: string | null): string;
|
|
15
|
+
export declare function normalizePartialEncryption(config?: PartialEncryptionConfig | null): PartialEncryptionConfig;
|
|
16
|
+
export declare function calculateEncryptedBytes(totalSize: number, config?: PartialEncryptionConfig | null): number;
|
|
17
|
+
export declare function resolveEncryptionProfile(input?: {
|
|
18
|
+
password?: string | null;
|
|
19
|
+
salt?: string | null;
|
|
20
|
+
algorithm?: string | null;
|
|
21
|
+
partialEncryption?: PartialEncryptionConfig | null;
|
|
22
|
+
}): EncryptionProfile;
|
|
23
|
+
export declare function isContentEncryptedName(name: string): boolean;
|
|
24
|
+
export declare function addContentEncryptionSuffix(name: string): string;
|
|
25
|
+
export declare function stripContentEncryptionSuffix(name: string): string;
|
|
26
|
+
export declare function applyEncryptionQueryParams(url: URL, profile: Pick<EncryptionProfile, "algorithm" | "partialEncryption">): URL;
|
|
27
|
+
export declare function parseEncryptionQueryParams(url: URL): Partial<Pick<EncryptionProfile, "algorithm" | "partialEncryption">> | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具函数
|
|
3
|
+
*/
|
|
4
|
+
export declare function hexToUint8Array(hexString: string): Uint8Array;
|
|
5
|
+
export declare function arrayBufferToBase64Url(buffer: Uint8Array): string;
|
|
6
|
+
export declare function base64UrlToArrayBuffer(base64Url: string): Uint8Array;
|
|
7
|
+
export declare function deriveKey(password: string, salt: Uint8Array, keyLength?: number): Promise<Uint8Array>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { FsCrypt, FileEncryptor, normalizeEncryptionAlgorithm, DEFAULT_ENCRYPTION_SALT_HEX, CONTENT_ENCRYPTION_EXTENSION, normalizeEncryptionFeatureEnabled, isFilenameEncryptionEnabled, isContentEncryptionEnabled, addContentEncryptionSuffix, stripContentEncryptionSuffix, isContentEncryptedName, calculateEncryptedBytes, normalizeEncryptionSaltHex, normalizePartialEncryption, resolveEncryptionProfile, applyEncryptionQueryParams, parseEncryptionQueryParams, hexToUint8Array, arrayBufferToBase64Url, base64UrlToArrayBuffer, deriveKey, } from "./crypt/index";
|
|
2
|
+
export type { EncryptionAlgorithm, PartialEncryptionConfig, EncryptionProfile, } from "./crypt/index.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
export declare const createDebug: (namespace: string) => debug.Debugger;
|
|
3
|
+
export declare const coreDebug: debug.Debugger;
|
|
4
|
+
export declare const fsDebug: debug.Debugger;
|
|
5
|
+
export declare const volumeDebug: debug.Debugger;
|
|
6
|
+
export declare const pathDebug: debug.Debugger;
|
|
7
|
+
export declare const cacheDebug: debug.Debugger;
|
|
8
|
+
export declare const pluginDebug: debug.Debugger;
|
|
9
|
+
export default debug;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MatchMode } from "./enums";
|
|
2
|
+
interface Filter {
|
|
3
|
+
name: string | null;
|
|
4
|
+
size: string | null;
|
|
5
|
+
type: string | null;
|
|
6
|
+
mode: MatchMode;
|
|
7
|
+
}
|
|
8
|
+
export declare function filterList(data: any[], filter: Filter): {
|
|
9
|
+
filteredFiles: any[];
|
|
10
|
+
unfilteredFiles: any[];
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import FileSystem from ".";
|
|
2
|
+
import Stat from "../stat";
|
|
3
|
+
interface Folder {
|
|
4
|
+
id: string;
|
|
5
|
+
thumb: string;
|
|
6
|
+
name: string;
|
|
7
|
+
size: string;
|
|
8
|
+
created: string;
|
|
9
|
+
mtime: string;
|
|
10
|
+
ext: string;
|
|
11
|
+
fullPath: string;
|
|
12
|
+
type: string;
|
|
13
|
+
bytes: string;
|
|
14
|
+
}
|
|
15
|
+
declare class Http extends FileSystem<Folder> {
|
|
16
|
+
getRecursiveKey(target: Folder): string | number;
|
|
17
|
+
constructor(options: any);
|
|
18
|
+
get(_: any, path: string): Promise<{
|
|
19
|
+
name: string;
|
|
20
|
+
href: string;
|
|
21
|
+
mtime: string;
|
|
22
|
+
size: string;
|
|
23
|
+
type: string | false;
|
|
24
|
+
}>;
|
|
25
|
+
link(stat: Stat): Promise<{}>;
|
|
26
|
+
request(path: string): Promise<string>;
|
|
27
|
+
fetchList(path: string): Promise<Folder[]>;
|
|
28
|
+
parseHtml(ctx: any): Folder[];
|
|
29
|
+
getThumbnail(target: Folder): string;
|
|
30
|
+
getId(target: Folder): string;
|
|
31
|
+
getName(target: Folder): string;
|
|
32
|
+
getSize(target: Folder): string;
|
|
33
|
+
getBytes(target: Folder): string;
|
|
34
|
+
getCreated(target: Folder): string;
|
|
35
|
+
getCTime(target: Folder): string;
|
|
36
|
+
getMTime(target: Folder): string;
|
|
37
|
+
getExt(target: Folder): string;
|
|
38
|
+
isFile(target: Folder): boolean;
|
|
39
|
+
}
|
|
40
|
+
export default Http;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import Stat from "../stat";
|
|
2
|
+
import { Cache } from "../cache";
|
|
3
|
+
import { Mode } from "../enums";
|
|
4
|
+
export interface FileSystemType<T> {
|
|
5
|
+
mkdir?: (stat: Stat, name: string) => Promise<any>;
|
|
6
|
+
remove?: (stat: Stat) => Promise<any>;
|
|
7
|
+
rename?: (stat: Stat, name: string) => Promise<any>;
|
|
8
|
+
copy?: (source: Stat, target: Stat) => Promise<any>;
|
|
9
|
+
move?: (source: Stat, target: Stat) => Promise<any>;
|
|
10
|
+
link?: (stat: Stat) => Promise<any>;
|
|
11
|
+
fetchList: (id: string | number) => Promise<any>;
|
|
12
|
+
search?: (data: any) => Promise<any>;
|
|
13
|
+
rapidupload?: (stat: Stat, file: any) => Promise<any>;
|
|
14
|
+
upload?: (stat: Stat, file: any) => Promise<any>;
|
|
15
|
+
share?: (stat: Stat, obj: any) => Promise<any>;
|
|
16
|
+
save?: (stat: Stat, obj: any) => Promise<any>;
|
|
17
|
+
getThumbnail?: (target: T) => string;
|
|
18
|
+
getRecursiveKey?: (target: T) => string | number;
|
|
19
|
+
getId: (target: T) => string | number;
|
|
20
|
+
getName: (target: T) => string;
|
|
21
|
+
getSize: (target: T) => string | number | null;
|
|
22
|
+
getATime?: (target: T) => string | number | null;
|
|
23
|
+
getCTime?: (target: T) => string | number;
|
|
24
|
+
getMTime: (target: T) => string | number;
|
|
25
|
+
getHash?: (target: T) => any;
|
|
26
|
+
getQuota?: (target: T) => any;
|
|
27
|
+
getExt: (target: T) => string;
|
|
28
|
+
isFile: (target: T) => boolean;
|
|
29
|
+
isEmpty?: (target: T) => boolean;
|
|
30
|
+
}
|
|
31
|
+
interface FSConfig {
|
|
32
|
+
cid?: string;
|
|
33
|
+
name: string;
|
|
34
|
+
provider: string;
|
|
35
|
+
ttl?: number;
|
|
36
|
+
userConfig?: any;
|
|
37
|
+
auth?: any;
|
|
38
|
+
rootPath: string;
|
|
39
|
+
cacheStrategy: any;
|
|
40
|
+
}
|
|
41
|
+
declare abstract class FileSystem<T> implements FileSystemType<T> {
|
|
42
|
+
private cid;
|
|
43
|
+
mode: Mode;
|
|
44
|
+
private name;
|
|
45
|
+
private provider;
|
|
46
|
+
private downExpireTime;
|
|
47
|
+
private userConfig;
|
|
48
|
+
workPath: string;
|
|
49
|
+
cache?: Cache;
|
|
50
|
+
root: any;
|
|
51
|
+
protected auth: any;
|
|
52
|
+
private duplicateList;
|
|
53
|
+
constructor(fsConfig: FSConfig);
|
|
54
|
+
private initCache;
|
|
55
|
+
private initProxy;
|
|
56
|
+
private parse;
|
|
57
|
+
private getCacheOrFetch;
|
|
58
|
+
private isRoot;
|
|
59
|
+
private resolvePath;
|
|
60
|
+
list(path: string, options: {
|
|
61
|
+
pagination: {
|
|
62
|
+
page: number;
|
|
63
|
+
pageSize: number;
|
|
64
|
+
};
|
|
65
|
+
sort: {
|
|
66
|
+
field: string;
|
|
67
|
+
order: string;
|
|
68
|
+
};
|
|
69
|
+
}): Promise<any>;
|
|
70
|
+
private getListByPath;
|
|
71
|
+
private getListByRecursive;
|
|
72
|
+
private unwrapListPayload;
|
|
73
|
+
formatList(resp: any[], workPath: string, path: string): any[];
|
|
74
|
+
format(data: any, workPath: string): Stat;
|
|
75
|
+
private findTarget;
|
|
76
|
+
hasMethod(method: string): boolean;
|
|
77
|
+
private getCacheKey;
|
|
78
|
+
private getRealPath;
|
|
79
|
+
abstract getName(data: T): string;
|
|
80
|
+
abstract getId(data: T): number | string;
|
|
81
|
+
abstract getThumbnail?(data: T): string;
|
|
82
|
+
abstract getSize(data: T): number | string | null;
|
|
83
|
+
abstract getCTime?(data: T): number | string;
|
|
84
|
+
abstract getMTime(data: T): number | string;
|
|
85
|
+
abstract getExt(data: T): string;
|
|
86
|
+
abstract isFile(data: T): boolean;
|
|
87
|
+
abstract fetchList(keyOrPath: string | number, options?: any): Promise<any>;
|
|
88
|
+
abstract getRecursiveKey(target: T): string | number;
|
|
89
|
+
getATime?(data: T): number | string;
|
|
90
|
+
getQuota?(data: T): any;
|
|
91
|
+
getHash?(data: T): any;
|
|
92
|
+
search?(data: any): Promise<any>;
|
|
93
|
+
[key: string]: any;
|
|
94
|
+
}
|
|
95
|
+
export default FileSystem;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Emitter, EventType } from "mitt";
|
|
2
|
+
import { Volume, ReadOnlyVolume } from "./volume";
|
|
3
|
+
import Stat from "./stat";
|
|
4
|
+
import Plugin from "./plugin";
|
|
5
|
+
import { ICacheStrategy } from "./cache";
|
|
6
|
+
export type EventCallback = (...args: any[]) => Promise<any> | any;
|
|
7
|
+
interface FileBoxOptions {
|
|
8
|
+
events?: Record<string, EventCallback | EventCallback[]>;
|
|
9
|
+
plugins?: Array<any>;
|
|
10
|
+
cacheStrategy?: ICacheStrategy;
|
|
11
|
+
}
|
|
12
|
+
declare class FileBox {
|
|
13
|
+
options: FileBoxOptions;
|
|
14
|
+
emitter: Emitter<Record<EventType, any>>;
|
|
15
|
+
volumeMap: Map<string, any>;
|
|
16
|
+
fs: any;
|
|
17
|
+
static plugin: typeof Plugin;
|
|
18
|
+
cacheStrategy?: ICacheStrategy;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
constructor(options?: FileBoxOptions);
|
|
21
|
+
static use(module: any): typeof FileBox;
|
|
22
|
+
getProvider(provider: string): any;
|
|
23
|
+
mount(options: any): Promise<Volume & ReadOnlyVolume & any>;
|
|
24
|
+
mountRaw(options: any): void;
|
|
25
|
+
unmount(volume: any): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 设置全局缓存策略
|
|
28
|
+
*/
|
|
29
|
+
setCache(cacheStrategy: ICacheStrategy): void;
|
|
30
|
+
/**
|
|
31
|
+
* 获取全局缓存策略
|
|
32
|
+
*/
|
|
33
|
+
getCache(): ICacheStrategy | undefined;
|
|
34
|
+
readFile(path: string): Promise<any>;
|
|
35
|
+
stat(path: string): Promise<any>;
|
|
36
|
+
list(path: string, options?: any): Promise<any>;
|
|
37
|
+
mkdir(path: string | Stat, options?: any): Promise<any>;
|
|
38
|
+
rename(path: string | Stat, newName: string): Promise<any>;
|
|
39
|
+
remove(path: string | Stat): Promise<any>;
|
|
40
|
+
upload(path: string, file: any, uploadProgress?: any): Promise<any>;
|
|
41
|
+
download(path: string, options?: any): Promise<any>;
|
|
42
|
+
copy(src: string, dest: string, options?: any): Promise<any>;
|
|
43
|
+
move(src: string, dest: string, options?: any): Promise<any>;
|
|
44
|
+
bulkRemove(options: any): Promise<any>;
|
|
45
|
+
_getProvider(path: string): {
|
|
46
|
+
fs: any;
|
|
47
|
+
driverPath: string;
|
|
48
|
+
};
|
|
49
|
+
getVolume(volume?: string, _options?: any): any;
|
|
50
|
+
}
|
|
51
|
+
export default FileBox;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import pathBrowserify from "path-browserify";
|
|
2
|
+
export declare const basename: (this: void, path: string, ext?: string) => string, dirname: (this: void, path: string) => string, extname: (this: void, path: string) => string, format: (this: void, pathObject: Partial<pathBrowserify.PathObject>) => string, isAbsolute: (this: void, path: string) => boolean, join: (this: void, ...paths: string[]) => string, normalize: (this: void, path: string) => string, parse: (this: void, path: string) => pathBrowserify.PathObject, relative: (this: void, from: string, to: string) => string, resolve: (this: void, ...pathSegments: string[]) => string, sep: string, delimiter: string;
|
|
3
|
+
/**
|
|
4
|
+
* 将路径分割为[目录, 最后一部分]
|
|
5
|
+
* @example
|
|
6
|
+
* reverseSplist('/foo/bar/baz') => ['/foo/bar', 'baz']
|
|
7
|
+
* reverseSplist('foo/bar') => ['foo', 'bar']
|
|
8
|
+
*/
|
|
9
|
+
export declare function reverseSplist(path: string): [string, string];
|
|
10
|
+
/**
|
|
11
|
+
* 将路径转换为数组形式
|
|
12
|
+
* @example
|
|
13
|
+
* toArray('/foo/bar/baz') => ['foo', 'bar', 'baz']
|
|
14
|
+
*/
|
|
15
|
+
export declare function toArray(path: string, sep?: string): string[];
|
|
16
|
+
/**
|
|
17
|
+
* 分割路径为[挂载点, 相对路径]
|
|
18
|
+
* @example
|
|
19
|
+
* split('/drive1/foo/bar') => ['drive1', '/foo/bar']
|
|
20
|
+
*/
|
|
21
|
+
export declare function split(path: string, options?: {
|
|
22
|
+
separator?: string;
|
|
23
|
+
normalizeFirst?: boolean;
|
|
24
|
+
}): [string, string];
|
|
25
|
+
/**
|
|
26
|
+
* 检查路径是否为根路径
|
|
27
|
+
*/
|
|
28
|
+
export declare function isRoot(path: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 获取路径的上级目录和文件名
|
|
31
|
+
*/
|
|
32
|
+
export declare function getParentAndName(path: string): {
|
|
33
|
+
parent: string;
|
|
34
|
+
name: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* 合并多个路径段
|
|
38
|
+
*/
|
|
39
|
+
export declare function joinPath(...paths: string[]): string;
|
|
40
|
+
/**
|
|
41
|
+
* 规范化路径(简化别名)
|
|
42
|
+
*/
|
|
43
|
+
export declare function normalizePath(path: string): string;
|
|
44
|
+
declare const _default: {
|
|
45
|
+
basename: (this: void, path: string, ext?: string) => string;
|
|
46
|
+
dirname: (this: void, path: string) => string;
|
|
47
|
+
extname: (this: void, path: string) => string;
|
|
48
|
+
format: (this: void, pathObject: Partial<pathBrowserify.PathObject>) => string;
|
|
49
|
+
isAbsolute: (this: void, path: string) => boolean;
|
|
50
|
+
join: (this: void, ...paths: string[]) => string;
|
|
51
|
+
normalize: (this: void, path: string) => string;
|
|
52
|
+
parse: (this: void, path: string) => pathBrowserify.PathObject;
|
|
53
|
+
relative: (this: void, from: string, to: string) => string;
|
|
54
|
+
resolve: (this: void, ...pathSegments: string[]) => string;
|
|
55
|
+
sep: string;
|
|
56
|
+
delimiter: string;
|
|
57
|
+
reverseSplist: typeof reverseSplist;
|
|
58
|
+
toArray: typeof toArray;
|
|
59
|
+
split: typeof split;
|
|
60
|
+
isRoot: typeof isRoot;
|
|
61
|
+
getParentAndName: typeof getParentAndName;
|
|
62
|
+
joinPath: typeof joinPath;
|
|
63
|
+
normalizePath: typeof normalizePath;
|
|
64
|
+
};
|
|
65
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare class Plugin {
|
|
2
|
+
private static plugins;
|
|
3
|
+
constructor();
|
|
4
|
+
static get(name: string): any;
|
|
5
|
+
static has(name: string): boolean;
|
|
6
|
+
static list(): any[];
|
|
7
|
+
static values(): MapIterator<any>;
|
|
8
|
+
static keys(): MapIterator<string>;
|
|
9
|
+
static entries(): MapIterator<[string, any]>;
|
|
10
|
+
static get size(): number;
|
|
11
|
+
static install(plugin: any): void;
|
|
12
|
+
static uninstall(name: string): void;
|
|
13
|
+
onload(): void;
|
|
14
|
+
unload(): void;
|
|
15
|
+
}
|
|
16
|
+
export default Plugin;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
declare const rawDataSymbol: unique symbol;
|
|
2
|
+
export interface IStat {
|
|
3
|
+
id: string | number;
|
|
4
|
+
name: string;
|
|
5
|
+
size: any;
|
|
6
|
+
byte: number | null;
|
|
7
|
+
thumbnail: string | null;
|
|
8
|
+
atime?: string | null;
|
|
9
|
+
ctime?: string | null;
|
|
10
|
+
mtime: string | null;
|
|
11
|
+
type: string | null;
|
|
12
|
+
hash?: {
|
|
13
|
+
md5?: string;
|
|
14
|
+
sha1?: string;
|
|
15
|
+
sha256?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export type StatConstructorParams = Omit<IStat, "rawData"> & {
|
|
19
|
+
rawData?: Record<string, any>;
|
|
20
|
+
parsePath: string;
|
|
21
|
+
rootPath: string;
|
|
22
|
+
mountPath: string;
|
|
23
|
+
provider: string;
|
|
24
|
+
duplicate?: number;
|
|
25
|
+
cid?: string | null;
|
|
26
|
+
};
|
|
27
|
+
declare class Stat implements IStat {
|
|
28
|
+
#private;
|
|
29
|
+
id: IStat["id"];
|
|
30
|
+
name: IStat["name"];
|
|
31
|
+
original_name: IStat["name"];
|
|
32
|
+
size: IStat["size"];
|
|
33
|
+
byte: IStat["byte"];
|
|
34
|
+
thumbnail: IStat["thumbnail"];
|
|
35
|
+
atime: IStat["atime"];
|
|
36
|
+
ctime: IStat["ctime"];
|
|
37
|
+
mtime: IStat["mtime"];
|
|
38
|
+
type: IStat["type"];
|
|
39
|
+
hash: IStat["hash"];
|
|
40
|
+
provider: string;
|
|
41
|
+
mountPath: string;
|
|
42
|
+
parent: string;
|
|
43
|
+
path: string;
|
|
44
|
+
relative: string;
|
|
45
|
+
is_duplicate: boolean;
|
|
46
|
+
duplicate_num: number;
|
|
47
|
+
duplicate_flag: string;
|
|
48
|
+
fid: number;
|
|
49
|
+
cid: string | null;
|
|
50
|
+
mime: string | boolean;
|
|
51
|
+
driver_name: string;
|
|
52
|
+
isStat: boolean;
|
|
53
|
+
basename: string;
|
|
54
|
+
[rawDataSymbol]: any;
|
|
55
|
+
constructor({ id, name, size, thumbnail, type, atime, ctime, mtime, rawData, provider, mountPath, parsePath, rootPath, hash, duplicate, cid, }: StatConstructorParams);
|
|
56
|
+
private formatDate;
|
|
57
|
+
private normalizePath;
|
|
58
|
+
getRawData(key?: string): any;
|
|
59
|
+
get file(): boolean;
|
|
60
|
+
get directory(): boolean;
|
|
61
|
+
get rootPath(): string;
|
|
62
|
+
get realPath(): string;
|
|
63
|
+
}
|
|
64
|
+
export default Stat;
|