mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix deleted file handle
This commit is contained in:
1 parent
4f4359bb9b
commit
cee1fa7d96
2 files changed
+31
-8
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.32.22",
|
"version": "2.32.23",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -28,32 +28,52 @@ export class StorageModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async get(path: string, savePath?: string) {
|
static async get(path: string, savePath?: string) {
|
||||||
const { value } = await StorageModel.coll.findOneAndUpdate({ path }, { $set: { lastUsage: new Date() } }, { returnDocument: 'after' });
|
const { value } = await StorageModel.coll.findOneAndUpdate(
|
||||||
|
{ path, autoDelete: { $exists: false } },
|
||||||
|
{ $set: { lastUsage: new Date() } },
|
||||||
|
{ returnDocument: 'after' },
|
||||||
|
);
|
||||||
return await storage.get(value?._id || path, savePath);
|
return await storage.get(value?._id || path, savePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async rename(path: string, newPath: string) {
|
static async rename(path: string, newPath: string) {
|
||||||
return await StorageModel.coll.updateOne({ path }, { $set: { path: newPath } });
|
return await StorageModel.coll.updateOne(
|
||||||
|
{ path, autoDelete: { $exists: false } },
|
||||||
|
{ $set: { path: newPath } },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async del(path: string[]) {
|
static async del(path: string[]) {
|
||||||
const autoDelete = moment().add(7, 'day').toDate();
|
const autoDelete = moment().add(7, 'day').toDate();
|
||||||
await StorageModel.coll.updateMany({ path: { $in: path } }, { $set: { autoDelete } });
|
await StorageModel.coll.updateMany(
|
||||||
|
{ path: { $in: path }, autoDelete: { $exists: false } },
|
||||||
|
{ $set: { autoDelete } },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async list(target: string, recursive = true) {
|
static async list(target: string, recursive = true) {
|
||||||
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
|
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
|
||||||
if (target.length && !target.endsWith('/')) target += '/';
|
if (target.length && !target.endsWith('/')) target += '/';
|
||||||
const results = recursive
|
const results = recursive
|
||||||
? await StorageModel.coll.find({ path: { $regex: new RegExp(`^${escapeRegExp(target)}`, 'i') } }).toArray()
|
? await StorageModel.coll.find({
|
||||||
: await StorageModel.coll.find({ path: { $regex: new RegExp(`^${escapeRegExp(target)}[^/]+$`) } }).toArray();
|
path: { $regex: new RegExp(`^${escapeRegExp(target)}`, 'i') },
|
||||||
|
autoDelete: { $exists: false },
|
||||||
|
}).toArray()
|
||||||
|
: await StorageModel.coll.find({
|
||||||
|
path: { $regex: new RegExp(`^${escapeRegExp(target)}[^/]+$`) },
|
||||||
|
autoDelete: { $exists: false },
|
||||||
|
}).toArray();
|
||||||
return results.map((i) => ({
|
return results.map((i) => ({
|
||||||
...i, name: i.path.split(target)[1], prefix: target,
|
...i, name: i.path.split(target)[1], prefix: target,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getMeta(path: string) {
|
static async getMeta(path: string) {
|
||||||
const { value } = await StorageModel.coll.findOneAndUpdate({ path }, { $set: { lastUsage: new Date() } }, { returnDocument: 'after' });
|
const { value } = await StorageModel.coll.findOneAndUpdate(
|
||||||
|
{ path, autoDelete: { $exists: false } },
|
||||||
|
{ $set: { lastUsage: new Date() } },
|
||||||
|
{ returnDocument: 'after' },
|
||||||
|
);
|
||||||
if (!value) return null;
|
if (!value) return null;
|
||||||
return {
|
return {
|
||||||
...value.meta,
|
...value.meta,
|
||||||
@@ -64,7 +84,10 @@ export class StorageModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async signDownloadLink(target: string, filename?: string, noExpire = false, useAlternativeEndpointFor?: 'user' | 'judge') {
|
static async signDownloadLink(target: string, filename?: string, noExpire = false, useAlternativeEndpointFor?: 'user' | 'judge') {
|
||||||
const res = await StorageModel.coll.findOneAndUpdate({ path: target }, { $set: { lastUsage: new Date() } });
|
const res = await StorageModel.coll.findOneAndUpdate(
|
||||||
|
{ path: target, autoDelete: { $exists: false } },
|
||||||
|
{ $set: { lastUsage: new Date() } },
|
||||||
|
);
|
||||||
if (!res.value) return '';
|
if (!res.value) return '';
|
||||||
return await storage.signDownloadLink(res.value._id, filename, noExpire, useAlternativeEndpointFor);
|
return await storage.signDownloadLink(res.value._id, filename, noExpire, useAlternativeEndpointFor);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user