✨ back: add enumeratePathsForFile to storage api (#799)
This commit is contained in:
committed by
Anton Shepilov
parent
34ff3e38f1
commit
193f2ee3fe
@@ -149,4 +149,12 @@ export default class S3ConnectorService implements StorageConnectorAPI {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async enumeratePathsForFile(filePath: string): Promise<string[]> {
|
||||||
|
return (
|
||||||
|
await (
|
||||||
|
await this.client.listObjectsV2(this.minioConfiguration.bucket, filePath, true)
|
||||||
|
).toArray()
|
||||||
|
).map(({ name }) => name as string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,4 +104,10 @@ export default class LocalConnectorService implements StorageConnectorAPI {
|
|||||||
const fullPath = this.getFullPath(path);
|
const fullPath = this.getFullPath(path);
|
||||||
return fs.existsSync(fullPath);
|
return fs.existsSync(fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async enumeratePathsForFile(filePath: string): Promise<string[]> {
|
||||||
|
return (await fs.promises.readdir(this.getFullPath(filePath), { recursive: true })).map(
|
||||||
|
item => filePath + "/" + item,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ export class DefaultStorageStrategy implements StorageConnectorAPI {
|
|||||||
return this.connector.exists(path, options, context);
|
return this.connector.exists(path, options, context);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enumeratePathsForFile = (filePath: string): Promise<string[]> => {
|
||||||
|
return this.connector.enumeratePathsForFile(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
remove = (
|
remove = (
|
||||||
path: string,
|
path: string,
|
||||||
options?: DeleteOptions,
|
options?: DeleteOptions,
|
||||||
|
|||||||
@@ -158,6 +158,15 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** If any of the storages fails, then fail. Otherwise return a union of all paths related to that file's path */
|
||||||
|
async enumeratePathsForFile(filePath: string): Promise<string[]> {
|
||||||
|
const paths = new Set<string>();
|
||||||
|
// This needs all storages to respond. Until then, deletion must be retried, so fail.
|
||||||
|
for (const storage of this.storages)
|
||||||
|
for (const path of await storage.enumeratePathsForFile(filePath)) paths.add(path);
|
||||||
|
return [...paths.values()];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a file from all configured storages.
|
* Removes a file from all configured storages.
|
||||||
* @param path - The path of the file to be removed.
|
* @param path - The path of the file to be removed.
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ export interface StorageConnectorAPI extends IServiceDiagnosticProvider {
|
|||||||
* @param path
|
* @param path
|
||||||
*/
|
*/
|
||||||
remove(path: string, options?: DeleteOptions, context?: ExecutionContext): Promise<boolean>;
|
remove(path: string, options?: DeleteOptions, context?: ExecutionContext): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumerate all physical storage paths related to the provided file path
|
||||||
|
*/
|
||||||
|
enumeratePathsForFile(filePath: string): Promise<string[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default interface StorageAPI extends TdriveServiceProvider, StorageConnectorAPI {
|
export default interface StorageAPI extends TdriveServiceProvider, StorageConnectorAPI {
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ export default class StorageService extends TdriveService<StorageAPI> implements
|
|||||||
return this.getConnector().exists(path + "/chunk1", options);
|
return this.getConnector().exists(path + "/chunk1", options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enumeratePathsForFile(filePath: string): Promise<string[]> {
|
||||||
|
return this.getConnector().enumeratePathsForFile(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
async write(path: string, stream: Stream, options?: WriteOptions): Promise<WriteMetadata> {
|
async write(path: string, stream: Stream, options?: WriteOptions): Promise<WriteMetadata> {
|
||||||
try {
|
try {
|
||||||
if (options?.encryptionKey) {
|
if (options?.encryptionKey) {
|
||||||
|
|||||||
Reference in New Issue
Block a user