feat(settings): organize categories and include optional font storage
This commit is contained in:
1 parent
1408982782
commit
88492fdcde
15 files changed
+134
-59
No files matched your search
+6
-5
@@ -38,11 +38,12 @@ type Server struct {
|
||||
// 串行化设置的"读取-合并-写入"
|
||||
settingsMu sync.Mutex
|
||||
// ThemesDir 指向数据目录中的主题目录;为空时只有内置主题。
|
||||
DataDir string
|
||||
ThemesDir string
|
||||
PluginsDir string
|
||||
FontsDir string
|
||||
pluginsMu sync.Mutex
|
||||
DataDir string
|
||||
ThemesDir string
|
||||
PluginsDir string
|
||||
FontsDir string
|
||||
pluginsMu sync.Mutex
|
||||
BuiltinFontsSize int64
|
||||
}
|
||||
|
||||
func New(v *vault.Vault, a *auth.Manager, st *store.Store, hub *events.Hub, index *search.Index) *Server {
|
||||
|
||||
@@ -2469,7 +2469,9 @@
|
||||
"categories",
|
||||
"assetsSize",
|
||||
"trashSize",
|
||||
"calculatedAt"
|
||||
"calculatedAt",
|
||||
"builtinFontsSize",
|
||||
"customFontsSize"
|
||||
],
|
||||
"properties": {
|
||||
"totalSize": {
|
||||
@@ -2514,6 +2516,14 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"builtinFontsSize": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"customFontsSize": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-5
@@ -17,11 +17,13 @@ type storageCategory struct {
|
||||
}
|
||||
|
||||
type storageUsage struct {
|
||||
TotalSize int64 `json:"totalSize"`
|
||||
Categories []storageCategory `json:"categories"`
|
||||
AssetsSize int64 `json:"assetsSize"`
|
||||
TrashSize int64 `json:"trashSize"`
|
||||
CalculatedAt int64 `json:"calculatedAt"`
|
||||
TotalSize int64 `json:"totalSize"`
|
||||
Categories []storageCategory `json:"categories"`
|
||||
AssetsSize int64 `json:"assetsSize"`
|
||||
TrashSize int64 `json:"trashSize"`
|
||||
BuiltinFontsSize int64 `json:"builtinFontsSize"`
|
||||
CustomFontsSize int64 `json:"customFontsSize"`
|
||||
CalculatedAt int64 `json:"calculatedAt"`
|
||||
}
|
||||
|
||||
func (s *Server) getStorage(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -30,6 +32,10 @@ func (s *Server) getStorage(w http.ResponseWriter, r *http.Request) {
|
||||
internalError(w, r, err)
|
||||
return
|
||||
}
|
||||
usage.BuiltinFontsSize = s.BuiltinFontsSize
|
||||
usage.CustomFontsSize = usage.Categories[2].Size
|
||||
usage.Categories[2].Size += s.BuiltinFontsSize
|
||||
usage.TotalSize += s.BuiltinFontsSize
|
||||
writeJSON(w, http.StatusOK, usage)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"rawmark/internal/vault"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -79,3 +82,31 @@ func TestStorageDoesNotReturnPartialSuccess(t *testing.T) {
|
||||
t.Fatalf("请求取消应停止扫描: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStorageIncludesOptionalAndImportedFontBytes(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
os.MkdirAll(filepath.Join(root, "vault"), 0700)
|
||||
os.MkdirAll(filepath.Join(root, "fonts/custom"), 0700)
|
||||
os.WriteFile(filepath.Join(root, "fonts/custom/font.woff2"), make([]byte, 123), 0600)
|
||||
v, err := vault.Open(filepath.Join(root, "vault"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := &Server{DataDir: root, vault: v, BuiltinFontsSize: 456}
|
||||
recorder := httptest.NewRecorder()
|
||||
s.getStorage(recorder, httptest.NewRequest("GET", "/", nil))
|
||||
var usage storageUsage
|
||||
if err = json.Unmarshal(recorder.Body.Bytes(), &usage); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if usage.BuiltinFontsSize != 456 || usage.CustomFontsSize != 123 || usage.Categories[2].Size != 579 {
|
||||
t.Fatalf("字体统计错误: %+v", usage)
|
||||
}
|
||||
var sum int64
|
||||
for _, category := range usage.Categories {
|
||||
sum += category.Size
|
||||
}
|
||||
if sum != usage.TotalSize {
|
||||
t.Fatal("分类与总量不一致")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user