Skip to content

Commit

Permalink
objectStorageを使わない場合があることを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyatea committed Dec 17, 2024
1 parent f5cf2ea commit 1531b6c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ export class DriveService {
}

const baseUrl = this.meta.objectStorageBaseUrl
?? `${ this.meta.objectStorageUseSSL ? 'https' : 'http' }://${ this.meta.objectStorageEndpoint }${ this.meta.objectStoragePort ? `:${this.meta.objectStoragePort}` : '' }/${ this.meta.objectStorageBucket }`;
? `${ this.meta.objectStorageUseSSL ? 'https' : 'http' }://${ this.meta.objectStorageEndpoint }${ this.meta.objectStoragePort ? `:${this.meta.objectStoragePort}` : '' }/${ this.meta.objectStorageBucket }` : this.config.objectStorage?.objectStorageBaseUrl
? `${ this.config.objectStorage.objectStorageUseSSL ? 'https' : 'http' }://${ this.config.objectStorage.objectStorageEndpoint }${ this.config.objectStorage.objectStoragePort ? `:${this.config.objectStorage.objectStoragePort}` : '' }/${ this.config.objectStorage.objectStorageBucket }` : '';

// for original
const key = `${this.meta.objectStoragePrefix}/${randomUUID()}${ext}`;
const key = `${this.meta.objectStoragePrefix ? this.meta.objectStoragePrefix : this.config.objectStorage?.objectStoragePrefix}/${randomUUID()}${ext}`;
const url = `${ baseUrl }/${ key }`;

// for alts
Expand All @@ -190,15 +191,15 @@ export class DriveService {
];

if (alts.webpublic) {
webpublicKey = `${this.meta.objectStoragePrefix}/webpublic-${randomUUID()}.${alts.webpublic.ext}`;
webpublicKey = `${this.meta.objectStoragePrefix ? this.meta.objectStoragePrefix : this.config.objectStorage?.objectStoragePrefix}/webpublic-${randomUUID()}.${alts.webpublic.ext}`;
webpublicUrl = `${ baseUrl }/${ webpublicKey }`;

this.registerLogger.info(`uploading webpublic: ${webpublicKey}`);
uploads.push(this.upload(webpublicKey, alts.webpublic.data, alts.webpublic.type, alts.webpublic.ext, name));
}

if (alts.thumbnail) {
thumbnailKey = `${this.meta.objectStoragePrefix}/thumbnail-${randomUUID()}.${alts.thumbnail.ext}`;
thumbnailKey = `${this.meta.objectStoragePrefix ? this.meta.objectStoragePrefix : this.config.objectStorage?.objectStoragePrefix}/thumbnail-${randomUUID()}.${alts.thumbnail.ext}`;
thumbnailUrl = `${ baseUrl }/${ thumbnailKey }`;

this.registerLogger.info(`uploading thumbnail: ${thumbnailKey}`);
Expand Down Expand Up @@ -376,7 +377,7 @@ export class DriveService {
if (!FILE_TYPE_BROWSERSAFE.includes(type)) type = 'application/octet-stream';

const params = {
Bucket: this.meta.objectStorageBucket,
Bucket: this.meta.objectStorageBucket ? this.meta.objectStorageBucket : this.config.objectStorage?.objectStorageBucket,
Key: key,
Body: stream,
ContentType: type,
Expand All @@ -389,7 +390,7 @@ export class DriveService {
// 許可されているファイル形式でしか拡張子をつけない
ext ? correctFilename(filename, ext) : filename,
);
if (this.meta.objectStorageSetPublicRead) params.ACL = 'public-read';
if (this.meta.objectStorageSetPublicRead || this.config.objectStorage?.objectStorageSetPublicRead) params.ACL = 'public-read';

await this.s3Service.upload(this.meta, params)
.then(
Expand Down Expand Up @@ -818,7 +819,7 @@ export class DriveService {
public async deleteObjectStorageFile(key: string) {
try {
const param = {
Bucket: this.meta.objectStorageBucket,
Bucket: this.meta.objectStorageBucket ? this.meta.objectStorageBucket : this.config.objectStorage?.objectStorageBucket,
Key: key,
} as DeleteObjectCommandInput;

Expand Down

0 comments on commit 1531b6c

Please sign in to comment.