Browse Source

fix: handle regex for windows

pull/9328/head
DarkPhoenix2704 3 months ago
parent
commit
5f8d6f07c4
  1. 4
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 2
      packages/nocodb/src/models/PresignedUrl.ts
  3. 6
      packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts
  4. 6
      packages/nocodb/src/plugins/mino/Minio.ts
  5. 9
      packages/nocodb/src/plugins/storage/Local.ts

4
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,
'',
)}`;

2
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 } : {}),

6
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 };
}

6
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<any> {
throw new Error('Method not implemented.');
public async fileDelete(path: string): Promise<any> {
return this.minioClient.removeObject(this.input.bucket, path).then(() => {
return true;
});
}
public async scanFiles(_globPattern: string): Promise<Readable> {

9
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, {

Loading…
Cancel
Save