Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e8936beea0 | |||
| f98df478bb | |||
| a03baca498 | |||
| 1904bfd265 | |||
| 2d488ffdcc | |||
| f4c5834f0c | |||
| db72e8fb7d | |||
| 6f93f2ff50 | |||
| 2913d510bd | |||
| 8bd2c87fc6 |
@@ -90,3 +90,4 @@ changelog:
|
|||||||
- '^docs:'
|
- '^docs:'
|
||||||
- '^test:'
|
- '^test:'
|
||||||
- '^[Bb]ump'
|
- '^[Bb]ump'
|
||||||
|
- '^[Cc]lean'
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ A self-hosted bookmark database with full-text page content search.
|
|||||||
mountpoint.
|
mountpoint.
|
||||||
* Run `docker-compose up -d`
|
* Run `docker-compose up -d`
|
||||||
|
|
||||||
|
To upgrade:
|
||||||
|
|
||||||
|
* `docker-compose pull`
|
||||||
|
* `docker-compose up -d`
|
||||||
|
|
||||||
## Packages (deb/rpm)
|
## Packages (deb/rpm)
|
||||||
|
|
||||||
* Download the .deb or .rpm from the releases
|
* Download the .deb or .rpm from the releases
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -100,7 +101,6 @@ func (m *BookmarkManager) SaveBookmark(bm *entity.Bookmark) error {
|
|||||||
func (m *BookmarkManager) LoadBookmarkByID(id uint64) entity.Bookmark {
|
func (m *BookmarkManager) LoadBookmarkByID(id uint64) entity.Bookmark {
|
||||||
// log.Printf("loading %v", ids)
|
// log.Printf("loading %v", ids)
|
||||||
ret := entity.Bookmark{}
|
ret := entity.Bookmark{}
|
||||||
log.Printf("loading id %d", id)
|
|
||||||
err := m.db.store.Get(id, &ret)
|
err := m.db.store.Get(id, &ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -207,7 +207,6 @@ func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
|
|||||||
func (m *BookmarkManager) UpdateIndexForBookmark(bm *entity.Bookmark) {
|
func (m *BookmarkManager) UpdateIndexForBookmark(bm *entity.Bookmark) {
|
||||||
words := content.Words(bm)
|
words := content.Words(bm)
|
||||||
words = append(words, bm.Tags...)
|
words = append(words, bm.Tags...)
|
||||||
log.Printf("index for %d %s (%d words)", bm.ID, bm.URL, len(words))
|
|
||||||
m.db.UpdateIndexForWordsByID(words, bm.ID)
|
m.db.UpdateIndexForWordsByID(words, bm.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,3 +280,18 @@ func (m *BookmarkManager) UpdateContent() {
|
|||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *BookmarkManager) Stats() (entity.DBStats, error) {
|
||||||
|
stats := entity.DBStats{}
|
||||||
|
err := m.db.store.Get("stats", &stats)
|
||||||
|
if err != nil && err != bolthold.ErrNotFound {
|
||||||
|
return stats, fmt.Errorf("could not load stats: %s", err)
|
||||||
|
}
|
||||||
|
// get the DB size
|
||||||
|
fi, err := os.Stat(m.db.file)
|
||||||
|
if err != nil {
|
||||||
|
return stats, fmt.Errorf("could not load db file size: %s", err)
|
||||||
|
}
|
||||||
|
stats.FileSize = int(fi.Size())
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
|||||||
2
db/db.go
2
db/db.go
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
store *bolthold.Store
|
store *bolthold.Store
|
||||||
|
file string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) Open(path string) error {
|
func (db *DB) Open(path string) error {
|
||||||
@@ -21,6 +22,7 @@ func (db *DB) Open(path string) error {
|
|||||||
return fmt.Errorf("cannot open '%s' - %s", path, err)
|
return fmt.Errorf("cannot open '%s' - %s", path, err)
|
||||||
}
|
}
|
||||||
db.store = store
|
db.store = store
|
||||||
|
db.file = path
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
type DBStats struct {
|
type DBStats struct {
|
||||||
History map[time.Time]BookmarkInfo
|
History map[time.Time]BookmarkInfo
|
||||||
|
FileSize int
|
||||||
Searches int
|
Searches int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,3 +33,16 @@ func (stats DBStats) String() string {
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (stats DBStats) MostRecentBookmarkInfo() BookmarkInfo {
|
||||||
|
mostRecent := time.Time{}
|
||||||
|
for k := range stats.History {
|
||||||
|
if k.After(mostRecent) {
|
||||||
|
mostRecent = k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !mostRecent.IsZero() {
|
||||||
|
return stats.History[mostRecent]
|
||||||
|
}
|
||||||
|
return BookmarkInfo{}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ func MemInfo() string {
|
|||||||
stats := runtime.MemStats{}
|
stats := runtime.MemStats{}
|
||||||
runtime.ReadMemStats(&stats)
|
runtime.ReadMemStats(&stats)
|
||||||
|
|
||||||
return fmt.Sprintf("%.3fMb", float64(stats.Alloc)/1024.0/1024.0)
|
return fmt.Sprintf("%.1fMb", float64(stats.Alloc)/1024.0/1024.0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Tag = "v0.0.30"
|
const Tag = "v0.0.33"
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
Local struct {
|
Local struct {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<div class="top-bar-right">
|
<div class="top-bar-right">
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
<li>
|
<li>
|
||||||
<a href="/releaseinfo">{{ version.Local.Tag }}
|
<a href="/info">{{ version.Local.Tag }}
|
||||||
{{ if version.UpgradeAvailable }}
|
{{ if version.UpgradeAvailable }}
|
||||||
❗
|
❗
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@@ -63,8 +63,8 @@
|
|||||||
{{ template "config.html" . }}
|
{{ template "config.html" . }}
|
||||||
{{ else if eq .page "edit" }}
|
{{ else if eq .page "edit" }}
|
||||||
{{ template "edit.html" . }}
|
{{ template "edit.html" . }}
|
||||||
{{ else if eq .page "releaseinfo" }}
|
{{ else if eq .page "info" }}
|
||||||
{{ template "release_info.html" . }}
|
{{ template "info.html" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{/* template "foundation_sample.html" . */}}
|
{{/* template "foundation_sample.html" . */}}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,7 +30,10 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<p>
|
<p>
|
||||||
<button type="button" hx-confirm="Delete this bookmark permanently?" hx-delete="/edit/{{.bookmark.ID}}" class="alert button">delete</button>
|
<button type="button" hx-confirm="Delete this bookmark permanently?" hx-delete="/edit/{{.bookmark.ID}}" class="alert button">Delete</button>
|
||||||
<button type="button" class="button" hx-post="/edit/{{.bookmark.ID}}">save</button>
|
<button type="button" class="button" hx-indicator="#saving" hx-post="/edit/{{.bookmark.ID}}"> {{ if .saved }} Saved {{ else }} Save {{ end }}</button>
|
||||||
|
<span id="saving" class="htmx-indicator">
|
||||||
|
<img style="height:1em;" src="/assets/image/beating.gif" /> Saving...
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
<div class="grid-x grid-padding-x">
|
<div class="grid-x grid-padding-x">
|
||||||
<div class="large-12 cell">
|
<div class="large-6 medium-12 cell">
|
||||||
|
|
||||||
<h5>Memory Usage</h5>
|
<h5>System information</h5>
|
||||||
<p>{{ meminfo }}</p>
|
<table>
|
||||||
|
<tr><th>Memory in use</th><td>{{ meminfo }}</td></tr>
|
||||||
|
<tr><th>Database disk size</th><td>{{ niceSizeMB .stats.FileSize }}Mb</td></tr>
|
||||||
|
<tr><th>Bookmarks</th><td>{{ .stats.MostRecentBookmarkInfo.Bookmarks }}</td></tr>
|
||||||
|
<tr><th>Words in index</th><td>{{ .stats.MostRecentBookmarkInfo.IndexedWords }}</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="large-6 medium-12 cell">
|
||||||
|
|
||||||
<h5>Release info</h5>
|
<h5>Release info</h5>
|
||||||
{{ if not version.Remote.Valid }}
|
{{ if not version.Remote.Valid }}
|
||||||
18
web/web.go
18
web/web.go
@@ -81,6 +81,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
template.FuncMap{
|
template.FuncMap{
|
||||||
"nicetime": niceTime,
|
"nicetime": niceTime,
|
||||||
"niceURL": niceURL,
|
"niceURL": niceURL,
|
||||||
|
"niceSizeMB": func(s int) string { return fmt.Sprintf("%.1f", float32(s)/1024/1024) },
|
||||||
"join": strings.Join,
|
"join": strings.Join,
|
||||||
"version": func() *version.Info { return &version.VersionInfo },
|
"version": func() *version.Info { return &version.VersionInfo },
|
||||||
"meminfo": meta.MemInfo,
|
"meminfo": meta.MemInfo,
|
||||||
@@ -187,6 +188,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
r.POST("/search", func(c *gin.Context) {
|
r.POST("/search", func(c *gin.Context) {
|
||||||
query := c.PostForm("query")
|
query := c.PostForm("query")
|
||||||
|
|
||||||
|
// no query, return an empty response
|
||||||
|
if len(query) == 0 {
|
||||||
|
c.Status(http.StatusNoContent)
|
||||||
|
c.Writer.Write([]byte{})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sr, err := bmm.Search(db.SearchOptions{Query: query})
|
sr, err := bmm.Search(db.SearchOptions{Query: query})
|
||||||
data := gin.H{
|
data := gin.H{
|
||||||
"results": sr,
|
"results": sr,
|
||||||
@@ -371,7 +379,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
bmm.SaveBookmark(&bookmark)
|
bmm.SaveBookmark(&bookmark)
|
||||||
bmm.UpdateIndexForBookmark(&bookmark) // because title may have changed
|
bmm.UpdateIndexForBookmark(&bookmark) // because title may have changed
|
||||||
|
|
||||||
meta := gin.H{"page": "edit", "bookmark": bookmark, "tw": gin.H{"tags": bookmark.Tags, "tags_hidden": strings.Join(bookmark.Tags, "|")}}
|
meta := gin.H{"page": "edit", "bookmark": bookmark, "saved": true, "tw": gin.H{"tags": bookmark.Tags, "tags_hidden": strings.Join(bookmark.Tags, "|")}}
|
||||||
|
|
||||||
c.HTML(http.StatusOK,
|
c.HTML(http.StatusOK,
|
||||||
"edit_form.html", meta,
|
"edit_form.html", meta,
|
||||||
@@ -396,8 +404,12 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/releaseinfo", func(c *gin.Context) {
|
r.GET("/info", func(c *gin.Context) {
|
||||||
meta := gin.H{"page": "releaseinfo", "config": config}
|
dbStats, err := bmm.Stats()
|
||||||
|
if err != nil {
|
||||||
|
panic("could not load stats for info page")
|
||||||
|
}
|
||||||
|
meta := gin.H{"page": "info", "stats": dbStats, "config": config}
|
||||||
c.HTML(http.StatusOK,
|
c.HTML(http.StatusOK,
|
||||||
"_layout.html", meta,
|
"_layout.html", meta,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user