mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-30 17:50:07 +08:00
17db813d1c
* feat(ids)!: normalize persistent identifiers to Base62 BREAKING CHANGE: historical ZPan-owned IDs and public tokens require the one-time normalization migration; old public links and stored credentials are invalidated without runtime fallback. * fix(ids): namespace public redirect tokens Generate share tokens as s plus 11 Base62 characters and image tokens as i plus 11 Base62 characters. Dispatch /r by namespace prefix, reuse the single resolved record, and update migration validation, contracts, documentation, and tests. * fix(ids): guard future object storage keys * fix(ids): normalize historical references safely
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { eq } from 'drizzle-orm'
|
|
import { generateId } from '../../../shared/ids'
|
|
import { systemOptions } from '../../db/schema'
|
|
import type { Database } from '../../platform/interface'
|
|
import type { InstanceRepo } from '../../usecases/ports'
|
|
|
|
const INSTANCE_ID_KEY = 'instance_id'
|
|
|
|
export function createInstanceRepo(db: Database): InstanceRepo {
|
|
return {
|
|
async getOrCreateInstanceId() {
|
|
const rows = await db
|
|
.select({ value: systemOptions.value })
|
|
.from(systemOptions)
|
|
.where(eq(systemOptions.key, INSTANCE_ID_KEY))
|
|
.limit(1)
|
|
if (rows[0]?.value) return rows[0].value
|
|
|
|
const id = generateId()
|
|
await db
|
|
.insert(systemOptions)
|
|
.values({ key: INSTANCE_ID_KEY, value: id })
|
|
.onConflictDoUpdate({ target: systemOptions.key, set: { value: id } })
|
|
return id
|
|
},
|
|
|
|
async getInstanceDisplayName() {
|
|
const rows = await db
|
|
.select({ value: systemOptions.value })
|
|
.from(systemOptions)
|
|
.where(eq(systemOptions.key, 'site_title'))
|
|
.limit(1)
|
|
return rows[0]?.value ?? 'ZPan'
|
|
},
|
|
}
|
|
}
|