51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { Feature } from 'oak-frontend-base/es/types/Feature';
|
||
import { Cache } from 'oak-frontend-base/es/features/cache';
|
||
import { EntityDict } from '../oak-app-domain';
|
||
import { Application } from './application';
|
||
import { OpSchema } from '../oak-app-domain/ExtraFile/Schema';
|
||
import { Cos } from '../types/Cos';
|
||
export type FileState = 'local' | 'uploading' | 'uploaded' | 'failed';
|
||
export interface ChunkOptions {
|
||
chunkSize: number;
|
||
parallelism?: number;
|
||
retryTimes?: number;
|
||
retryDelay?: number;
|
||
}
|
||
export declare class ExtraFile<ED extends EntityDict> extends Feature {
|
||
private cache;
|
||
private application;
|
||
private files;
|
||
private fileUpLoad;
|
||
private uploadIdToTaskId;
|
||
constructor(cache: Cache<ED>, application: Application<ED>);
|
||
registerCos(clazzes: Array<new () => Cos<ED>>): void;
|
||
addLocalFile(id: string, file: File | string): void;
|
||
removeLocalFiles(ids: string[]): void;
|
||
upload(id: string): Promise<void>;
|
||
getUrl(extraFile?: Partial<EntityDict['extraFile']['OpSchema']>, style?: string): string;
|
||
getFileState(id: string): {
|
||
state: FileState;
|
||
percentage?: number;
|
||
} | undefined;
|
||
getFileName(extraFile: ED['extraFile']['OpSchema']): string;
|
||
formatBytes(size: number): string;
|
||
autoUpload(options: {
|
||
extraFile: ED['extraFile']['OpSchema'];
|
||
file: File | string;
|
||
style?: string;
|
||
getPercent?: Function;
|
||
chunkOptions?: ChunkOptions;
|
||
}): Promise<string>;
|
||
/**
|
||
* 中止上传
|
||
* @param extraFileId ExtraFile的ID
|
||
*/
|
||
abortUpload(extraFileId: string): void;
|
||
private doUpload;
|
||
private uploadToAspect;
|
||
/**
|
||
* 生成上传ID列表,请确保在cos实现时,该方法生成的ID与upload方法中调用的上传接口的任务ID一致
|
||
*/
|
||
generateUploadId(extraFile: Partial<OpSchema>): string[];
|
||
}
|