feat: custom CDN for GitHub storage (#172) (#174)

Co-authored-by: Innei <tukon479@gmail.com>
This commit is contained in:
Chrys
2025-11-30 23:36:05 +08:00
committed by GitHub
parent 7b02aeaba6
commit a4ed1ecbc2
11 changed files with 107 additions and 2 deletions

View File

@@ -457,6 +457,12 @@ const enUiSchema = {
description: 'Optional path within the repository to limit syncing.',
placeholder: 'public/photos',
},
'custom-domain': {
label: 'Custom CDN domain',
description: 'CDN or proxy domain used when generating public URLs.',
placeholder: 'cdn.jsdelivr.net/gh/owner/repo@branch',
helper: 'Leave empty to keep raw.githubusercontent.com URLs.',
},
'use-raw': {
label: 'Use raw URL',
description: 'Use raw.githubusercontent.com when generating public URLs.',

View File

@@ -451,6 +451,12 @@ const zhCnUiSchema = {
description: '可选,限制同步的仓库路径。',
placeholder: 'public/photos可选',
},
'custom-domain': {
label: '自定义 CDN 域名',
description: '用于生成公开链接的 CDN 或代理域名。',
placeholder: 'cdn.jsdelivr.net/gh/owner/repo@branch示例',
helper: '留空则继续使用 raw.githubusercontent.com。',
},
'use-raw': {
label: '使用 raw 链接',
description: '生成公开链接时使用 raw.githubusercontent.com。',

View File

@@ -135,6 +135,13 @@ const STORAGE_PROVIDER_FIELD_CONFIG: Record<StorageProviderType, readonly Storag
placeholderKey: 'storage.providers.fields.github.path.placeholder',
descriptionKey: 'storage.providers.fields.github.path.description',
},
{
key: 'customDomain',
labelKey: 'storage.providers.fields.github.custom-domain.label',
placeholderKey: 'storage.providers.fields.github.custom-domain.placeholder',
descriptionKey: 'storage.providers.fields.github.custom-domain.description',
helperKey: 'storage.providers.fields.github.custom-domain.helper',
},
{
key: 'useRawUrl',
labelKey: 'storage.providers.fields.github.use-raw.label',

View File

@@ -191,6 +191,8 @@ export class PhotoStorageService {
if (pathValue) result.path = pathValue
const useRawUrl = parseBoolean(config.useRawUrl)
if (typeof useRawUrl === 'boolean') result.useRawUrl = useRawUrl
const customDomain = normalizeStringToUndefined(config.customDomain)
if (customDomain) result.customDomain = customDomain
return result
}

View File

@@ -46,6 +46,7 @@ const githubConfigSchema = z.object({
branch: z.string().optional(),
token: z.string().optional(),
path: z.string().optional(),
customDomain: z.string().optional(),
useRawUrl: z.boolean().optional(),
})