refactor(server): 规范化 licence 持久化结构
This commit is contained in:
@@ -4,7 +4,10 @@ import { generatedFields } from '../fields'
|
|||||||
export const uxConfigTable = sqliteTable('ux_config', {
|
export const uxConfigTable = sqliteTable('ux_config', {
|
||||||
...generatedFields,
|
...generatedFields,
|
||||||
singletonKey: text('singleton_key').notNull().unique().default('default'),
|
singletonKey: text('singleton_key').notNull().unique().default('default'),
|
||||||
licence: text('licence'),
|
licencePayload: text('licence_payload'),
|
||||||
|
licenceSignature: text('licence_signature'),
|
||||||
|
licenceId: text('licence_id'),
|
||||||
|
licenceExpireTime: text('licence_expire_time'),
|
||||||
fingerprint: text('fingerprint').notNull(),
|
fingerprint: text('fingerprint').notNull(),
|
||||||
platformPublicKey: text('platform_public_key'),
|
platformPublicKey: text('platform_public_key'),
|
||||||
pgpPrivateKey: text('pgp_private_key'),
|
pgpPrivateKey: text('pgp_private_key'),
|
||||||
|
|||||||
@@ -32,17 +32,37 @@ export const ensureUxConfig = async (db: DB) => {
|
|||||||
.values({
|
.values({
|
||||||
singletonKey: UX_CONFIG_KEY,
|
singletonKey: UX_CONFIG_KEY,
|
||||||
fingerprint,
|
fingerprint,
|
||||||
licence: null,
|
licencePayload: null,
|
||||||
|
licenceSignature: null,
|
||||||
|
licenceId: null,
|
||||||
|
licenceExpireTime: null,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
|
|
||||||
return rows[0] as (typeof rows)[number]
|
return rows[0] as (typeof rows)[number]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setUxLicence = async (db: DB, licence: string) => {
|
export const setUxLicence = async (
|
||||||
|
db: DB,
|
||||||
|
licence: {
|
||||||
|
payload: string
|
||||||
|
signature: string
|
||||||
|
licenceId: string
|
||||||
|
expireTime: string
|
||||||
|
},
|
||||||
|
) => {
|
||||||
const config = await ensureUxConfig(db)
|
const config = await ensureUxConfig(db)
|
||||||
|
|
||||||
const rows = await db.update(uxConfigTable).set({ licence }).where(eq(uxConfigTable.id, config.id)).returning()
|
const rows = await db
|
||||||
|
.update(uxConfigTable)
|
||||||
|
.set({
|
||||||
|
licencePayload: licence.payload,
|
||||||
|
licenceSignature: licence.signature,
|
||||||
|
licenceId: licence.licenceId,
|
||||||
|
licenceExpireTime: licence.expireTime,
|
||||||
|
})
|
||||||
|
.where(eq(uxConfigTable.id, config.id))
|
||||||
|
.returning()
|
||||||
|
|
||||||
return rows[0] as (typeof rows)[number]
|
return rows[0] as (typeof rows)[number]
|
||||||
}
|
}
|
||||||
@@ -57,10 +77,21 @@ export const setUxPgpPrivateKey = async (db: DB, pgpPrivateKey: string) => {
|
|||||||
|
|
||||||
export const setUxPlatformPublicKey = async (db: DB, platformPublicKey: string) => {
|
export const setUxPlatformPublicKey = async (db: DB, platformPublicKey: string) => {
|
||||||
const config = await ensureUxConfig(db)
|
const config = await ensureUxConfig(db)
|
||||||
|
const shouldClearLicence = config.platformPublicKey !== platformPublicKey
|
||||||
|
|
||||||
const rows = await db
|
const rows = await db
|
||||||
.update(uxConfigTable)
|
.update(uxConfigTable)
|
||||||
.set({ platformPublicKey })
|
.set({
|
||||||
|
platformPublicKey,
|
||||||
|
...(shouldClearLicence
|
||||||
|
? {
|
||||||
|
licencePayload: null,
|
||||||
|
licenceSignature: null,
|
||||||
|
licenceId: null,
|
||||||
|
licenceExpireTime: null,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
})
|
||||||
.where(eq(uxConfigTable.id, config.id))
|
.where(eq(uxConfigTable.id, config.id))
|
||||||
.returning()
|
.returning()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user