Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(application-system-api): Copy object on upload fix #16883

Merged
merged 17 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libs/file-storage/src/lib/file-storage.configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from 'zod'

const FileStorageModule = z.object({
uploadBucket: z.string(),
secondUploadBucket: z.string(),
})

export const FileStorageConfig = defineConfig({
Expand All @@ -13,5 +14,9 @@ export const FileStorageConfig = defineConfig({
'FILE_STORAGE_UPLOAD_BUCKET',
'island-is-dev-upload-api',
),
secondUploadBucket: env.optional(
'APPLICATION_ATTACHMENT_BUCKET',
'bruh'
),
HjorturJ marked this conversation as resolved.
Show resolved Hide resolved
}),
})
6 changes: 5 additions & 1 deletion libs/file-storage/src/lib/file-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kebabCase from 'lodash/kebabCase'
import { ConfigType } from '@nestjs/config'
import { FileStorageConfig } from './file-storage.configuration'
import { PresignedPost } from '@aws-sdk/s3-presigned-post'
import { LOGGER_PROVIDER, type Logger } from '@island.is/logging'

const PRESIGNED_POST_EXPIRES = 1000 * 60 * 5
const SIGNED_GET_EXPIRES = 10 * 60
Expand All @@ -15,6 +16,7 @@ export class FileStorageService {
@Inject(FileStorageConfig.KEY)
private config: ConfigType<typeof FileStorageConfig>,
private readonly s3Service: S3Service,
@Inject(LOGGER_PROVIDER) protected readonly logger: Logger,
) {}

generatePresignedPost(filename: string): Promise<PresignedPost> {
Expand Down Expand Up @@ -66,14 +68,16 @@ export class FileStorageService {
throw new Error('Upload bucket not configured.')
}
const region = await this.s3Service.getClientRegion()
this.logger.error(`copySource: ${this.config.secondUploadBucket}/${sourceKey}. Returned value: https://${destinationBucket}.s3-${region}.amazonaws.com/${destinationKey}`)
HjorturJ marked this conversation as resolved.
Show resolved Hide resolved

await this.s3Service.copyObject(
{
bucket: destinationBucket,
key: destinationKey,
},
`${this.config.uploadBucket}/${sourceKey}`,
`${this.config.secondUploadBucket}/${sourceKey}`,
)

HjorturJ marked this conversation as resolved.
Show resolved Hide resolved
return `https://${destinationBucket}.s3-${region}.amazonaws.com/${destinationKey}`
}
}
Loading