import { DeviceType } from '@ucap-webmessenger/core'; import { APIRequest, APIResponse, APIEncoder, APIDecoder, ParameterUtil, StatusCode, JsonAnalization } from '@ucap-webmessenger/api'; import { JsonObject } from 'type-fest'; export interface FileTalkSaveRequest extends APIRequest { userSeq: string; deviceType: DeviceType; token: string; file?: File; fileName?: string; thumb?: File; voice?: boolean; voiceTime?: string; roomId?: string; type?: string; } export interface FileTalkSaveResponse extends APIResponse { roomID?: string; 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; } 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', roomId: 'p_room_id', type: 'p_type' }; export const encodeFileTalkSave: APIEncoder = ( req: FileTalkSaveRequest ) => { const extraParams: any = {}; if (!!req.voice) { extraParams.voice = req.voice ? 'Y' : 'N'; } return ParameterUtil.encode(fileTalkSaveEncodeMap, req, extraParams); }; export const decodeFileTalkSave: APIDecoder = ( res: any ) => { try { const json: JsonObject | Error = JsonAnalization.receiveAnalization(res); return { statusCode: json.StatusCode, roomID: json.RoomID, 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; } };