Signed file follow up (#12347)

This commit is contained in:
martmull
2025-05-28 13:02:27 +02:00
committed by GitHub
parent d4fac6793a
commit 69831b17ff
11 changed files with 58 additions and 119 deletions

View File

@ -4,10 +4,13 @@ import { basename, dirname, extname } from 'path';
import { Stream } from 'stream';
import { v4 as uuidV4 } from 'uuid';
import { buildSignedPath } from 'twenty-shared/utils';
import { isNonEmptyString } from '@sniptt/guards';
import { FileStorageService } from 'src/engine/core-modules/file-storage/file-storage.service';
import { JwtWrapperService } from 'src/engine/core-modules/jwt/services/jwt-wrapper.service';
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
import { extractFilenameFromPath } from 'src/engine/core-modules/file/utils/extract-file-id-from-path.utils';
export type FilePayloadToEncode = {
workspaceId: string;
@ -35,6 +38,20 @@ export class FileService {
});
}
signFileUrl({ url, workspaceId }: { url: string; workspaceId: string }) {
if (!isNonEmptyString(url)) {
return url;
}
return buildSignedPath({
path: url,
token: this.encodeFileToken({
filename: extractFilenameFromPath(url),
workspaceId,
}),
});
}
encodeFileToken(payloadToEncode: FilePayloadToEncode) {
const fileTokenExpiresIn = this.twentyConfigService.get(
'FILE_TOKEN_EXPIRES_IN',