core: support move() and exists() operation

This commit is contained in:
undefined committed 2024-10-18 11:01:06 +08:00
1 parent 76b2edba8c
commit ba8f81d6e9
1 file changed
+13
+13
View File
@@ -123,6 +123,19 @@ export class StorageModel {
return await storage.signDownloadLink(res.value?.link || res.value?._id || target, filename, noExpire, useAlternativeEndpointFor);
}
static async move(src: string, dst: string) {
const res = await StorageModel.coll.findOneAndUpdate(
{ path: src, autoDelete: null },
{ $set: { path: dst } },
);
return !!res.value;
}
static async exists(path: string) {
const value = await StorageModel.coll.findOne({ path, autoDelete: null });
return !!value;
}
static async copy(src: string, dst: string) {
const { value } = await StorageModel.coll.findOneAndUpdate(
{ path: src, autoDelete: null },