Merged PR 196: 音声ファイルアップロード時のアップロード先URLにユーザーIDを追加する
## 概要 [Task2101: 音声ファイルアップロード時のアップロード先URLにユーザーIDを追加する](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2101) - 音声ファイルアップロード先URLにユーザーIDを含めるのを、ODMSCloud側で実施するよう修正しました - URLの構築はURLオブジェクトを利用するのが安全であるため、リファクタしました。 ## レビューポイント - 修正方針は妥当か ## 動作確認状況 - ローカルで確認 - 返却されたURLをもとに、ODMSCloudツールから音声ファイルアップロードできるところまで確認しました
This commit is contained in:
parent
e4bc4776b0
commit
f47a686bac
@ -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;
|
||||
|
||||
@ -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<string> {
|
||||
async publishUploadSas(
|
||||
accountId: number,
|
||||
userId: number,
|
||||
country: string,
|
||||
): Promise<string> {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user