Add Timezone, Zombie GC. Improved and select theme.
This commit is contained in:
1 parent
ea3eba180b
commit
5a596985e0
26 files changed
+605
-59
No files matched your search
@@ -3,7 +3,9 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func parseNavItemsFromForm(
|
||||
@@ -132,6 +134,87 @@ func (s *Server) handleConfig(
|
||||
return
|
||||
}
|
||||
|
||||
timezoneName :=
|
||||
strings.TrimSpace(
|
||||
r.FormValue("timezone"),
|
||||
)
|
||||
|
||||
if timezoneName == "" {
|
||||
timezoneName = "UTC"
|
||||
}
|
||||
|
||||
_, err = time.LoadLocation(
|
||||
timezoneName,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, "invalid timezone", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err = s.store.SetConfig(
|
||||
"timezone",
|
||||
timezoneName,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
theme :=
|
||||
s.getTheme()
|
||||
|
||||
if v := strings.TrimSpace(r.FormValue("theme")); v != "" {
|
||||
switch v {
|
||||
case "dark", "light", "monokai", "solarized-dark", "solarized-light":
|
||||
theme = v
|
||||
default:
|
||||
http.Error(w, "invalid theme", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = s.store.SetConfig(
|
||||
"theme",
|
||||
theme,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
graceHours :=
|
||||
strings.TrimSpace(
|
||||
r.FormValue("zombie_grace_hours"),
|
||||
)
|
||||
|
||||
if graceHours == "" {
|
||||
graceHours = "24"
|
||||
}
|
||||
|
||||
_, err = strconv.ParseInt(
|
||||
graceHours,
|
||||
10,
|
||||
64,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, "invalid zombie grace hours", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err = s.store.SetConfig(
|
||||
"zombie_grace_hours",
|
||||
graceHours,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
case "nav-home":
|
||||
|
||||
err = s.saveNavConfig(
|
||||
@@ -156,6 +239,18 @@ func (s *Server) handleConfig(
|
||||
return
|
||||
}
|
||||
|
||||
case "zombie-purge":
|
||||
|
||||
_, err = s.store.PurgeZombieObjects(
|
||||
s.getZombieGraceSeconds(),
|
||||
100,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
http.Error(
|
||||
@@ -167,10 +262,16 @@ func (s *Server) handleConfig(
|
||||
return
|
||||
}
|
||||
|
||||
panel := section
|
||||
|
||||
if section == "zombie-purge" {
|
||||
panel = "objects"
|
||||
}
|
||||
|
||||
http.Redirect(
|
||||
w,
|
||||
r,
|
||||
"/-/sys/config?panel="+section,
|
||||
"/-/sys/config?panel="+panel,
|
||||
http.StatusFound,
|
||||
)
|
||||
|
||||
@@ -201,6 +302,9 @@ func (s *Server) handleConfig(
|
||||
wikiName = "Pages Wiki"
|
||||
}
|
||||
|
||||
zombieGraceHours :=
|
||||
s.getZombieGraceHours()
|
||||
|
||||
recent, err :=
|
||||
s.store.ListRecentObjects(
|
||||
50,
|
||||
@@ -211,6 +315,16 @@ func (s *Server) handleConfig(
|
||||
return
|
||||
}
|
||||
|
||||
zombies, err :=
|
||||
s.store.ListZombieObjects(
|
||||
s.getZombieGraceSeconds(),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
s.render(
|
||||
w,
|
||||
"config.gohtml",
|
||||
@@ -222,7 +336,11 @@ func (s *Server) handleConfig(
|
||||
"HomePath": homePath,
|
||||
"WikiName": wikiName,
|
||||
"Locale": s.getLocale(),
|
||||
"Timezone": s.getTimezoneName(),
|
||||
"Theme": s.getTheme(),
|
||||
"ZombieGraceHours": zombieGraceHours,
|
||||
"Objects": recent,
|
||||
"ZombieObjects": zombies,
|
||||
"HomeNavItemsConfig": s.getHomeNavItems(),
|
||||
"SystemNavItemsConfig": s.getSystemNavItems(),
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@ func (s *Server) startGCWorker() {
|
||||
|
||||
deleted, err :=
|
||||
s.store.PurgeZombieObjects(
|
||||
24*60*60,
|
||||
s.getZombieGraceSeconds(),
|
||||
100,
|
||||
)
|
||||
|
||||
|
||||
+60
-56
@@ -6,64 +6,68 @@ import (
|
||||
|
||||
var translations = map[string]map[string]string{
|
||||
"en": {
|
||||
"config.title": "Config",
|
||||
"config.home": "Home",
|
||||
"config.wiki_name": "Wiki name",
|
||||
"config.locale": "Language",
|
||||
"config.home_path": "Home semantic path",
|
||||
"config.save": "Save",
|
||||
"config.nav": "Navigation",
|
||||
"config.objects": "Recent Objects",
|
||||
"config.primary": "Primary Link",
|
||||
"config.size": "Size",
|
||||
"config.updated": "Updated",
|
||||
"config.object": "Object",
|
||||
"config.nav_label": "Label",
|
||||
"config.nav_href": "Href",
|
||||
"config.nav_order": "Order",
|
||||
"config.nav_save": "Save Navigation",
|
||||
"config.nav_home": "Home Navigation",
|
||||
"config.nav_system": "System Navigation",
|
||||
"link.title": "Link Manager",
|
||||
"link.object": "Object",
|
||||
"link.primary": "Primary",
|
||||
"link.path": "Path",
|
||||
"link.linked_at": "Linked At",
|
||||
"link.action": "Action",
|
||||
"link.delete": "Delete",
|
||||
"link.add": "Add",
|
||||
"link.add_path": "Add Link",
|
||||
"link.placeholder": "/pageswiki/example",
|
||||
"config.title": "Config",
|
||||
"config.home": "Home",
|
||||
"config.wiki_name": "Wiki name",
|
||||
"config.locale": "Language",
|
||||
"config.timezone": "Timezone",
|
||||
"config.zombie_grace_hours": "Zombie grace period (hours)",
|
||||
"config.home_path": "Home semantic path",
|
||||
"config.save": "Save",
|
||||
"config.nav": "Navigation",
|
||||
"config.objects": "Recent Objects",
|
||||
"config.primary": "Primary Link",
|
||||
"config.size": "Size",
|
||||
"config.updated": "Updated",
|
||||
"config.object": "Object",
|
||||
"config.nav_label": "Label",
|
||||
"config.nav_href": "Href",
|
||||
"config.nav_order": "Order",
|
||||
"config.nav_save": "Save Navigation",
|
||||
"config.nav_home": "Home Navigation",
|
||||
"config.nav_system": "System Navigation",
|
||||
"link.title": "Link Manager",
|
||||
"link.object": "Object",
|
||||
"link.primary": "Primary",
|
||||
"link.path": "Path",
|
||||
"link.linked_at": "Linked At",
|
||||
"link.action": "Action",
|
||||
"link.delete": "Delete",
|
||||
"link.add": "Add",
|
||||
"link.add_path": "Add Link",
|
||||
"link.placeholder": "/pageswiki/example",
|
||||
},
|
||||
"ja": {
|
||||
"config.title": "設定",
|
||||
"config.home": "ホーム",
|
||||
"config.wiki_name": "Wiki名称",
|
||||
"config.locale": "言語",
|
||||
"config.home_path": "トップページ",
|
||||
"config.save": "保存",
|
||||
"config.nav": "ナビゲーション",
|
||||
"config.nav_home": "ホームナビゲーション",
|
||||
"config.nav_system": "システムナビゲーション",
|
||||
"config.objects": "最近のオブジェクト",
|
||||
"link.title": "リンク管理",
|
||||
"link.object": "オブジェクト",
|
||||
"link.primary": "主リンク",
|
||||
"link.path": "パス",
|
||||
"link.linked_at": "リンクされた日時",
|
||||
"link.action": "操作",
|
||||
"link.delete": "削除",
|
||||
"link.add": "追加",
|
||||
"link.add_path": "リンクを追加",
|
||||
"link.placeholder": "/pageswiki/example",
|
||||
"config.primary": "主なリンク",
|
||||
"config.size": "サイズ",
|
||||
"config.updated": "最終更新",
|
||||
"config.object": "オブジェクト",
|
||||
"config.nav_label": "表示名",
|
||||
"config.nav_href": "リンク先",
|
||||
"config.nav_order": "順序",
|
||||
"config.nav_save": "ナビゲーションを保存",
|
||||
"config.title": "設定",
|
||||
"config.home": "ホーム",
|
||||
"config.wiki_name": "Wiki名称",
|
||||
"config.locale": "言語",
|
||||
"config.timezone": "タイムゾーン",
|
||||
"config.zombie_grace_hours": "ゾンビ判定猶予時間(時間)",
|
||||
"config.home_path": "トップページ",
|
||||
"config.save": "保存",
|
||||
"config.nav": "ナビゲーション",
|
||||
"config.nav_home": "ホームナビゲーション",
|
||||
"config.nav_system": "システムナビゲーション",
|
||||
"config.objects": "最近のオブジェクト",
|
||||
"link.title": "リンク管理",
|
||||
"link.object": "オブジェクト",
|
||||
"link.primary": "主リンク",
|
||||
"link.path": "パス",
|
||||
"link.linked_at": "リンクされた日時",
|
||||
"link.action": "操作",
|
||||
"link.delete": "削除",
|
||||
"link.add": "追加",
|
||||
"link.add_path": "リンクを追加",
|
||||
"link.placeholder": "/pageswiki/example",
|
||||
"config.primary": "主なリンク",
|
||||
"config.size": "サイズ",
|
||||
"config.updated": "最終更新",
|
||||
"config.object": "オブジェクト",
|
||||
"config.nav_label": "表示名",
|
||||
"config.nav_href": "リンク先",
|
||||
"config.nav_order": "順序",
|
||||
"config.nav_save": "ナビゲーションを保存",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,12 @@ import (
|
||||
func mergeTemplateData(
|
||||
data any,
|
||||
wikiName string,
|
||||
theme string,
|
||||
) map[string]any {
|
||||
|
||||
out := map[string]any{
|
||||
"WikiName": wikiName,
|
||||
"Theme": theme,
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
@@ -43,6 +45,7 @@ func (s *Server) render(
|
||||
mergeTemplateData(
|
||||
data,
|
||||
s.getWikiName(),
|
||||
s.getTheme(),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -139,7 +139,10 @@ func (s *Server) mustLoadTemplates() {
|
||||
return "-"
|
||||
}
|
||||
|
||||
return time.Unix(ts, 0).Format("2006-01-02 15:04")
|
||||
return time.
|
||||
Unix(ts, 0).
|
||||
In(s.getLocation()).
|
||||
Format("2006-01-02 15:04")
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package server
|
||||
|
||||
func (s *Server) getTheme() string {
|
||||
|
||||
theme, err :=
|
||||
s.store.GetConfig(
|
||||
"theme",
|
||||
)
|
||||
|
||||
if err != nil || theme == "" {
|
||||
return "dark"
|
||||
}
|
||||
|
||||
switch theme {
|
||||
case "dark", "light", "monokai", "solarized-dark", "solarized-light":
|
||||
return theme
|
||||
default:
|
||||
return "dark"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package server
|
||||
|
||||
import "time"
|
||||
|
||||
func (s *Server) getTimezoneName() string {
|
||||
|
||||
tz, err :=
|
||||
s.store.GetConfig(
|
||||
"timezone",
|
||||
)
|
||||
|
||||
if err != nil || tz == "" {
|
||||
return "UTC"
|
||||
}
|
||||
|
||||
_, err = time.LoadLocation(tz)
|
||||
|
||||
if err != nil {
|
||||
return "UTC"
|
||||
}
|
||||
|
||||
return tz
|
||||
}
|
||||
|
||||
func (s *Server) getLocation() *time.Location {
|
||||
|
||||
loc, err :=
|
||||
time.LoadLocation(
|
||||
s.getTimezoneName(),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return time.UTC
|
||||
}
|
||||
|
||||
return loc
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package server
|
||||
|
||||
import "strconv"
|
||||
|
||||
func (s *Server) getZombieGraceHours() int64 {
|
||||
|
||||
raw, err :=
|
||||
s.store.GetConfig(
|
||||
"zombie_grace_hours",
|
||||
)
|
||||
|
||||
if err != nil || raw == "" {
|
||||
return 24
|
||||
}
|
||||
|
||||
n, err :=
|
||||
strconv.ParseInt(
|
||||
raw,
|
||||
10,
|
||||
64,
|
||||
)
|
||||
|
||||
if err != nil || n < 0 {
|
||||
return 24
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func (s *Server) getZombieGraceSeconds() int64 {
|
||||
|
||||
return s.getZombieGraceHours() * 60 * 60
|
||||
}
|
||||
Reference in new issue
Block a user