Browse Source

fix: URI decode issue

nc-feat/attachment-clean-up
mertmit 4 months ago
parent
commit
78e57629b9
  1. 4
      packages/nocodb/src/models/PresignedUrl.ts
  2. 2
      packages/nocodb/src/modules/jobs/jobs/attachment-clean-up/attachment-clean-up.ts
  3. 7
      packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts
  4. 15
      packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts

4
packages/nocodb/src/models/PresignedUrl.ts

@ -101,7 +101,9 @@ export default class PresignedUrl {
const isUrl = /^https?:\/\//i.test(param.pathOrUrl);
let path = (
isUrl ? decodeURI(new URL(param.pathOrUrl).pathname) : param.pathOrUrl
isUrl
? decodeURI(new URL(encodeURI(param.pathOrUrl)).pathname)
: param.pathOrUrl
).replace(/^\/+/, '');
const {

2
packages/nocodb/src/modules/jobs/jobs/attachment-clean-up/attachment-clean-up.ts

@ -42,7 +42,7 @@ export class AttachmentCleanUpProcessor {
if (storageAdapterName === 'Local') {
relativePath = file.file_url.replace(/^\/?nc\/uploads\//, '');
} else {
relativePath = new URL(file.file_url).pathname.replace(
relativePath = new URL(encodeURI(file.file_url)).pathname.replace(
/^\/?nc\/uploads\//,
'',
);

7
packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts

@ -131,10 +131,9 @@ export class ThumbnailGeneratorProcessor {
if (attachment.path) {
relativePath = attachment.path.replace(/^download\//, '');
} else if (attachment.url) {
relativePath = decodeURI(new URL(attachment.url).pathname).replace(
/^\/+/,
'',
);
relativePath = decodeURI(
new URL(encodeURI(attachment.url)).pathname,
).replace(/^\/+/, '');
}
const file = await storageAdapter.fileRead(relativePath);

15
packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts

@ -329,12 +329,7 @@ export class AttachmentMigration {
if ('path' in attachment || 'url' in attachment) {
const filePath = `nc/uploads/${
attachment.path?.replace(/^download\//, '') ||
decodeURI(
`${new URL(attachment.url).pathname.replace(
/.*?nc\/uploads\//,
'',
)}`,
)
this.normalizeUrl(attachment.url)
}`;
const isReferenced = await ncMeta
@ -347,9 +342,8 @@ export class AttachmentMigration {
this.log(
`file not found in file references table ${
attachment.path || attachment.url
}`,
}, ${filePath}`,
);
continue;
} else if (isReferenced.referenced === false) {
const fileNameWithExt = path.basename(filePath);
@ -486,4 +480,9 @@ export class AttachmentMigration {
return true;
}
normalizeUrl(url: string) {
const newUrl = new URL(encodeURI(url));
return decodeURI(newUrl.pathname.replace(/.*?nc\/uploads\//, ''));
}
}

Loading…
Cancel
Save