This commit is contained in:
陆柯 2023-10-13 18:38:10 +08:00
parent 6d54d1f507
commit 3da2705fe2

View File

@ -132,15 +132,15 @@ export default {
if (/^\/static\//.test(route)) {
return route
}
// cid
// 纯字母的cid
if (/^[\da-zA-Z]+$/.test(route)) {
return (envar.ipfsGateway || '') + route
return `${envar.ipfsGateway.replace(/\/$/, '')}/${route.replace(/^\//, '')}`
}
// 需要组装url
//// base url / 后台服务器url 需要组装。包括了 route === '_filestore/xxx' 的情况
route = route.replace(/^\//, '')
// 已有现成后端服务域名
if (envar.servUrl) {
return `${envar.servUrl}/${route}`
return `${envar.servUrl.replace(/\/$/, '')}/${route}`
}
// 需要组装后端服务域名
const hostname = envar.servHostname /*|| globalThis.window?.location?.hostname*/ || 'localhost'
@ -294,7 +294,7 @@ export default {
uni.showLoading()
let [errorUpload, { data, statusCode } = {}] = await uni.uploadFile({ url: this.make_server_url(url), filePath, name, header, formData })
// 后台 Multer 处理 req.file = { destination, filename, originalname, path, mimetype, size }, 其中 path 包括了 destination 和 filename 的文件相对路径。
// url 所在方法进一步处理后,通过 uni.uploadFile 存在 data 里返回结果
// url 指向的后台方法进一步处理后,通过 uni.uploadFile 存在 data 里返回结果: { ...file, cid?, ipfsUrl?, baseUrl? }
uni.hideLoading()
if (typeof data === 'string') {
@ -307,7 +307,8 @@ export default {
}
if (data?._state === 'SUCCESS' && data?.path) {
return { _state: 'SUCCESS', fileUrl: this.make_server_url(data.path), filePath: data.path, ...data }
// 后台送来的 baseUrl 在开发环境下,不一定符合前端实际,因为后台只知道预设的 servUrl而前端会再根据 location.origin 来调整,所以再设置一个 fileUrl。
return { _state: 'SUCCESS', fileUrl: this.make_server_url(data.path), ...data } // { path, destination, filename, fileUrl, cid?, ipfsUrl?, baseUrl?, ...file } 注意data.path 不包含起头的 '/'
} else {
return { _state: 'CLIENT_FAIL_UPLOAD_FILE', error: errorUpload }
}
@ -400,7 +401,6 @@ export default {
} = {}) {
if (/^UNICLOUD/.test(baseType)) {
return await this.pickupFile2Cloud({ mediaType, count, sizeType, sourceType, maxDuration })
return resultCloud
} else if (baseType === 'SERVER') {
return await this.pickupFile2Server({ mediaType, count, sizeType, sourceType, maxDuration, url, header, formData, name })
} else {