mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-30 05:18:49 +01:00
🎨 数据快照 - 本地快照显示文件类型 https://github.com/siyuan-note/siyuan/issues/6870
This commit is contained in:
parent
fc8d451e7c
commit
26a11dc3d0
4 changed files with 68 additions and 4 deletions
|
|
@ -86,7 +86,7 @@ const renderRepoItem = (response: IWebSocketData, element: Element, type: string
|
|||
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}"><svg><use xlink:href="#iconUndo"></use></svg></span>`;
|
||||
}
|
||||
let repoHTML = "";
|
||||
response.data.snapshots.forEach((item: { memo: string, id: string, hCreated: string, count: number, hSize: string, tag: string }) => {
|
||||
response.data.snapshots.forEach((item: { memo: string, id: string, hCreated: string, count: number, hSize: string, tag: string, typesCount: { type: string, count: number }[] }) => {
|
||||
if (isMobile()) {
|
||||
repoHTML += `<li class="b3-list-item b3-list-item--two">
|
||||
<div class="b3-list-item__first">
|
||||
|
|
@ -111,6 +111,11 @@ const renderRepoItem = (response: IWebSocketData, element: Element, type: string
|
|||
<span class="ft__smaller ft__on-surface">${item.hCreated}</span>
|
||||
<span class="b3-list-item__meta">${window.siyuan.languages.fileSize} ${item.hSize}</span>
|
||||
<span class="b3-list-item__meta">${window.siyuan.languages.fileCount} ${item.count}</span>
|
||||
<span class="b3-list-item__meta">
|
||||
${item.typesCount.map((type: { type: string, count: number }) => {
|
||||
return `${type.type} ${type.count}`;
|
||||
}).join(" ")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
${actionHTML}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ require (
|
|||
github.com/panjf2000/ants/v2 v2.7.0
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/radovskyb/watcher v1.0.7
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214060041-f7b64a7eb12a
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214062838-c08423e72b57
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
|
||||
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
|
||||
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
|
||||
|
|
|
|||
|
|
@ -363,6 +363,10 @@ github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYED
|
|||
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214060041-f7b64a7eb12a h1:9sAurbeois47ROtvJ9EcQFWfJIdL7C6fPZm29PhTBXg=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214060041-f7b64a7eb12a/go.mod h1:aarwJw3uJaqNoIGVLmyhZjMCjI+xAzwrMIg05scqmtc=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214062510-12058008827b h1:ACydDbRC5n76G843HaW+mx86hm3CZya/VUZlB0dtFnU=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214062510-12058008827b/go.mod h1:aarwJw3uJaqNoIGVLmyhZjMCjI+xAzwrMIg05scqmtc=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214062838-c08423e72b57 h1:luEVy9oqVB8yAlxVdwIMFoI53mVvSRG3N1rJ/+U6p3I=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221214062838-c08423e72b57/go.mod h1:aarwJw3uJaqNoIGVLmyhZjMCjI+xAzwrMIg05scqmtc=
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
|
||||
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -53,7 +54,18 @@ func init() {
|
|||
subscribeEvents()
|
||||
}
|
||||
|
||||
func GetRepoSnapshots(page int) (logs []*dejavu.Log, pageCount, totalCount int, err error) {
|
||||
type Snapshot struct {
|
||||
*dejavu.Log
|
||||
TypesCount []*TypeCount `json:"typesCount"`
|
||||
}
|
||||
|
||||
type TypeCount struct {
|
||||
Type string `json:"type"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
func GetRepoSnapshots(page int) (ret []*Snapshot, pageCount, totalCount int, err error) {
|
||||
ret = []*Snapshot{}
|
||||
if 1 > len(Conf.Repo.Key) {
|
||||
err = errors.New(Conf.Language(26))
|
||||
return
|
||||
|
|
@ -64,7 +76,7 @@ func GetRepoSnapshots(page int) (logs []*dejavu.Log, pageCount, totalCount int,
|
|||
return
|
||||
}
|
||||
|
||||
logs, pageCount, totalCount, err = repo.GetIndexLogs(page, 32)
|
||||
logs, pageCount, totalCount, err := repo.GetIndexLogs(page, 32)
|
||||
if nil != err {
|
||||
if dejavu.ErrNotFoundIndex == err {
|
||||
logs = []*dejavu.Log{}
|
||||
|
|
@ -75,6 +87,49 @@ func GetRepoSnapshots(page int) (logs []*dejavu.Log, pageCount, totalCount int,
|
|||
logging.LogErrorf("get data repo index logs failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 数据快照 - 本地快照显示文件类型 https://github.com/siyuan-note/siyuan/issues/6870
|
||||
for _, l := range logs {
|
||||
typesCount := statTypesByPath(l.Files)
|
||||
ret = append(ret, &Snapshot{
|
||||
Log: l,
|
||||
TypesCount: typesCount,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func statTypesByPath(files []*entity.File) (ret []*TypeCount) {
|
||||
m := map[string]int{}
|
||||
|
||||
for _, f := range files {
|
||||
ext := path.Ext(f.Path)
|
||||
m[ext]++
|
||||
}
|
||||
|
||||
var stated []string
|
||||
for ext, count := range m {
|
||||
ret = append(ret, &TypeCount{
|
||||
Type: ext,
|
||||
Count: count,
|
||||
})
|
||||
stated = append(stated, ext)
|
||||
if 10 < len(ret) {
|
||||
break
|
||||
}
|
||||
}
|
||||
sort.Slice(ret, func(i, j int) bool { return ret[i].Count > ret[j].Count })
|
||||
for _, s := range stated {
|
||||
delete(m, s)
|
||||
}
|
||||
otherCount := 0
|
||||
for _, count := range m {
|
||||
otherCount += count
|
||||
}
|
||||
ret = append(ret, &TypeCount{
|
||||
Type: "Other",
|
||||
Count: otherCount,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue