🎨 Optimize storage logic
This commit is contained in:
@@ -124,6 +124,7 @@ type AppConfig struct {
|
||||
Editing EditingConfig `json:"editing"` // 编辑设置
|
||||
Appearance AppearanceConfig `json:"appearance"` // 外观设置
|
||||
Updates UpdatesConfig `json:"updates"` // 更新设置
|
||||
Sync GitSyncConfig `json:"sync"` // Git同步设置
|
||||
Metadata ConfigMetadata `json:"metadata"` // 配置元数据
|
||||
}
|
||||
|
||||
@@ -138,6 +139,7 @@ func NewDefaultAppConfig() *AppConfig {
|
||||
|
||||
currentDir, _ := os.UserHomeDir()
|
||||
dataDir := filepath.Join(currentDir, ".voidraft", "data")
|
||||
repoPath := filepath.Join(currentDir, ".voidraft", "sync-repo")
|
||||
|
||||
return &AppConfig{
|
||||
General: GeneralConfig{
|
||||
@@ -173,7 +175,7 @@ func NewDefaultAppConfig() *AppConfig {
|
||||
CustomTheme: *NewDefaultCustomThemeConfig(),
|
||||
},
|
||||
Updates: UpdatesConfig{
|
||||
Version: "1.0.0",
|
||||
Version: "1.2.0",
|
||||
AutoUpdate: true,
|
||||
PrimarySource: UpdateSourceGithub,
|
||||
BackupSource: UpdateSourceGitea,
|
||||
@@ -189,9 +191,25 @@ func NewDefaultAppConfig() *AppConfig {
|
||||
Repo: "voidraft",
|
||||
},
|
||||
},
|
||||
Sync: GitSyncConfig{
|
||||
Enabled: false,
|
||||
RepoURL: "",
|
||||
Branch: "main",
|
||||
AuthMethod: Token,
|
||||
Username: "",
|
||||
Password: "",
|
||||
Token: "",
|
||||
SSHKeyPath: "",
|
||||
SyncInterval: 60,
|
||||
LastSyncTime: time.Time{},
|
||||
AutoSync: true,
|
||||
LocalRepoPath: repoPath,
|
||||
SyncStrategy: LocalFirst,
|
||||
FilesToSync: []string{"voidraft.db"},
|
||||
},
|
||||
Metadata: ConfigMetadata{
|
||||
LastUpdated: time.Now().Format(time.RFC3339),
|
||||
Version: "1.0.0",
|
||||
Version: "1.2.0",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,10 @@ type Document struct {
|
||||
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
IsLocked bool `json:"is_locked" db:"is_locked"` // 锁定标志,锁定的文档无法被删除
|
||||
}
|
||||
|
||||
// NewDocument 创建新文档(不需要传ID,由数据库自增)
|
||||
// NewDocument 创建新文档
|
||||
func NewDocument(title, content string) *Document {
|
||||
now := time.Now()
|
||||
return &Document{
|
||||
@@ -23,6 +24,7 @@ func NewDocument(title, content string) *Document {
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
IsDeleted: false,
|
||||
IsLocked: false, // 默认不锁定
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import "time"
|
||||
|
||||
// Extension 单个扩展配置
|
||||
type Extension struct {
|
||||
ID ExtensionID `json:"id"` // 扩展唯一标识
|
||||
Enabled bool `json:"enabled"` // 是否启用
|
||||
IsDefault bool `json:"isDefault"` // 是否为默认扩展
|
||||
Config ExtensionConfig `json:"config"` // 扩展配置项
|
||||
ID ExtensionID `json:"id" db:"id"` // 扩展唯一标识
|
||||
Enabled bool `json:"enabled" db:"enabled"` // 是否启用
|
||||
IsDefault bool `json:"isDefault" db:"is_default"` // 是否为默认扩展
|
||||
Config ExtensionConfig `json:"config" db:"config"` // 扩展配置项
|
||||
}
|
||||
|
||||
// ExtensionID 扩展标识符
|
||||
|
||||
@@ -4,11 +4,11 @@ import "time"
|
||||
|
||||
// KeyBinding 单个快捷键绑定
|
||||
type KeyBinding struct {
|
||||
Command KeyBindingCommand `json:"command"` // 快捷键动作
|
||||
Extension ExtensionID `json:"extension"` // 所属扩展
|
||||
Key string `json:"key"` // 快捷键组合(如 "Mod-f", "Ctrl-Shift-p")
|
||||
Enabled bool `json:"enabled"` // 是否启用
|
||||
IsDefault bool `json:"isDefault"` // 是否为默认快捷键
|
||||
Command KeyBindingCommand `json:"command" db:"command"` // 快捷键动作
|
||||
Extension ExtensionID `json:"extension" db:"extension"` // 所属扩展
|
||||
Key string `json:"key" db:"key"` // 快捷键组合(如 "Mod-f", "Ctrl-Shift-p")
|
||||
Enabled bool `json:"enabled" db:"enabled"` // 是否启用
|
||||
IsDefault bool `json:"isDefault" db:"is_default"` // 是否为默认快捷键
|
||||
}
|
||||
|
||||
// KeyBindingCommand 快捷键命令
|
||||
|
||||
63
internal/models/sync.go
Normal file
63
internal/models/sync.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// AuthMethod 定义Git认证方式
|
||||
type AuthMethod string
|
||||
|
||||
const (
|
||||
Token AuthMethod = "token" // 个人访问令牌
|
||||
SSHKey AuthMethod = "ssh_key" // SSH密钥
|
||||
UserPass AuthMethod = "user_pass" // 用户名密码
|
||||
)
|
||||
|
||||
// SyncStrategy 定义同步策略
|
||||
type SyncStrategy string
|
||||
|
||||
const (
|
||||
// LocalFirst 本地优先:如有冲突,保留本地修改
|
||||
LocalFirst SyncStrategy = "local_first"
|
||||
// RemoteFirst 远程优先:如有冲突,采用远程版本
|
||||
RemoteFirst SyncStrategy = "remote_first"
|
||||
)
|
||||
|
||||
// GitSyncConfig 保存Git同步的配置信息
|
||||
type GitSyncConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
RepoURL string `json:"repo_url"`
|
||||
Branch string `json:"branch"`
|
||||
AuthMethod AuthMethod `json:"auth_method"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
SSHKeyPath string `json:"ssh_key_path,omitempty"`
|
||||
SSHKeyPassphrase string `json:"ssh_key_passphrase,omitempty"`
|
||||
SyncInterval int `json:"sync_interval"` // 同步间隔(分钟)
|
||||
LastSyncTime time.Time `json:"last_sync_time"`
|
||||
AutoSync bool `json:"auto_sync"` // 是否启用自动同步
|
||||
LocalRepoPath string `json:"local_repo_path"`
|
||||
SyncStrategy SyncStrategy `json:"sync_strategy"` // 合并冲突策略
|
||||
FilesToSync []string `json:"files_to_sync"` // 要同步的文件列表,默认为数据库文件
|
||||
}
|
||||
|
||||
// GitSyncStatus 保存同步状态信息
|
||||
type GitSyncStatus struct {
|
||||
IsSyncing bool `json:"is_syncing"`
|
||||
LastSyncTime time.Time `json:"last_sync_time"`
|
||||
LastSyncStatus string `json:"last_sync_status"` // success, failed, conflict
|
||||
LastErrorMsg string `json:"last_error_msg,omitempty"`
|
||||
LastCommitID string `json:"last_commit_id,omitempty"`
|
||||
RemoteCommitID string `json:"remote_commit_id,omitempty"`
|
||||
CommitAhead int `json:"commit_ahead"` // 本地领先远程的提交数
|
||||
CommitBehind int `json:"commit_behind"` // 本地落后远程的提交数
|
||||
}
|
||||
|
||||
// SyncLogEntry 记录每次同步操作的日志
|
||||
type SyncLogEntry struct {
|
||||
ID int64 `json:"id"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Action string `json:"action"` // push, pull, reset
|
||||
Status string `json:"status"` // success, failed
|
||||
Message string `json:"message,omitempty"`
|
||||
ChangedFiles int `json:"changed_files"`
|
||||
}
|
||||
Reference in New Issue
Block a user