✨ Complete the document saving service
This commit is contained in:
@@ -16,6 +16,21 @@ const (
|
||||
TabTypeTab TabType = "tab"
|
||||
)
|
||||
|
||||
// SaveOptions 保存选项
|
||||
type SaveOptions struct {
|
||||
// 自动保存延迟(毫秒)- 内容变更后多久自动保存
|
||||
AutoSaveDelay int `json:"autoSaveDelay"`
|
||||
// 变更字符阈值,超过此阈值立即触发保存
|
||||
ChangeThreshold int `json:"changeThreshold"`
|
||||
// 最小保存间隔(毫秒)- 两次保存之间的最小时间间隔,避免频繁IO
|
||||
MinSaveInterval int `json:"minSaveInterval"`
|
||||
}
|
||||
|
||||
// DocumentConfig 定义文档配置
|
||||
type DocumentConfig struct {
|
||||
SaveOptions SaveOptions `json:"saveOptions"` // 详细保存选项
|
||||
}
|
||||
|
||||
// EditorConfig 定义编辑器配置
|
||||
type EditorConfig struct {
|
||||
FontSize int `json:"fontSize"` // 字体大小
|
||||
@@ -45,6 +60,7 @@ type PathsConfig struct {
|
||||
// AppConfig 应用配置 - 包含业务配置和路径配置
|
||||
type AppConfig struct {
|
||||
Editor EditorConfig `json:"editor"` // 编辑器配置
|
||||
Document DocumentConfig `json:"document"` // 文档配置
|
||||
Paths PathsConfig `json:"paths"` // 路径配置
|
||||
Metadata ConfigMetadata `json:"metadata"` // 配置元数据
|
||||
}
|
||||
@@ -65,6 +81,7 @@ func NewDefaultAppConfig() *AppConfig {
|
||||
|
||||
// 默认路径配置
|
||||
rootDir := filepath.Join(homePath, ".voidraft")
|
||||
dataDir := filepath.Join(rootDir, "data")
|
||||
|
||||
return &AppConfig{
|
||||
Editor: EditorConfig{
|
||||
@@ -75,9 +92,16 @@ func NewDefaultAppConfig() *AppConfig {
|
||||
Language: LangZhCN,
|
||||
AlwaysOnTop: false,
|
||||
},
|
||||
Document: DocumentConfig{
|
||||
SaveOptions: SaveOptions{
|
||||
AutoSaveDelay: 5000, // 5秒后自动保存
|
||||
ChangeThreshold: 500, // 500个字符变更触发保存
|
||||
MinSaveInterval: 1000, // 最小间隔1000毫秒
|
||||
},
|
||||
},
|
||||
Paths: PathsConfig{
|
||||
LogPath: filepath.Join(rootDir, "logs"),
|
||||
DataPath: filepath.Join(rootDir, "data"),
|
||||
DataPath: dataDir,
|
||||
},
|
||||
Metadata: ConfigMetadata{
|
||||
Version: "1.0.0",
|
||||
|
||||
41
internal/models/document.go
Normal file
41
internal/models/document.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// DocumentMeta 文档元数据
|
||||
type DocumentMeta struct {
|
||||
ID string `json:"id"` // 文档唯一标识
|
||||
Title string `json:"title"` // 文档标题
|
||||
LastUpdated time.Time `json:"lastUpdated"` // 最后更新时间
|
||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
||||
}
|
||||
|
||||
// Document 表示一个文档
|
||||
type Document struct {
|
||||
Meta DocumentMeta `json:"meta"` // 元数据
|
||||
Content string `json:"content"` // 文档内容
|
||||
}
|
||||
|
||||
// DocumentInfo 文档信息(不包含内容,用于列表展示)
|
||||
type DocumentInfo struct {
|
||||
ID string `json:"id"` // 文档ID
|
||||
Title string `json:"title"` // 文档标题
|
||||
LastUpdated time.Time `json:"lastUpdated"` // 最后更新时间
|
||||
Path string `json:"path"` // 文档路径
|
||||
}
|
||||
|
||||
// NewDefaultDocument 创建默认文档
|
||||
func NewDefaultDocument() *Document {
|
||||
now := time.Now()
|
||||
return &Document{
|
||||
Meta: DocumentMeta{
|
||||
ID: "default",
|
||||
Title: "默认文档",
|
||||
LastUpdated: now,
|
||||
CreatedAt: now,
|
||||
},
|
||||
Content: "// 在此处编写文本...",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user