feat:首页和案例库功能
This commit is contained in:
36
src/utils/resolve-oss-media.ts
Normal file
36
src/utils/resolve-oss-media.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { getOssListByIds } from '@/api/oss'
|
||||
|
||||
export function isHttpUrl(value?: string) {
|
||||
return Boolean(value && /^https?:\/\//.test(value))
|
||||
}
|
||||
|
||||
export async function resolveOssUrlMap(rawIds: Array<string | undefined>) {
|
||||
const map = new Map<string, string>()
|
||||
const ossIds = rawIds
|
||||
.filter((id): id is string => Boolean(id && !isHttpUrl(id)))
|
||||
.map(String)
|
||||
|
||||
if (!ossIds.length)
|
||||
return map
|
||||
|
||||
try {
|
||||
const files = await getOssListByIds(ossIds)
|
||||
for (const file of files ?? []) {
|
||||
if (file.ossId && file.url)
|
||||
map.set(String(file.ossId), file.url)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return map
|
||||
}
|
||||
|
||||
export function pickMediaUrl(raw?: string, urlMap?: Map<string, string>) {
|
||||
if (!raw)
|
||||
return undefined
|
||||
if (isHttpUrl(raw))
|
||||
return raw
|
||||
return urlMap?.get(String(raw))
|
||||
}
|
||||
Reference in New Issue
Block a user