Browse Source

fix: use original url if signed url not available (#9062)

* fix: use original url if signed url not available

Signed-off-by: mertmit <mertmit99@gmail.com>

* fix: check url more precisely

Signed-off-by: mertmit <mertmit99@gmail.com>

---------

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/9066/head
Mert E. 4 months ago committed by GitHub
parent
commit
b7dd12b0ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 7
      packages/nocodb/src/models/FormView.ts
  3. 14
      packages/nocodb/src/models/PresignedUrl.ts
  4. 4
      packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts
  5. 4
      packages/nocodb/src/services/attachments.service.ts

10
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -7233,7 +7233,7 @@ class BaseModelSqlv2 {
if (lookedUpAttachment?.path) {
promises.push(
PresignedUrl.getSignedUrl({
path: lookedUpAttachment.path.replace(
pathOrUrl: lookedUpAttachment.path.replace(
/^download\//,
'',
),
@ -7242,9 +7242,7 @@ class BaseModelSqlv2 {
} else if (lookedUpAttachment?.url) {
promises.push(
PresignedUrl.getSignedUrl({
path: decodeURI(
new URL(lookedUpAttachment.url).pathname,
),
pathOrUrl: lookedUpAttachment.url,
}).then((r) => (lookedUpAttachment.signedUrl = r)),
);
}
@ -7253,13 +7251,13 @@ class BaseModelSqlv2 {
if (attachment?.path) {
promises.push(
PresignedUrl.getSignedUrl({
path: attachment.path.replace(/^download\//, ''),
pathOrUrl: attachment.path.replace(/^download\//, ''),
}).then((r) => (attachment.signedPath = r)),
);
} else if (attachment?.url) {
promises.push(
PresignedUrl.getSignedUrl({
path: decodeURI(new URL(attachment.url).pathname),
pathOrUrl: attachment.url,
}).then((r) => (attachment.signedUrl = r)),
);
}

7
packages/nocodb/src/models/FormView.ts

@ -242,7 +242,10 @@ export default class FormView implements FormViewType {
promises.push(
PresignedUrl.getSignedUrl(
{
path: formAttachments[key].path.replace(/^download\//, ''),
pathOrUrl: formAttachments[key].path.replace(
/^download\//,
'',
),
},
ncMeta,
).then((r) => (formAttachments[key].signedPath = r)),
@ -250,7 +253,7 @@ export default class FormView implements FormViewType {
} else if (formAttachments[key]?.url) {
promises.push(
PresignedUrl.getSignedUrl(
{ path: decodeURI(new URL(formAttachments[key].url).pathname) },
{ pathOrUrl: formAttachments[key].url },
ncMeta,
).then((r) => (formAttachments[key].signedUrl = r)),
);

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

@ -88,13 +88,17 @@ export default class PresignedUrl {
public static async getSignedUrl(
param: {
path: string;
pathOrUrl: string;
expireSeconds?: number;
filename?: string;
},
ncMeta = Noco.ncMeta,
) {
let path = param.path.replace(/^\/+/, '');
const isUrl = /^https?:\/\//i.test(param.pathOrUrl);
let path = isUrl
? decodeURI(new URL(param.pathOrUrl).pathname)
: param.pathOrUrl.replace(/^\/+/, '');
const { expireSeconds = DEFAULT_EXPIRE_SECONDS, filename } = param;
@ -140,8 +144,10 @@ export default class PresignedUrl {
expiresInSeconds,
});
} else {
// if not present, create a new url
tempUrl = `dltemp/${nanoid(16)}/${expireAt.getTime()}/${path}`;
// if not present, use url or generate url for local storage
tempUrl = isUrl
? param.pathOrUrl
: `dltemp/${nanoid(16)}/${expireAt.getTime()}/${path}`;
// if filename is present, add it to the destination
if (filename) {

4
packages/nocodb/src/modules/jobs/jobs/data-export/data-export.processor.ts

@ -93,13 +93,13 @@ export class DataExportProcessor {
// if url is not defined, it is local attachment
if (!url) {
url = await PresignedUrl.getSignedUrl({
path: path.join(destPath.replace('nc/uploads/', '')),
pathOrUrl: path.join(destPath.replace('nc/uploads/', '')),
filename: `${model.title} (${getViewTitle(view)}).csv`,
expireSeconds: 3 * 60 * 60, // 3 hours
});
} else {
url = await PresignedUrl.getSignedUrl({
path: decodeURI(new URL(url).pathname),
pathOrUrl: url,
filename: `${model.title} (${getViewTitle(view)}).csv`,
expireSeconds: 3 * 60 * 60, // 3 hours
});

4
packages/nocodb/src/services/attachments.service.ts

@ -82,11 +82,11 @@ export class AttachmentsService {
);
attachment.signedPath = await PresignedUrl.getSignedUrl({
path: attachment.path.replace(/^download\//, ''),
pathOrUrl: attachment.path.replace(/^download\//, ''),
});
} else {
attachment.signedUrl = await PresignedUrl.getSignedUrl({
path: decodeURI(new URL(attachment.url).pathname),
pathOrUrl: attachment.url,
});
}

Loading…
Cancel
Save