2019-09-18 15:02:21 +09:00
|
|
|
import { Injectable, Inject } from '@angular/core';
|
2019-10-29 18:17:16 +09:00
|
|
|
import {
|
|
|
|
HttpClient,
|
|
|
|
HttpEventType,
|
|
|
|
HttpResponse,
|
|
|
|
HttpRequest,
|
|
|
|
HttpProgressEvent
|
|
|
|
} from '@angular/common/http';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { map } from 'rxjs/operators';
|
|
|
|
|
|
|
|
import { _MODULE_CONFIG } from '../types/token';
|
|
|
|
import { ModuleConfig } from '../types/module-config';
|
|
|
|
import {
|
|
|
|
FileProfileSaveRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
FileProfileSaveResponse,
|
|
|
|
encodeFileProfileSave,
|
|
|
|
decodeFileProfileSave
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/file-profile-save';
|
2019-09-20 11:39:09 +09:00
|
|
|
import {
|
|
|
|
FileTalkDownloadRequest,
|
|
|
|
encodeFileTalkDownload
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/file-talk-download';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
FileTalkSaveRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
FileTalkSaveResponse,
|
|
|
|
encodeFileTalkSave,
|
|
|
|
decodeFileTalkSave
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/file-talk-save';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
FileTalkShareRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
FileTalkShareResponse,
|
|
|
|
encodeFileTalkShare,
|
|
|
|
decodeFileTalkShare
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/file-talk-share';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
MassTalkDownloadRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
MassTalkDownloadResponse,
|
|
|
|
encodeMassTalkDownload,
|
|
|
|
decodeMassTalkDownload
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/mass-talk-download';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
MassTalkSaveRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
MassTalkSaveResponse,
|
|
|
|
encodeMassTalkSave,
|
|
|
|
decodeMassTalkSave
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/mass-talk-save';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
TransMassTalkDownloadRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
TransMassTalkDownloadResponse,
|
|
|
|
encodeTransMassTalkDownload,
|
|
|
|
decodeTransMassTalkDownload
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/trans-mass-talk-download';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
TransMassTalkSaveRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
TransMassTalkSaveResponse,
|
|
|
|
encodeTransMassTalkSave,
|
|
|
|
decodeTransMassTalkSave
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/trans-mass-talk-save';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
TranslationReqRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
TranslationReqResponse,
|
|
|
|
encodeTranslationReq,
|
|
|
|
decodeTranslationReq
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/translation-req';
|
2019-09-18 15:02:21 +09:00
|
|
|
import {
|
|
|
|
TranslationSaveRequest,
|
2019-09-20 11:39:09 +09:00
|
|
|
TranslationSaveResponse,
|
|
|
|
encodeTranslationSave,
|
|
|
|
decodeTranslationSave
|
2019-10-08 15:42:36 +09:00
|
|
|
} from '../apis/translation-save';
|
2019-09-18 15:02:21 +09:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class CommonApiService {
|
|
|
|
constructor(
|
|
|
|
@Inject(_MODULE_CONFIG) private moduleConfig: ModuleConfig,
|
|
|
|
private httpClient: HttpClient
|
|
|
|
) {}
|
|
|
|
|
|
|
|
public fileProfileSave(
|
2019-10-29 16:53:25 +09:00
|
|
|
req: FileProfileSaveRequest,
|
|
|
|
fileProfileSaveUrl?: string
|
2019-09-18 15:02:21 +09:00
|
|
|
): Observable<FileProfileSaveResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
2019-10-29 16:53:25 +09:00
|
|
|
!!fileProfileSaveUrl
|
|
|
|
? fileProfileSaveUrl
|
|
|
|
: this.moduleConfig.urls.fileProfileSave,
|
2019-09-18 15:02:21 +09:00
|
|
|
{},
|
|
|
|
{
|
2019-09-20 11:39:09 +09:00
|
|
|
params: encodeFileProfileSave(req)
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeFileProfileSave(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
2019-10-29 16:53:25 +09:00
|
|
|
public fileTalkDownload(
|
|
|
|
req: FileTalkDownloadRequest,
|
|
|
|
fileTalkDownloadUrl?: string
|
|
|
|
): Observable<Blob> {
|
2019-09-18 15:02:21 +09:00
|
|
|
return this.httpClient.post<Blob>(
|
2019-10-29 16:53:25 +09:00
|
|
|
!!fileTalkDownloadUrl
|
|
|
|
? fileTalkDownloadUrl
|
|
|
|
: this.moduleConfig.urls.fileTalkDownload,
|
2019-09-18 15:02:21 +09:00
|
|
|
{ responseType: 'blob' },
|
|
|
|
{
|
2019-09-20 11:39:09 +09:00
|
|
|
params: encodeFileTalkDownload(req)
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public fileTalkSave(
|
2019-10-29 16:53:25 +09:00
|
|
|
req: FileTalkSaveRequest,
|
|
|
|
fileTalkSaveUrl?: string
|
2019-10-29 18:17:16 +09:00
|
|
|
): Observable<FileTalkSaveResponse | HttpProgressEvent> {
|
|
|
|
const httpReq = new HttpRequest(
|
|
|
|
'POST',
|
|
|
|
!!fileTalkSaveUrl ? fileTalkSaveUrl : this.moduleConfig.urls.fileTalkSave,
|
|
|
|
encodeFileTalkSave(req),
|
|
|
|
{ reportProgress: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
return this.httpClient.request(httpReq).pipe(
|
|
|
|
map(event => {
|
|
|
|
if (event instanceof HttpResponse) {
|
|
|
|
return decodeFileTalkSave(event);
|
|
|
|
} else if (HttpEventType.UploadProgress === event.type) {
|
|
|
|
return event;
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
2019-10-29 18:17:16 +09:00
|
|
|
})
|
|
|
|
);
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
2019-11-01 13:43:03 +09:00
|
|
|
public acceptableExtensionForFileTalk(extension: string): boolean {
|
|
|
|
return -1 !== this.moduleConfig.acceptableFileExtensions.indexOf(extension);
|
|
|
|
}
|
|
|
|
|
2019-09-18 15:02:21 +09:00
|
|
|
public fileTalkShare(
|
|
|
|
req: FileTalkShareRequest
|
|
|
|
): Observable<FileTalkShareResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
|
|
|
this.moduleConfig.urls.fileTalkShare,
|
|
|
|
{},
|
|
|
|
{
|
2019-09-20 11:39:09 +09:00
|
|
|
params: encodeFileTalkShare(req)
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeFileTalkShare(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public massTalkDownload(
|
|
|
|
req: MassTalkDownloadRequest
|
|
|
|
): Observable<MassTalkDownloadResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
|
|
|
this.moduleConfig.urls.massTalkDownload,
|
|
|
|
{},
|
|
|
|
{
|
2019-10-28 18:03:27 +09:00
|
|
|
params: encodeMassTalkDownload(req),
|
|
|
|
responseType: 'text' as 'json'
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeMassTalkDownload(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public massTalkSave(
|
|
|
|
req: MassTalkSaveRequest
|
|
|
|
): Observable<MassTalkSaveResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
|
|
|
this.moduleConfig.urls.massTalkSave,
|
|
|
|
{},
|
|
|
|
{
|
2019-10-28 18:03:27 +09:00
|
|
|
params: encodeMassTalkSave(req),
|
|
|
|
responseType: 'text' as 'json'
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeMassTalkSave(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public transMassTalkDownload(
|
|
|
|
req: TransMassTalkDownloadRequest
|
|
|
|
): Observable<TransMassTalkDownloadResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
|
|
|
this.moduleConfig.urls.transMassTalkDownload,
|
|
|
|
{},
|
|
|
|
{
|
2019-09-20 11:39:09 +09:00
|
|
|
params: encodeTransMassTalkDownload(req)
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeTransMassTalkDownload(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public transMassTalkSave(
|
|
|
|
req: TransMassTalkSaveRequest
|
|
|
|
): Observable<TransMassTalkSaveResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
|
|
|
this.moduleConfig.urls.transMassTalkSave,
|
|
|
|
{},
|
|
|
|
{
|
2019-09-20 11:39:09 +09:00
|
|
|
params: encodeTransMassTalkSave(req)
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeTransMassTalkSave(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public translationReq(
|
|
|
|
req: TranslationReqRequest
|
|
|
|
): Observable<TranslationReqResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
|
|
|
this.moduleConfig.urls.translationReq,
|
|
|
|
{},
|
|
|
|
{
|
2019-09-20 11:39:09 +09:00
|
|
|
params: encodeTranslationReq(req)
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeTranslationReq(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public translationSave(
|
|
|
|
req: TranslationSaveRequest
|
|
|
|
): Observable<TranslationSaveResponse> {
|
|
|
|
return this.httpClient
|
|
|
|
.post<any>(
|
|
|
|
this.moduleConfig.urls.translationSave,
|
|
|
|
{},
|
|
|
|
{
|
2019-09-20 11:39:09 +09:00
|
|
|
params: encodeTranslationSave(req)
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
)
|
2019-09-20 11:39:09 +09:00
|
|
|
.pipe(map(res => decodeTranslationSave(res)));
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|
|
|
|
}
|