From 5f8d6f07c4a913abdb49160392b5e30e7d507d39 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Mon, 26 Aug 2024 12:03:54 +0000 Subject: [PATCH] fix: handle regex for windows --- packages/nocodb/src/db/BaseModelSqlv2.ts | 4 ++-- packages/nocodb/src/models/PresignedUrl.ts | 2 +- .../thumbnail-generator/thumbnail-generator.processor.ts | 6 +++--- packages/nocodb/src/plugins/mino/Minio.ts | 6 ++++-- packages/nocodb/src/plugins/storage/Local.ts | 9 ++++++--- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 5761abc8ce..fac240a4a8 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -8184,7 +8184,7 @@ class BaseModelSqlv2 { }; const thumbnailPath = `thumbnails/${lookedUpAttachment.path.replace( - /^download\//, + /^download[/\\]/i, '', )}`; @@ -8257,7 +8257,7 @@ class BaseModelSqlv2 { } const thumbnailPath = `thumbnails/${attachment.path.replace( - /^download\//, + /^download[/\\]/i, '', )}`; diff --git a/packages/nocodb/src/models/PresignedUrl.ts b/packages/nocodb/src/models/PresignedUrl.ts index 65db77d78d..3403ad400d 100644 --- a/packages/nocodb/src/models/PresignedUrl.ts +++ b/packages/nocodb/src/models/PresignedUrl.ts @@ -246,7 +246,7 @@ export default class PresignedUrl { if (attachment?.path) { nestedObj.signedPath = await PresignedUrl.getSignedUrl( { - pathOrUrl: attachment.path.replace(/^download\//, ''), + pathOrUrl: attachment.path.replace(/^download[/\\]/i, ''), preview, mimetype: mimetype || attachment.mimetype, ...(extra ? { ...extra } : {}), diff --git a/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts b/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts index 654008702a..25b8f54903 100644 --- a/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts +++ b/packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts @@ -75,7 +75,7 @@ export class ThumbnailGeneratorProcessor { tiny: path.join('nc', 'thumbnails', relativePath, 'tiny.jpg'), }; - const sharpImage = await sharp(file, { + const sharpImage = sharp(file, { limitInputPixels: false, }); @@ -135,7 +135,7 @@ export class ThumbnailGeneratorProcessor { relativePath = path.join( 'nc', 'uploads', - attachment.path.replace(/^download\//, ''), + attachment.path.replace(/^download[/\\]/i, ''), ); } else if (attachment.url) { relativePath = getPathFromUrl(attachment.url).replace(/^\/+/, ''); @@ -144,7 +144,7 @@ export class ThumbnailGeneratorProcessor { const file = await storageAdapter.fileRead(relativePath); // remove everything before 'nc/uploads/' (including nc/uploads/) in relativePath - relativePath = relativePath.replace(/.*?nc\/uploads\//, ''); + relativePath = relativePath.replace(/^.*?nc[/\\]uploads[/\\]/, ''); return { file, relativePath }; } diff --git a/packages/nocodb/src/plugins/mino/Minio.ts b/packages/nocodb/src/plugins/mino/Minio.ts index ba93a2c620..0efa2c47ab 100644 --- a/packages/nocodb/src/plugins/mino/Minio.ts +++ b/packages/nocodb/src/plugins/mino/Minio.ts @@ -198,8 +198,10 @@ export default class Minio implements IStorageAdapterV2 { return Promise.resolve(undefined); } - public async fileDelete(_path: string): Promise { - throw new Error('Method not implemented.'); + public async fileDelete(path: string): Promise { + return this.minioClient.removeObject(this.input.bucket, path).then(() => { + return true; + }); } public async scanFiles(_globPattern: string): Promise { diff --git a/packages/nocodb/src/plugins/storage/Local.ts b/packages/nocodb/src/plugins/storage/Local.ts index d907178792..ecb27011a5 100644 --- a/packages/nocodb/src/plugins/storage/Local.ts +++ b/packages/nocodb/src/plugins/storage/Local.ts @@ -112,15 +112,18 @@ export default class Local implements IStorageAdapterV2 { } public async scanFiles(globPattern: string) { + // Normalize the path separator + globPattern = globPattern.replace(/\//g, path.sep); + // remove all dots from the glob pattern globPattern = globPattern.replace(/\./g, ''); // remove the leading slash globPattern = globPattern.replace(/^\//, ''); - // make sure pattern starts with nc/uploads/ - if (!globPattern.startsWith('nc/uploads/')) { - globPattern = `nc/uploads/${globPattern}`; + // Ensure the pattern starts with 'nc/uploads/' + if (!globPattern.startsWith(path.join('nc', 'uploads'))) { + globPattern = path.join('nc', 'uploads', globPattern); } const stream = globStream(globPattern, {