2024-06-10 14:47:20 +00:00
|
|
|
import * as plugins from './plugins.js';
|
|
|
|
import * as interfaces from './interfaces.js';
|
|
|
|
import * as helpers from './helpers.js';
|
|
|
|
import type { Bucket } from './classes.bucket.js';
|
|
|
|
import type { Directory } from './classes.directory.js';
|
|
|
|
import type { File } from './classes.file.js';
|
|
|
|
|
|
|
|
|
|
|
|
export class Trash {
|
|
|
|
public bucketRef: Bucket;
|
|
|
|
|
|
|
|
constructor(bucketRefArg: Bucket) {
|
|
|
|
this.bucketRef = bucketRefArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getTrashDir() {
|
|
|
|
return this.bucketRef.getDirectoryFromPath({ path: '.trash' });
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getTrashedFileByOriginalName(pathDescriptor: interfaces.IPathDecriptor): Promise<File> {
|
2024-06-11 15:20:48 +00:00
|
|
|
const trashDir = await this.getTrashDir();
|
|
|
|
const originalPath = await helpers.reducePathDescriptorToPath(pathDescriptor);
|
|
|
|
const trashKey = await this.getTrashKeyByOriginalBasePath(originalPath);
|
2024-06-18 16:44:58 +00:00
|
|
|
return trashDir.getFile({ path: trashKey });
|
2024-06-10 14:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async getTrashKeyByOriginalBasePath (originalPath: string): Promise<string> {
|
|
|
|
return plugins.smartstring.base64.encode(originalPath);
|
|
|
|
}
|
|
|
|
}
|