Files
website/src/payload/upload-paste-url-allow-list.ts
T

30 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-04-28 00:55:07 +08:00
import type { AllowList } from 'payload'
2026-07-27 18:14:19 +08:00
/**
* Paste-URL allow list for upload fields (media / files / videos).
*
* Configure via the NEXT_PUBLIC_PASTE_URL_ALLOW_LIST environment variable:
* - Comma-separated hostnames, e.g. "www.eversolo.com,am.luxsinaudio.com"
* - Bare hostnames default to https; you may also pass full "protocol://host" entries.
* - When the variable is unset or empty, the built-in defaults below are used.
*
* NOTE: NEXT_PUBLIC_ prefix is required so the client-side fetch interceptor
* can also read this value at build time.
*/
const DEFAULT_HOSTS = ['www.eversolo.com', 'eversolo.com', 'am.luxsinaudio.com']
function buildAllowList(): AllowList {
const raw = (process.env.NEXT_PUBLIC_PASTE_URL_ALLOW_LIST || '').trim()
const entries = raw ? raw.split(',').map((item) => item.trim()).filter(Boolean) : DEFAULT_HOSTS
return entries.map((entry) => {
if (/^https?:\/\//i.test(entry)) {
const url = new URL(entry)
return { hostname: url.hostname, protocol: url.protocol.replace(':', '') as 'http' | 'https' }
}
return { hostname: entry, protocol: 'https' as const }
})
}
export const eversoloPasteURLAllowList: AllowList = buildAllowList()