Skip to content

Commit

Permalink
feat(be): add subfolder s3
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Jul 11, 2023
1 parent c0d942c commit 3ca8387
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/chapter/chapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ export class ChapterService {
);

const uploadFiles = allowedFiles.map((f) => {
const keyName = `manga-${mangaId}/chapter-${chapterNumber}/lang-${f.languageId}/${f.fileName}`;
const s3SubFolder =
this.configService.get<string>('aws.s3SubFolder') || 'images';
const keyName = `${s3SubFolder}/manga-${mangaId}/chapter-${chapterNumber}/lang-${f.languageId}/${f.fileName}`;
return {
name: f.fileName,
key_name: keyName,
Expand Down
8 changes: 6 additions & 2 deletions src/files/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export class FilesService {
if (!thumbnail.type.includes('image')) {
throw Error('thumbnail not valid');
}
const keyName = `manga-${mangaId}/chapter-${chapterNumber}/thumbnail.${thumbnail.fileName
const s3SubFolder =
this.configService.get<string>('aws.s3SubFolder') || 'images';
const keyName = `${s3SubFolder}/manga-${mangaId}/chapter-${chapterNumber}/thumbnail.${thumbnail.fileName
.split('.')
.pop()}`;
const filePath = thumbnail.fullPath;
Expand All @@ -81,7 +83,9 @@ export class FilesService {
// const keyName = `manga-${mangaId}/${f.fieldname}.${f.originalname
// .split('.')
// .pop()}`;
const keyName = `manga-${mangaId}/${f.originalname}`;
const s3SubFolder =
this.configService.get<string>('aws.s3SubFolder') || 'images';
const keyName = `${s3SubFolder}/manga-${mangaId}/${f.originalname}`;

await this.uploadToS3(keyName, f.buffer);
return new URL(keyName, this.configService.get<string>('aws.queryEndpoint'))
Expand Down

0 comments on commit 3ca8387

Please sign in to comment.