@nocobase/plugin-file-manager
Version:
Provides files storage services with files collection template and attachment field.
74 lines (73 loc) • 2.23 kB
TypeScript
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
/// <reference types="node" />
import { StorageEngine } from 'multer';
import type { Readable } from 'stream';
export interface StorageModel {
id?: number;
title: string;
type: string;
name: string;
baseUrl: string;
renameMode?: string;
options: Record<string, any>;
rules?: Record<string, any>;
path?: string;
default?: boolean;
paranoid?: boolean;
settings?: Record<string, any>;
}
export interface AttachmentModel {
id?: number;
title: string;
filename: string;
mimetype?: string;
path: string;
url?: string;
storageId?: number | null;
source?: {
dataSourceKey?: string;
collectionName?: string;
field?: string;
documentCache?: boolean;
trustworthy?: boolean;
};
}
export declare abstract class StorageType {
storage: StorageModel;
static defaults(): StorageModel;
static filenameKey?: string;
constructor(storage: StorageModel);
abstract make(): StorageEngine;
abstract delete(records: AttachmentModel[]): [number, AttachmentModel[]] | Promise<[number, AttachmentModel[]]>;
exists(record: AttachmentModel): Promise<boolean>;
copy(source: AttachmentModel, target: AttachmentModel): Promise<void>;
getFileKey(record: AttachmentModel): any;
getFileData(file: any, meta?: {}): {
title: string;
filename: string;
extname: string;
path: string;
size: any;
mimetype: any;
meta: {};
storageId: number;
};
getFileURL(file: AttachmentModel, preview?: boolean): string | Promise<string>;
getFileStream(file: AttachmentModel, options?: GetFileStreamOptions): Promise<{
stream: Readable;
contentType?: string;
}>;
}
export type StorageClassType = {
new (storage: StorageModel): StorageType;
} & typeof StorageType;
export type GetFileStreamOptions = {
requestOptions?: any;
};