This commit is contained in:
Luk
2025-09-24 11:46:52 +08:00
parent 0c05bfd464
commit f9ffbb4989
2 changed files with 14 additions and 8 deletions

View File

@@ -146,7 +146,7 @@ module.exports = {
}
},
make_server_url (route, envar = globalThis.wo?.envar || {}) {
make_server_url (route, { envar = globalThis.wo?.envar, fullUrl = false } = {}) {
if (typeof route === 'string') route = route.replace('\\', '/')
else if (route?.apiWho && route?.apiTodo) {
const { apiVersion = 'api', apiWho, apiTodo } = route
@@ -163,22 +163,26 @@ module.exports = {
if (/^\/static\//.test(route)) {
return route
}
route = route.replace(/^\//, '')
// 对 route='abc.com' 这种,应当有 fullUrl===true就直接使用而不是组装成 pexserver.tic.cc/abc.com
// 纯数字和字母的cid
if (/^[\da-zA-Z]+$/.test(route) && envar.ipfsLens) {
return `${envar.ipfsLens.replace(/\/$/, '')}/${route.replace(/^\//, '')}`
if (/^[0-9a-zA-Z]+$/.test(route) && envar?.ipfsLens) {
return `${envar.ipfsLens.replace(/\/$/, '')}/${route}`
}
//// base url / 后台服务器url 需要组装。包括了 route === '_filestore/xxx' 的情况
route = route.replace(/^\//, '')
// 已有现成后端服务域名
if (envar.servUrl) {
if (fullUrl) {
return `http://${route}`
} else if (envar?.servUrl) {
return `${envar.servUrl.replace(/\/$/, '')}/${route}`
} else {
} else if (envar?.servHostname) {
// 需要组装后端服务域名
const hostname = envar.servHostname /*|| globalThis.window?.location?.hostname*/ || 'localhost'
const port = envar.servPort /*|| globalThis.window?.location?.port*/ || ''
const protocol = hostname === 'localhost' ? 'http' : envar.servProtocol || (process.env.NODE_ENV === 'production' ? 'https' : 'http')
return `${protocol}://${hostname}${port ? ':' : ''}${port}/${route}`
}
return route
},
make_bgurl (image) {