@@ -16,15 +16,10 @@ const { Upload } = require('@aws-sdk/lib-storage');
1616const isGCS = process . env . S3_FILES_GCS || 'false'
1717const bucket = process . env . S3_FILES_BUCKET || 'lagoon-files'
1818
19-
20- export const getDownloadLink : ResolverFn = async ( { s3Key } , input , { userActivityLogger } ) => {
21- const command = new GetObjectCommand ( {
22- Bucket : bucket ,
23- Key : s3Key ,
24- } ) ;
19+ async function generateDownloadLink ( s3Key : string , userActivityLogger ?: Function ) {
20+ const command = new GetObjectCommand ( { Bucket : bucket , Key : s3Key } ) ;
2521
2622 if ( typeof userActivityLogger === 'function' ) {
27-
2823 const auditLog : AuditLog = {
2924 resource : {
3025 type : AuditType . FILE ,
@@ -40,12 +35,33 @@ export const getDownloadLink: ResolverFn = async ({ s3Key }, input, { userActivi
4035 }
4136 } ) ;
4237 }
43-
44- return getSignedUrl ( s3Client , command , {
38+ const signedUrl = await getSignedUrl ( s3Client , command , {
4539 expiresIn : s3Config . signedLinkExpiration ,
4640 } ) ;
41+ return signedUrl ;
42+ }
43+
44+ export const getDownloadLink : ResolverFn = async ( { s3Key } , input , { userActivityLogger } ) => {
45+ return generateDownloadLink ( s3Key , userActivityLogger ) ;
4746} ;
4847
48+ export const getDownloadLinkByTaskFileId : ResolverFn = async (
49+ root ,
50+ { taskId, fileId } ,
51+ { sqlClientPool, hasPermission, userActivityLogger }
52+ ) => {
53+ const rowsPerms = await query ( sqlClientPool , taskSql . selectPermsForTask ( taskId ) ) ;
54+
55+ await hasPermission ( 'task' , 'view' , {
56+ project : R . path ( [ '0' , 'pid' ] , rowsPerms )
57+ } ) ;
58+
59+ const rows = await query ( sqlClientPool , Sql . selectTaskFileById ( taskId , fileId ) ) ;
60+
61+ const downloadUrl = await generateDownloadLink ( rows [ 0 ] . s3Key , userActivityLogger )
62+ return downloadUrl ;
63+ }
64+
4965export const getFilesByTaskId : ResolverFn = async (
5066 { id : tid } ,
5167 _args ,
0 commit comments