100 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-09-18 15:02:21 +09:00
import { DeviceType } from '@ucap-webmessenger/core';
2019-09-20 11:39:09 +09:00
import {
APIRequest,
APIResponse,
APIEncoder,
APIDecoder,
2019-10-29 18:16:51 +09:00
ParameterUtil,
StatusCode,
2019-11-05 13:46:17 +09:00
JsonAnalization,
APIFormDataEncoder
2019-09-20 11:39:09 +09:00
} from '@ucap-webmessenger/api';
2019-11-05 13:46:17 +09:00
import { FileUploadItem } from '../models/file-upload-item';
2019-09-18 15:02:21 +09:00
export interface FileTalkSaveRequest extends APIRequest {
2019-11-05 13:46:17 +09:00
userSeq: number;
2019-09-18 15:02:21 +09:00
deviceType: DeviceType;
token: string;
2019-11-05 13:46:17 +09:00
file: File;
2019-09-18 15:02:21 +09:00
fileName?: string;
2019-11-05 13:46:17 +09:00
fileUploadItem: FileUploadItem;
2019-09-18 15:02:21 +09:00
thumb?: File;
voice?: boolean;
voiceTime?: string;
2019-11-05 13:46:17 +09:00
roomSeq?: string;
2019-09-18 15:02:21 +09:00
type?: string;
}
export interface FileTalkSaveResponse extends APIResponse {
2019-11-05 13:46:17 +09:00
roomSeq?: string;
2019-10-29 18:16:51 +09:00
fileName?: string;
fileExt?: string;
fileType?: string;
thumbnailUrl?: string;
attachmentSeq?: string;
attachmentSize?: string;
attachmentRegDate?: string;
imageWidth?: string;
imageHeight?: string;
companyCode?: string;
voiceTime?: string;
synapKey?: string;
returnJson?: any;
2019-09-18 15:02:21 +09:00
}
2019-09-20 11:39:09 +09:00
2019-10-29 18:16:51 +09:00
const fileTalkSaveEncodeMap = {
userSeq: 'p_user_seq',
deviceType: 'p_device_type',
token: 'p_token',
file: 'file',
fileName: 'p_file_name',
thumb: 'thumb',
voice: 'p_voice',
voiceTime: 'p_voice_time',
2019-11-05 13:46:17 +09:00
roomSeq: 'p_room_id',
2019-10-29 18:16:51 +09:00
type: 'p_type'
};
2019-09-20 11:39:09 +09:00
2019-11-05 13:46:17 +09:00
export const encodeFileTalkSave: APIFormDataEncoder<FileTalkSaveRequest> = (
2019-09-20 11:39:09 +09:00
req: FileTalkSaveRequest
) => {
2019-10-29 18:16:51 +09:00
const extraParams: any = {};
2019-11-05 13:46:17 +09:00
extraParams.userSeq = String(req.userSeq);
2019-10-29 18:16:51 +09:00
if (!!req.voice) {
extraParams.voice = req.voice ? 'Y' : 'N';
}
2019-11-05 13:46:17 +09:00
return ParameterUtil.encodeFormData(fileTalkSaveEncodeMap, req, extraParams);
2019-09-20 11:39:09 +09:00
};
export const decodeFileTalkSave: APIDecoder<FileTalkSaveResponse> = (
res: any
) => {
2019-10-29 18:16:51 +09:00
try {
2019-11-06 13:48:06 +09:00
const json = JsonAnalization.receiveAnalization(res);
2019-10-29 18:16:51 +09:00
return {
statusCode: json.StatusCode,
2019-11-05 13:46:17 +09:00
roomSeq: json.RoomID,
2019-10-29 18:16:51 +09:00
fileName: json.FileName,
fileExt: json.FileExt,
fileType: json.FileType,
thumbnailUrl: json.ThumbURL,
attachmentSeq: json.AttSEQ,
attachmentSize: json.AttSize,
attachmentRegDate: json.AttRegDate,
imageWidth: json.ImageWidth,
imageHeight: json.ImageHeight,
companyCode: json.CompanyCode,
voiceTime: json.VoiceTime,
synapKey: json.SynapKey,
returnJson: res
} as FileTalkSaveResponse;
} catch (e) {
return {
statusCode: StatusCode.Fail,
errorMessage: e
} as FileTalkSaveResponse;
}
2019-09-20 11:39:09 +09:00
};