52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { attachmentFullUrl } from './attachment.js'
|
|
|
|
const BASE_REL = '/minio/zkxw'
|
|
const BASE_ABS = 'https://xwyd.zkxw.cn/minio/zkxw'
|
|
|
|
{
|
|
assert.equal(attachmentFullUrl(''), '')
|
|
assert.equal(
|
|
attachmentFullUrl('https://cdn.example.com/a.png', BASE_REL),
|
|
'https://cdn.example.com/a.png'
|
|
)
|
|
}
|
|
|
|
// 已带同域反代前缀:不得再拼 → 避免 /minio/zkxw/minio/zkxw/...
|
|
{
|
|
const key = '/minio/zkxw/oa-approval/202608/10/907efa94baf245dcb47da30880bb0be5.png'
|
|
assert.equal(attachmentFullUrl(key, BASE_REL), key)
|
|
assert.equal(
|
|
attachmentFullUrl(key.slice(1), BASE_REL),
|
|
key
|
|
)
|
|
assert.equal(
|
|
attachmentFullUrl(key, BASE_ABS),
|
|
`${BASE_ABS}/oa-approval/202608/10/907efa94baf245dcb47da30880bb0be5.png`
|
|
)
|
|
}
|
|
|
|
// 纯 object key
|
|
{
|
|
assert.equal(
|
|
attachmentFullUrl('oa-approval/202608/10/x.png', BASE_REL),
|
|
'/minio/zkxw/oa-approval/202608/10/x.png'
|
|
)
|
|
assert.equal(
|
|
attachmentFullUrl('oa-approval/202608/10/x.png', BASE_ABS),
|
|
'https://xwyd.zkxw.cn/minio/zkxw/oa-approval/202608/10/x.png'
|
|
)
|
|
}
|
|
|
|
// 内网绝对地址(无 location 时退回 pathname,避免双前缀)
|
|
{
|
|
const intranet =
|
|
'http://112.30.112.8:60001/minio/zkxw/oa-approval/202608/10/907efa94baf245dcb47da30880bb0be5.png'
|
|
assert.equal(
|
|
attachmentFullUrl(intranet, BASE_REL),
|
|
'/minio/zkxw/oa-approval/202608/10/907efa94baf245dcb47da30880bb0be5.png'
|
|
)
|
|
}
|
|
|
|
console.log('attachment.test.js: ok')
|