diff --git a/dictation_server/src/features/files/files.service.ts b/dictation_server/src/features/files/files.service.ts index 7cc1de7..6ddd5b3 100644 --- a/dictation_server/src/features/files/files.service.ts +++ b/dictation_server/src/features/files/files.service.ts @@ -151,14 +151,14 @@ export class FilesService { //DBから国情報とアカウントIDを取得する let accountId: number; let country: string; + let userId: number; try { const user = await this.usersRepository.findUserByExternalId( token.userId, ); - if (user.account) { - accountId = user.account.id; - country = user.account.country; - } + accountId = user.account.id; + userId = user.id; + country = user.account.country; } catch (e) { this.logger.error(`error=${e}`); throw new HttpException( @@ -173,7 +173,7 @@ export class FilesService { accountId, country, ); - //TODO コンテナが無ければ作成 + //TODO コンテナが無ければ作成しているが、アカウント登録時に作成するので本処理は削除予定。 if (!isContainerExist) { await this.blobStorageService.createContainer(accountId, country); } @@ -189,6 +189,7 @@ export class FilesService { // SASトークン発行 const url = await this.blobStorageService.publishUploadSas( accountId, + userId, country, ); return url; diff --git a/dictation_server/src/gateways/blobstorage/blobstorage.service.ts b/dictation_server/src/gateways/blobstorage/blobstorage.service.ts index 32081f5..824ce13 100644 --- a/dictation_server/src/gateways/blobstorage/blobstorage.service.ts +++ b/dictation_server/src/gateways/blobstorage/blobstorage.service.ts @@ -84,12 +84,17 @@ export class BlobstorageService { } /** - * Publishs upload sas + * SASトークン付きのBlobStorageアップロードURLを生成し返却します * @param accountId + * @param userId * @param country * @returns upload sas */ - async publishUploadSas(accountId: number, country: string): Promise { + async publishUploadSas( + accountId: number, + userId: number, + country: string, + ): Promise { this.logger.log(`[IN] ${this.publishUploadSas.name}`); let containerClient: ContainerClient; let sharedKeyCredential: StorageSharedKeyCredential; @@ -126,7 +131,10 @@ export class BlobstorageService { sharedKeyCredential, ); - return `${containerClient.url}?${sasToken}`; + const url = new URL(containerClient.url); + url.pathname += `/${userId}`; + url.search = `${sasToken}`; + return url.toString(); } /**