Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

handle secure attachment part

Fendy Heryantoa91a38dfa1c2
diff --git a/packages/nocodb/src/helpers/attachmentHelpers.ts b/packages/nocodb/src/helpers/attachmentHelpers.ts
index e425316824..dd10b83949 100644
--- a/packages/nocodb/src/helpers/attachmentHelpers.ts
+++ b/packages/nocodb/src/helpers/attachmentHelpers.ts
@@ -4,8 +4,11 @@ import mime from 'mime/lite';
import slash from 'slash';
import { PublicAttachmentScope } from 'nocodb-sdk';
import { nanoid } from 'nanoid';
+import moment from 'dayjs';
+import hash from 'object-hash';
import type { NcContext } from 'nocodb-sdk';
import type { Column } from '~/models';
+import { isSecureAttachmentEnabled } from '~/utils';
import { getToolDir } from '~/utils/nc-config';
import { NcError } from '~/helpers/catchError';
@@ -132,9 +135,10 @@ export const constructFilePath = (
scope?: string;
},
) => {
- const filePath = path.join(
+ let filePath = path.join(
...[
- context.workspace_id,
+ // somehow, even in production gui upload doesn't use workspace id
+ 'noco', // context.workspace_id,
context.base_id,
param.modelId,
param.columnId,
@@ -142,6 +146,12 @@ export const constructFilePath = (
].filter((k) => k),
);
+ if (param.scope) {
+ filePath = hash(context.user.id);
+ } else if (isSecureAttachmentEnabled) {
+ filePath = `${moment().format('YYYY/MM/DD')}/${hash(context.user.id)}`;
+ }
+
const destPath = path.join(...['nc', param.scope ?? 'uploads', filePath]);
return {
diff --git a/packages/nocodb/src/utils/envs.ts b/packages/nocodb/src/utils/envs.ts
index 5056a8adf1..1fb3abbaf7 100644
--- a/packages/nocodb/src/utils/envs.ts
+++ b/packages/nocodb/src/utils/envs.ts
@@ -1,2 +1,4 @@
export const isWorker = process.env.NC_WORKER_CONTAINER === 'true';
export const isMuxEnabled = false;
+export const isSecureAttachmentEnabled =
+ process.env.NC_SECURE_ATTACHMENTS === 'true';