refactor(web): adopt modular Vue architecture and isolate bearer sessions
This commit is contained in:
1 parent
1b2b2b12ff
commit
3cd641a380
379 files changed
+19736
-8712
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import type { CustomFont } from '@@/apis/preferences/type'
|
||||
import { fontResourceRoot, prepareResources } from '@@/apis/auth/resources'
|
||||
import { preferencesApi } from '@@/apis/preferences'
|
||||
import { shallowRef } from 'vue'
|
||||
|
||||
export const customFonts = shallowRef<CustomFont[]>([])
|
||||
|
||||
export function applyFontCatalog(fonts: CustomFont[]) {
|
||||
customFonts.value = fonts
|
||||
let style = document.getElementById('rm-custom-fonts')
|
||||
if (!style) {
|
||||
style = document.createElement('style'); style.id = 'rm-custom-fonts'; document.head.append(style)
|
||||
}
|
||||
// 名称仅用于界面;CSS 标识和资源路径只由服务端内容哈希构成。
|
||||
const css = fonts.map(font => `@font-face { font-family: '${font.id}'; src: url('${fontResourceRoot()}${font.id}/file'); font-display: block; }`).join('\n')
|
||||
if (style.textContent !== css) style.textContent = css
|
||||
}
|
||||
|
||||
export function parseFontCatalog(value: unknown): CustomFont[] {
|
||||
if (!Array.isArray(value) || value.some(font => !font || typeof font !== 'object' || !/^custom-[a-f0-9]{64}$/.test(font.id) || typeof font.name !== 'string' || !['ttf', 'otf', 'woff', 'woff2'].includes(font.format))) throw new Error('字体列表格式无效')
|
||||
return value
|
||||
}
|
||||
|
||||
export async function loadFonts() {
|
||||
await prepareResources()
|
||||
applyFontCatalog(parseFontCatalog(await preferencesApi.fonts()))
|
||||
}
|
||||
Reference in new issue
Block a user