mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: storage: prefer lowercase filename
This commit is contained in:
1 file changed
+3
-3
@@ -14,7 +14,7 @@ export class StorageModel {
|
|||||||
static coll = db.collection('storage');
|
static coll = db.collection('storage');
|
||||||
|
|
||||||
static generateId(ext: string) {
|
static generateId(ext: string) {
|
||||||
return `${nanoid(3).replace(/[_-]/g, '0')}/${nanoid().replace(/[_-]/g, '0')}${ext}`;
|
return `${nanoid(3).replace(/[_-]/g, '0')}/${nanoid().replace(/[_-]/g, '0')}${ext}`.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
static async put(path: string, file: string | Buffer | Readable, owner?: number) {
|
static async put(path: string, file: string | Buffer | Readable, owner?: number) {
|
||||||
@@ -106,10 +106,10 @@ export class StorageModel {
|
|||||||
meta['Content-Type'] = (dst.endsWith('.ans') || dst.endsWith('.out'))
|
meta['Content-Type'] = (dst.endsWith('.ans') || dst.endsWith('.out'))
|
||||||
? 'text/plain'
|
? 'text/plain'
|
||||||
: lookup(dst) || 'application/octet-stream';
|
: lookup(dst) || 'application/octet-stream';
|
||||||
let _id = `${nanoid(3)}/${nanoid()}${extname(dst)}`;
|
let _id = StorageModel.generateId(extname(dst));
|
||||||
// Make sure id is not used
|
// Make sure id is not used
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
while (await StorageModel.coll.findOne({ _id })) _id = `${nanoid(3)}/${nanoid()}${extname(dst)}`;
|
while (await StorageModel.coll.findOne({ _id })) _id = StorageModel.generateId(extname(dst));
|
||||||
const result = await storage.copy(value._id, dst);
|
const result = await storage.copy(value._id, dst);
|
||||||
const { metaData, size, etag } = await storage.getMeta(_id);
|
const { metaData, size, etag } = await storage.getMeta(_id);
|
||||||
await StorageModel.coll.insertOne({
|
await StorageModel.coll.insertOne({
|
||||||
|
|||||||
Reference in new issue
Block a user