🎨 Optimize storage logic

This commit is contained in:
2025-07-13 22:32:58 +08:00
parent 6d8fdf62f1
commit b4b0ad9bba
11 changed files with 671 additions and 45 deletions

View File

@@ -33,6 +33,11 @@ export class AppConfig {
*/
"updates": UpdatesConfig;
/**
* Git同步设置
*/
"sync": GitSyncConfig;
/**
* 配置元数据
*/
@@ -52,6 +57,9 @@ export class AppConfig {
if (!("updates" in $$source)) {
this["updates"] = (new UpdatesConfig());
}
if (!("sync" in $$source)) {
this["sync"] = (new GitSyncConfig());
}
if (!("metadata" in $$source)) {
this["metadata"] = (new ConfigMetadata());
}
@@ -68,6 +76,7 @@ export class AppConfig {
const $$createField2_0 = $$createType2;
const $$createField3_0 = $$createType3;
const $$createField4_0 = $$createType4;
const $$createField5_0 = $$createType5;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("general" in $$parsedSource) {
$$parsedSource["general"] = $$createField0_0($$parsedSource["general"]);
@@ -81,8 +90,11 @@ export class AppConfig {
if ("updates" in $$parsedSource) {
$$parsedSource["updates"] = $$createField3_0($$parsedSource["updates"]);
}
if ("sync" in $$parsedSource) {
$$parsedSource["sync"] = $$createField4_0($$parsedSource["sync"]);
}
if ("metadata" in $$parsedSource) {
$$parsedSource["metadata"] = $$createField4_0($$parsedSource["metadata"]);
$$parsedSource["metadata"] = $$createField5_0($$parsedSource["metadata"]);
}
return new AppConfig($$parsedSource as Partial<AppConfig>);
}
@@ -126,7 +138,7 @@ export class AppearanceConfig {
* Creates a new AppearanceConfig instance from a string or object.
*/
static createFrom($$source: any = {}): AppearanceConfig {
const $$createField2_0 = $$createType5;
const $$createField2_0 = $$createType6;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("customTheme" in $$parsedSource) {
$$parsedSource["customTheme"] = $$createField2_0($$parsedSource["customTheme"]);
@@ -135,6 +147,31 @@ export class AppearanceConfig {
}
}
/**
* AuthMethod 定义Git认证方式
*/
export enum AuthMethod {
/**
* The Go zero value for the underlying type of the enum.
*/
$zero = "",
/**
* 个人访问令牌
*/
Token = "token",
/**
* SSH密钥
*/
SSHKey = "ssh_key",
/**
* 用户名密码
*/
UserPass = "user_pass",
};
/**
* ConfigMetadata 配置元数据
*/
@@ -200,8 +237,8 @@ export class CustomThemeConfig {
* Creates a new CustomThemeConfig instance from a string or object.
*/
static createFrom($$source: any = {}): CustomThemeConfig {
const $$createField0_0 = $$createType6;
const $$createField1_0 = $$createType6;
const $$createField0_0 = $$createType7;
const $$createField1_0 = $$createType7;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("darkTheme" in $$parsedSource) {
$$parsedSource["darkTheme"] = $$createField0_0($$parsedSource["darkTheme"]);
@@ -224,6 +261,11 @@ export class Document {
"updatedAt": time$0.Time;
"is_deleted": boolean;
/**
* 锁定标志,锁定的文档无法被删除
*/
"is_locked": boolean;
/** Creates a new Document instance. */
constructor($$source: Partial<Document> = {}) {
if (!("id" in $$source)) {
@@ -244,6 +286,9 @@ export class Document {
if (!("is_deleted" in $$source)) {
this["is_deleted"] = false;
}
if (!("is_locked" in $$source)) {
this["is_locked"] = false;
}
Object.assign(this, $$source);
}
@@ -389,7 +434,7 @@ export class Extension {
* Creates a new Extension instance from a string or object.
*/
static createFrom($$source: any = {}): Extension {
const $$createField3_0 = $$createType7;
const $$createField3_0 = $$createType8;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("config" in $$parsedSource) {
$$parsedSource["config"] = $$createField3_0($$parsedSource["config"]);
@@ -522,7 +567,7 @@ export class GeneralConfig {
* Creates a new GeneralConfig instance from a string or object.
*/
static createFrom($$source: any = {}): GeneralConfig {
const $$createField5_0 = $$createType9;
const $$createField5_0 = $$createType10;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("globalHotkey" in $$parsedSource) {
$$parsedSource["globalHotkey"] = $$createField5_0($$parsedSource["globalHotkey"]);
@@ -531,6 +576,91 @@ export class GeneralConfig {
}
}
/**
* GitSyncConfig 保存Git同步的配置信息
*/
export class GitSyncConfig {
"enabled": boolean;
"repo_url": string;
"branch": string;
"auth_method": AuthMethod;
"username"?: string;
"password"?: string;
"token"?: string;
"ssh_key_path"?: string;
"ssh_key_passphrase"?: string;
/**
* 同步间隔(分钟)
*/
"sync_interval": number;
"last_sync_time": time$0.Time;
/**
* 是否启用自动同步
*/
"auto_sync": boolean;
"local_repo_path": string;
/**
* 合并冲突策略
*/
"sync_strategy": SyncStrategy;
/**
* 要同步的文件列表,默认为数据库文件
*/
"files_to_sync": string[];
/** Creates a new GitSyncConfig instance. */
constructor($$source: Partial<GitSyncConfig> = {}) {
if (!("enabled" in $$source)) {
this["enabled"] = false;
}
if (!("repo_url" in $$source)) {
this["repo_url"] = "";
}
if (!("branch" in $$source)) {
this["branch"] = "";
}
if (!("auth_method" in $$source)) {
this["auth_method"] = ("" as AuthMethod);
}
if (!("sync_interval" in $$source)) {
this["sync_interval"] = 0;
}
if (!("last_sync_time" in $$source)) {
this["last_sync_time"] = null;
}
if (!("auto_sync" in $$source)) {
this["auto_sync"] = false;
}
if (!("local_repo_path" in $$source)) {
this["local_repo_path"] = "";
}
if (!("sync_strategy" in $$source)) {
this["sync_strategy"] = ("" as SyncStrategy);
}
if (!("files_to_sync" in $$source)) {
this["files_to_sync"] = [];
}
Object.assign(this, $$source);
}
/**
* Creates a new GitSyncConfig instance from a string or object.
*/
static createFrom($$source: any = {}): GitSyncConfig {
const $$createField14_0 = $$createType11;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("files_to_sync" in $$parsedSource) {
$$parsedSource["files_to_sync"] = $$createField14_0($$parsedSource["files_to_sync"]);
}
return new GitSyncConfig($$parsedSource as Partial<GitSyncConfig>);
}
}
/**
* GiteaConfig Gitea配置
*/
@@ -1038,6 +1168,26 @@ export enum LanguageType {
LangEnUS = "en-US",
};
/**
* SyncStrategy 定义同步策略
*/
export enum SyncStrategy {
/**
* The Go zero value for the underlying type of the enum.
*/
$zero = "",
/**
* LocalFirst 本地优先:如有冲突,保留本地修改
*/
LocalFirst = "local_first",
/**
* RemoteFirst 远程优先:如有冲突,采用远程版本
*/
RemoteFirst = "remote_first",
};
/**
* SystemThemeType 系统主题类型定义
*/
@@ -1389,8 +1539,8 @@ export class UpdatesConfig {
* Creates a new UpdatesConfig instance from a string or object.
*/
static createFrom($$source: any = {}): UpdatesConfig {
const $$createField6_0 = $$createType10;
const $$createField7_0 = $$createType11;
const $$createField6_0 = $$createType12;
const $$createField7_0 = $$createType13;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("github" in $$parsedSource) {
$$parsedSource["github"] = $$createField6_0($$parsedSource["github"]);
@@ -1407,16 +1557,18 @@ const $$createType0 = GeneralConfig.createFrom;
const $$createType1 = EditingConfig.createFrom;
const $$createType2 = AppearanceConfig.createFrom;
const $$createType3 = UpdatesConfig.createFrom;
const $$createType4 = ConfigMetadata.createFrom;
const $$createType5 = CustomThemeConfig.createFrom;
const $$createType6 = ThemeColorConfig.createFrom;
var $$createType7 = (function $$initCreateType7(...args): any {
if ($$createType7 === $$initCreateType7) {
$$createType7 = $$createType8;
const $$createType4 = GitSyncConfig.createFrom;
const $$createType5 = ConfigMetadata.createFrom;
const $$createType6 = CustomThemeConfig.createFrom;
const $$createType7 = ThemeColorConfig.createFrom;
var $$createType8 = (function $$initCreateType8(...args): any {
if ($$createType8 === $$initCreateType8) {
$$createType8 = $$createType9;
}
return $$createType7(...args);
return $$createType8(...args);
});
const $$createType8 = $Create.Map($Create.Any, $Create.Any);
const $$createType9 = HotkeyCombo.createFrom;
const $$createType10 = GithubConfig.createFrom;
const $$createType11 = GiteaConfig.createFrom;
const $$createType9 = $Create.Map($Create.Any, $Create.Any);
const $$createType10 = HotkeyCombo.createFrom;
const $$createType11 = $Create.Array($Create.Any);
const $$createType12 = GithubConfig.createFrom;
const $$createType13 = GiteaConfig.createFrom;

View File

@@ -22,6 +22,14 @@ export function OnDataPathChanged(): Promise<void> & { cancel(): void } {
return $resultPromise;
}
/**
* RegisterModel 注册模型与表的映射关系
*/
export function RegisterModel(tableName: string, model: any): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(175397515, tableName, model) as any;
return $resultPromise;
}
/**
* ServiceShutdown shuts down the service when the application closes
*/

View File

@@ -81,6 +81,14 @@ export function ListDeletedDocumentsMeta(): Promise<(models$0.Document | null)[]
return $typingPromise;
}
/**
* LockDocument 锁定文档,防止删除
*/
export function LockDocument(id: number): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1889494473, id) as any;
return $resultPromise;
}
/**
* RestoreDocument restores a deleted document
*/
@@ -97,6 +105,14 @@ export function ServiceStartup(options: application$0.ServiceOptions): Promise<v
return $resultPromise;
}
/**
* UnlockDocument 解锁文档
*/
export function UnlockDocument(id: number): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(222307930, id) as any;
return $resultPromise;
}
/**
* UpdateDocumentContent updates the content of a document
*/

View File

@@ -11,6 +11,9 @@ import {
TabType,
UpdatesConfig,
UpdateSourceType,
GitSyncConfig,
AuthMethod,
SyncStrategy
} from '@/../bindings/voidraft/internal/models/models';
import {useI18n} from 'vue-i18n';
import {ConfigUtils} from '@/utils/configUtils';
@@ -48,6 +51,10 @@ type UpdatesConfigKeyMap = {
readonly [K in keyof UpdatesConfig]: string;
};
type SyncConfigKeyMap = {
readonly [K in keyof GitSyncConfig]: string;
};
type NumberConfigKey = 'fontSize' | 'tabSize' | 'lineHeight';
// 配置键映射
@@ -88,6 +95,24 @@ const UPDATES_CONFIG_KEY_MAP: UpdatesConfigKeyMap = {
gitea: 'updates.gitea'
} as const;
const SYNC_CONFIG_KEY_MAP: SyncConfigKeyMap = {
enabled: 'sync.enabled',
repo_url: 'sync.repo_url',
branch: 'sync.branch',
auth_method: 'sync.auth_method',
username: 'sync.username',
password: 'sync.password',
token: 'sync.token',
ssh_key_path: 'sync.ssh_key_path',
ssh_key_passphrase: 'sync.ssh_key_passphrase',
sync_interval: 'sync.sync_interval',
last_sync_time: 'sync.last_sync_time',
auto_sync: 'sync.auto_sync',
local_repo_path: 'sync.local_repo_path',
sync_strategy: 'sync.sync_strategy',
files_to_sync: 'sync.files_to_sync'
} as const;
// 配置限制
const CONFIG_LIMITS = {
fontSize: {min: 12, max: 28, default: 13},
@@ -261,6 +286,23 @@ const DEFAULT_CONFIG: AppConfig = {
repo: "voidraft",
}
},
sync: {
enabled: false,
repo_url: "",
branch: "main",
auth_method: AuthMethod.Token,
username: "",
password: "",
token: "",
ssh_key_path: "",
ssh_key_passphrase: "",
sync_interval: 60,
last_sync_time: null,
auto_sync: true,
local_repo_path: "",
sync_strategy: SyncStrategy.LocalFirst,
files_to_sync: ["voidraft.db"]
},
metadata: {
version: '1.0.0',
lastUpdated: new Date().toString(),
@@ -348,6 +390,21 @@ export const useConfigStore = defineStore('config', () => {
state.config.updates[key] = value;
};
const updateSyncConfig = async <K extends keyof GitSyncConfig>(key: K, value: GitSyncConfig[K]): Promise<void> => {
// 确保配置已加载
if (!state.configLoaded && !state.isLoading) {
await initConfig();
}
const backendKey = SYNC_CONFIG_KEY_MAP[key];
if (!backendKey) {
throw new Error(`No backend key mapping found for sync.${key.toString()}`);
}
await ConfigService.Set(backendKey, value);
state.config.sync[key] = value;
};
// 加载配置
const initConfig = async (): Promise<void> => {
if (state.isLoading) return;
@@ -362,6 +419,7 @@ export const useConfigStore = defineStore('config', () => {
if (appConfig.editing) Object.assign(state.config.editing, appConfig.editing);
if (appConfig.appearance) Object.assign(state.config.appearance, appConfig.appearance);
if (appConfig.updates) Object.assign(state.config.updates, appConfig.updates);
if (appConfig.sync) Object.assign(state.config.sync, appConfig.sync);
if (appConfig.metadata) Object.assign(state.config.metadata, appConfig.metadata);
}
@@ -594,6 +652,20 @@ export const useConfigStore = defineStore('config', () => {
},
// 更新配置相关方法
setAutoUpdate: async (value: boolean) => await updateUpdatesConfig('autoUpdate', value)
setAutoUpdate: async (value: boolean) => await updateUpdatesConfig('autoUpdate', value),
// Git同步配置相关方法
setGitSyncEnabled: (value: boolean) => updateSyncConfig('enabled', value),
setGitRepoUrl: (value: string) => updateSyncConfig('repo_url', value),
setGitBranch: (value: string) => updateSyncConfig('branch', value),
setAuthMethod: (value: AuthMethod) => updateSyncConfig('auth_method', value),
setGitUsername: (value: string) => updateSyncConfig('username', value),
setGitPassword: (value: string) => updateSyncConfig('password', value),
setGitToken: (value: string) => updateSyncConfig('token', value),
setSSHKeyPath: (value: string) => updateSyncConfig('ssh_key_path', value),
setSyncInterval: (value: number) => updateSyncConfig('sync_interval', value),
setAutoSync: (value: boolean) => updateSyncConfig('auto_sync', value),
setSyncStrategy: (value: SyncStrategy) => updateSyncConfig('sync_strategy', value),
setFilesToSync: (value: string[]) => updateSyncConfig('files_to_sync', value),
};
});