mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
* start supporting isolatedDeclarations
* add errors and storage package
* add utils, and storage-driver-local
* fix rest of packages
* fix types/collab import
* hardcode "isolatedDeclarations": true in all configs for now
* Revert "hardcode "isolatedDeclarations": true in all configs for now"
This reverts commit ac71582159.
* fix formatting
* undo readme change
* remove link
* fix lockfile
* dont do a js string cast here I guess
* use tsc over tsdown because of failing tests
* last fixes
* use tsdown --clean instead of rimraf
* fmt and fixes
* re add weird space
* add run as entry
* undo api using tsdown
* switch back to tsdown again now with unbundle 🥳
* more ts fixes
* build with tsdown in @directus/themes
* fix bb tests
* undo spaces
* another space
* fix collab import
* add changeset
* Apply suggestion from @ComfortablyCoding
* Apply suggestion from @ComfortablyCoding
* Update .changeset/hungry-yaks-enter.md
Co-authored-by: judda <44623501+ComfortablyCoding@users.noreply.github.com>
---------
Co-authored-by: judda <44623501+ComfortablyCoding@users.noreply.github.com>
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import type { Readable } from 'node:stream';
|
|
import type { ChunkedUploadContext, Range, ReadOptions, Stat } from '@directus/types';
|
|
|
|
export class StorageManager {
|
|
private drivers = new Map<string, typeof Driver>();
|
|
private locations = new Map<string, Driver>();
|
|
|
|
registerDriver(name: string, driver: typeof Driver): void {
|
|
this.drivers.set(name, driver);
|
|
}
|
|
|
|
registerLocation(name: string, config: DriverConfig): void {
|
|
const driverName = config.driver;
|
|
|
|
const Driver = this.drivers.get(driverName);
|
|
|
|
if (!Driver) {
|
|
throw new Error(`Driver "${driverName}" isn't registered.`);
|
|
}
|
|
|
|
this.locations.set(name, new Driver(config.options));
|
|
}
|
|
|
|
location(name: string): Driver {
|
|
const driver = this.locations.get(name);
|
|
|
|
if (!driver) {
|
|
throw new Error(`Location "${name}" doesn't exist.`);
|
|
}
|
|
|
|
return driver;
|
|
}
|
|
}
|
|
|
|
export declare class Driver {
|
|
constructor(config: Record<string, unknown>);
|
|
|
|
read(filepath: string, options?: ReadOptions): Promise<Readable>;
|
|
write(filepath: string, content: Readable, type?: string): Promise<void>;
|
|
delete(filepath: string): Promise<void>;
|
|
stat(filepath: string): Promise<Stat>;
|
|
exists(filepath: string): Promise<boolean>;
|
|
move(src: string, dest: string): Promise<void>;
|
|
copy(src: string, dest: string): Promise<void>;
|
|
list(prefix?: string): AsyncIterable<string>;
|
|
}
|
|
|
|
export interface TusDriver extends Driver {
|
|
get tusExtensions(): string[];
|
|
|
|
createChunkedUpload(filepath: string, context: ChunkedUploadContext): Promise<ChunkedUploadContext>;
|
|
finishChunkedUpload(filepath: string, context: ChunkedUploadContext): Promise<void>;
|
|
deleteChunkedUpload(filepath: string, context: ChunkedUploadContext): Promise<void>;
|
|
writeChunk(filepath: string, content: Readable, offset: number, context: ChunkedUploadContext): Promise<number>;
|
|
}
|
|
|
|
export function supportsTus(driver: Driver): driver is TusDriver {
|
|
return 'tusExtensions' in driver;
|
|
}
|
|
|
|
export type DriverConfig = {
|
|
driver: string;
|
|
options: Record<string, unknown>;
|
|
};
|
|
|
|
export type { Range, Stat, ReadOptions, ChunkedUploadContext };
|