mirror of
https://github.com/basketikun/infinite-canvas.git
synced 2026-08-05 17:04:27 +08:00
feat(webdav): add WebDAV synchronization configuration and functionality
This commit is contained in:
@@ -36,6 +36,15 @@ export type AiConfig = {
|
||||
canvasImageCount: string;
|
||||
};
|
||||
|
||||
export type WebdavSyncConfig = {
|
||||
proxyMode: "direct" | "nextjs";
|
||||
url: string;
|
||||
username: string;
|
||||
password: string;
|
||||
directory: string;
|
||||
lastSyncedAt: string;
|
||||
};
|
||||
|
||||
export const CONFIG_STORE_KEY = "infinite-canvas:ai_config_store";
|
||||
export type ModelCapability = "image" | "video" | "text" | "audio";
|
||||
|
||||
@@ -68,13 +77,24 @@ export const defaultConfig: AiConfig = {
|
||||
canvasImageCount: "3",
|
||||
};
|
||||
|
||||
export const defaultWebdavSyncConfig: WebdavSyncConfig = {
|
||||
proxyMode: "direct",
|
||||
url: "",
|
||||
username: "",
|
||||
password: "",
|
||||
directory: "infinite-canvas",
|
||||
lastSyncedAt: "",
|
||||
};
|
||||
|
||||
type ConfigStore = {
|
||||
config: AiConfig;
|
||||
webdav: WebdavSyncConfig;
|
||||
publicSettings: AdminPublicSettings | null;
|
||||
isPublicSettingsLoading: boolean;
|
||||
isConfigOpen: boolean;
|
||||
shouldPromptContinue: boolean;
|
||||
updateConfig: <K extends keyof AiConfig>(key: K, value: AiConfig[K]) => void;
|
||||
updateWebdavConfig: <K extends keyof WebdavSyncConfig>(key: K, value: WebdavSyncConfig[K]) => void;
|
||||
loadPublicSettings: () => Promise<void>;
|
||||
isAiConfigReady: (config: AiConfig, model: string) => boolean;
|
||||
openConfigDialog: (shouldPromptContinue?: boolean) => void;
|
||||
@@ -168,6 +188,7 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
config: defaultConfig,
|
||||
webdav: defaultWebdavSyncConfig,
|
||||
publicSettings: null,
|
||||
isPublicSettingsLoading: false,
|
||||
isConfigOpen: false,
|
||||
@@ -179,6 +200,13 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
[key]: value,
|
||||
},
|
||||
})),
|
||||
updateWebdavConfig: (key, value) =>
|
||||
set((state) => ({
|
||||
webdav: {
|
||||
...state.webdav,
|
||||
[key]: value,
|
||||
},
|
||||
})),
|
||||
loadPublicSettings: async () => {
|
||||
if (get().isPublicSettingsLoading) return;
|
||||
set({ isPublicSettingsLoading: true });
|
||||
@@ -195,12 +223,15 @@ export const useConfigStore = create<ConfigStore>()(
|
||||
}),
|
||||
{
|
||||
name: CONFIG_STORE_KEY,
|
||||
partialize: (state) => ({ config: state.config }),
|
||||
partialize: (state) => ({ config: state.config, webdav: state.webdav }),
|
||||
merge: (persisted, current) => {
|
||||
const persistedConfig = ((persisted as Partial<ConfigStore>).config || {}) as Partial<AiConfig>;
|
||||
const persistedState = (persisted || {}) as Partial<ConfigStore>;
|
||||
const persistedConfig = (persistedState.config || {}) as Partial<AiConfig>;
|
||||
const persistedWebdav = (persistedState.webdav || {}) as Partial<WebdavSyncConfig>;
|
||||
const config = { ...defaultConfig, ...persistedConfig };
|
||||
return {
|
||||
...current,
|
||||
webdav: { ...defaultWebdavSyncConfig, ...persistedWebdav },
|
||||
config: {
|
||||
...config,
|
||||
channelMode: config.channelMode || "remote",
|
||||
|
||||
Reference in New Issue
Block a user