2 lines
2.9 KiB
JavaScript
2 lines
2.9 KiB
JavaScript
"use strict";const e=require("../common/vendor.js"),t={development:{baseURL:"http://115.190.167.176:20002",timeout:3e4},production:{baseURL:"https://fhapp.ddn-ai.cloud",timeout:3e4}},o="production",i=t[o].baseURL,r=t[o].timeout;function a(e){return e.startsWith("http://")||e.startsWith("https://")?e:`${i}${e}`}exports.API_BASE=i,exports.API_CONFIG=t,exports.API_ENDPOINTS={revival:{getList:"/api/revival/list",createVideo:"/api/revival/create",deleteVideo:e=>`/api/revival/delete/${e}`,getDetail:e=>`/api/revival/detail/${e}`},volcengine:{generateVideo:"/api/photo-revival/volcengine-video"},voice:{getList:"/api/voice/list",create:"/api/voice/create",delete:e=>`/api/voice/delete/${e}`},conversation:{send:"/api/conversation/send",getAudio:e=>`/api/conversation/audio/${e}`,clearHistory:"/api/conversation/clear-history"},static:{video:e=>`/static/videos/${e}`,image:e=>`/static/images/${e}`},config:{getAppConfig:"/api/config/app"},complaint:{create:"/api/complaints"},works:{plaza:"/api/works/plaza",findBySource:"/api/works/source",publishRevivalVideo:"/api/works/publish/revival-video",unpublish:"/api/works/unpublish"}},exports.API_TIMEOUT=r,exports.request=function(t){const{url:o,method:i="GET",data:n={},header:s={},timeout:d=r}=t,c=e.index.getStorageSync("userId")||"",u=e.index.getStorageSync("token")||"";return new Promise(((t,r)=>{e.index.request({url:a(o),method:i,data:n,header:{"Content-Type":"application/json","X-User-Id":c||"",...u?{Authorization:`Bearer ${u}`}:{},...s},timeout:d,success:o=>{200===o.statusCode?t(o.data):401===o.statusCode?(e.index.removeStorageSync("token"),e.index.removeStorageSync("userId"),e.index.removeStorageSync("userPhone"),e.index.removeStorageSync("userNickname"),e.index.removeStorageSync("username"),e.index.showToast({title:"登录已过期,请重新登录",icon:"none"}),setTimeout((()=>{e.index.reLaunch({url:"/pages/login/login"})}),1500),r(new Error("未授权"))):r(new Error(`请求失败: ${o.statusCode}`))},fail:e=>{r(e)}})}))},exports.uploadFile=function(t){const{url:o,filePath:i,name:n="file",formData:s={},timeout:d=r}=t,c=e.index.getStorageSync("userId")||"",u=e.index.getStorageSync("token")||"";return new Promise(((t,r)=>{e.index.uploadFile({url:a(o),filePath:i,name:n,formData:{...s,userId:c||""},header:{"X-User-Id":c||"",...u?{Authorization:`Bearer ${u}`}:{}},timeout:d,success:o=>{if(200===o.statusCode)try{const e=JSON.parse(o.data);t(e)}catch(i){t(o.data)}else 401===o.statusCode?(e.index.removeStorageSync("token"),e.index.removeStorageSync("userId"),e.index.removeStorageSync("userInfo"),e.index.removeStorageSync("userPhone"),e.index.removeStorageSync("userNickname"),e.index.removeStorageSync("username"),e.index.showToast({title:"登录已过期,请重新登录",icon:"none"}),setTimeout((()=>{e.index.reLaunch({url:"/pages/login/login"})}),1500),r(new Error("Token expired"))):r(new Error(`上传失败: ${o.statusCode}`))},fail:e=>{r(e)}})}))};
|