import http from '../scan/httpUtil'

const baseUrl = '/image-service'

//分片上传文件接口

/**
 * info: 申请分片上传接口(获取上传UploadId)
 * @param {systemId:string} param 系统的名称
 * @param {secret:string} param 系统的密码
 * @param {key:string} param  成功的回上传的文件名(可以包含文件路径)
 * @param {overwrite:boolean} param 表示是否覆盖已有的文件(如果存在) 注：overwrite有一定风险, 只在注册分片时校验, 合并时候如果key被占用, 会覆盖掉之前文件
 * 
 */
export function getUploadId(param, success) {
  let url = ` ${baseUrl}/common/register_multipart_upload?systemId=${param.systemId}&secret=${param.secret}&key=${param.key}&overwrite=${param.overwrite}`
  http.postJson(url, {}, success)
}

/**
 * info: 合并分片的接口
 * @param {systemId:string} param 系统的名称
 * @param {secret:string} param 系统的密码
 * @param {uploadId:string} param  需要合并的上传文件的uploadId
 * 
 */
export function mergeMultipart(param, success) {
  let url = ` ${baseUrl}/common/merge_multipart?systemId=${param.systemId}&secret=${param.secret}&uploadId=${param.uploadId}`
  http.postJson(url, {}, success)
}