mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 15:09:19 +08:00
feat: 新增浏览器插件
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
export interface ExtensionSettings {
|
||||
/** 例:https://host/api (不要末尾斜杠) */
|
||||
apiBaseUrl: string;
|
||||
/** Open API Key(非 JWT) */
|
||||
apiKey: string;
|
||||
/** 记住的渠道店铺 */
|
||||
channelShopId?: number;
|
||||
channelShopName?: string;
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'ecbi.extension.settings';
|
||||
|
||||
const DEFAULT_SETTINGS: ExtensionSettings = {
|
||||
apiBaseUrl: '',
|
||||
apiKey: '',
|
||||
};
|
||||
|
||||
export async function getSettings(): Promise<ExtensionSettings> {
|
||||
const result = await chrome.storage.local.get(STORAGE_KEY);
|
||||
const raw = result[STORAGE_KEY] as Partial<ExtensionSettings> | undefined;
|
||||
return {
|
||||
...DEFAULT_SETTINGS,
|
||||
...raw,
|
||||
apiBaseUrl: (raw?.apiBaseUrl ?? '').replace(/\/+$/, ''),
|
||||
apiKey: raw?.apiKey ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
export async function saveSettings(
|
||||
patch: Partial<ExtensionSettings>,
|
||||
): Promise<ExtensionSettings> {
|
||||
const current = await getSettings();
|
||||
const next: ExtensionSettings = {
|
||||
...current,
|
||||
...patch,
|
||||
apiBaseUrl: (patch.apiBaseUrl ?? current.apiBaseUrl).replace(/\/+$/, ''),
|
||||
};
|
||||
await chrome.storage.local.set({ [STORAGE_KEY]: next });
|
||||
return next;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export type { ExtensionSettings } from './settings';
|
||||
Reference in New Issue
Block a user