release: v1.2.6 — 新 UI 体验优化与存储标识规则
GitHub Release / release (push) Canceled after 0s
ci / ci (22, ubuntu-latest) (push) Canceled after 0s
Publish Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Canceled after 0s
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Canceled after 0s
Publish Docker image / merge (push) Canceled after 0s

This commit is contained in:
O96u committed 2026-09-01 21:31:02 +08:00
1 parent ac65c1eb9d
commit 8408d01197
38 files changed
+491 -369

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest'
import {
generateStorageBackendId,
resolveObjectStorageIdPrefix
} from './storage-backends'
describe('resolveObjectStorageIdPrefix', () => {
it('uses explicit provider when given', () => {
expect(resolveObjectStorageIdPrefix(
{ endpoint: 'https://example.com' },
'r2'
)).toBe('r2')
expect(resolveObjectStorageIdPrefix(
{ endpoint: 'https://example.com' },
'aws'
)).toBe('s3')
})
it('detects provider from endpoint', () => {
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://abc123.r2.cloudflarestorage.com'
})).toBe('r2')
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://cos.ap-guangzhou.myqcloud.com'
})).toBe('cos')
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://oss-cn-hangzhou.aliyuncs.com'
})).toBe('oss')
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://s3.us-east-1.amazonaws.com'
})).toBe('s3')
})
})
describe('generateStorageBackendId', () => {
it('uses provider-specific prefix', () => {
expect(generateStorageBackendId('r2')).toMatch(/^r2-[0-9a-f]{8}$/)
expect(generateStorageBackendId('s3')).toMatch(/^s3-[0-9a-f]{8}$/)
})
})
+27 -3
View File
@@ -368,16 +368,39 @@ function getNextSortOrder(): number {
return row.max_order + 1
}
export function generateStorageBackendId(): string {
export type ObjectStorageIdPrefix = 'r2' | 'cos' | 'oss' | 's3'
/** 根据表单预设或 endpoint 推断新建后端的 id 前缀 */
export function resolveObjectStorageIdPrefix(
config: Pick<S3BackendConfig, 'endpoint'>,
provider?: string
): ObjectStorageIdPrefix {
const normalized = provider?.trim().toLowerCase()
if (normalized === 'r2' || normalized === 'cos' || normalized === 'oss') {
return normalized
}
if (normalized === 'aws' || normalized === 's3') {
return 's3'
}
const endpoint = config.endpoint.trim().toLowerCase()
if (endpoint.includes('r2.cloudflarestorage.com')) return 'r2'
if (endpoint.includes('myqcloud.com')) return 'cos'
if (endpoint.includes('aliyuncs.com')) return 'oss'
return 's3'
}
export function generateStorageBackendId(prefix: ObjectStorageIdPrefix = 's3'): string {
const bytes = new Uint8Array(4)
crypto.getRandomValues(bytes)
const suffix = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('')
return `s3-${suffix}`
return `${prefix}-${suffix}`
}
export function insertStorageBackend(input: {
id?: string
name: string
provider?: string
config: S3BackendConfig
secrets: { accessKeyId: string, secretAccessKey: string }
servingMode?: ServingMode
@@ -387,7 +410,8 @@ export function insertStorageBackend(input: {
isDefault?: boolean
}): string {
ensureDefaultBackends()
const id = input.id ?? generateStorageBackendId()
const idPrefix = resolveObjectStorageIdPrefix(input.config, input.provider)
const id = input.id ?? generateStorageBackendId(idPrefix)
const sortOrder = getNextSortOrder()
getDb().prepare(`