19 Commits

Author SHA1 Message Date
c5957e38db Bump version 2022-08-20 12:16:08 +09:30
5be599589a Show memory usage on the version page 2022-08-20 12:14:52 +09:30
da970239a5 Improve notification for a new version, show release notes 2022-07-03 12:12:32 +09:30
451335e17d Capture release notes of all versions above currently running one 2022-06-10 13:17:00 +09:30
6175c77478 Bump version 2022-06-10 11:24:29 +09:30
742f42115f Add error checking for URL validity 2022-06-10 11:23:55 +09:30
9e7914c9a1 Space cells so that tags do not go on a new row. 2022-06-10 11:14:21 +09:30
fe9d8e71f4 Bump version 2022-06-09 20:21:45 +09:30
0c3bf0701d Don't panic if we cannot fetch current version from github 2022-06-09 20:20:31 +09:30
0bc777c6f1 Bump version 2022-06-09 19:56:21 +09:30
2055bba5f0 Capture tag if URL added before tag submission, allow for tags to be comma separated. 2022-06-09 19:51:21 +09:30
a2a1f9c06d Fix some element positioning 2022-06-09 19:38:30 +09:30
79280135a1 Bump version 2022-06-07 20:00:12 +09:30
4422f3840e Fix bug where column headings were displayed incorrectly on small screens 2022-06-07 19:59:33 +09:30
ffcf7c0438 Bump version 2022-06-07 19:52:35 +09:30
a910aac946 Add reversible column sorting, with sort direction indicators 2022-06-07 19:51:56 +09:30
eed41aebbb Neaten the formatting of durations 2022-06-07 16:45:03 +09:30
037be4d7e8 Bump version 2022-06-07 16:26:39 +09:30
6cf327226d Add basic sorting to management interface 2022-06-07 16:25:45 +09:30
15 changed files with 226 additions and 59 deletions

View File

@@ -30,12 +30,12 @@ func main() {
go func() {
for {
version.UpdateVersionInfo()
version.VersionInfo.UpdateVersionInfo()
time.Sleep(time.Hour * 6)
}
}()
log.Printf("linkwallet version %s starting", version.Is())
log.Printf("linkwallet version %s starting", version.VersionInfo.Local.Tag)
server := web.Create(bmm, cmm)
go bmm.RunQueue()

View File

@@ -1,9 +1,11 @@
package db
import (
"errors"
"fmt"
"io"
"log"
"strings"
"sync"
"time"
@@ -21,6 +23,7 @@ type BookmarkManager struct {
type SearchOptions struct {
Query string
Tags []string
Sort string
}
func NewBookmarkManager(db *DB) *BookmarkManager {
@@ -31,6 +34,12 @@ func NewBookmarkManager(db *DB) *BookmarkManager {
// if this bookmark already exists (based on URL match).
// The entity.Bookmark ID field will be updated.
func (m *BookmarkManager) AddBookmark(bm *entity.Bookmark) error {
if strings.Index(bm.URL, "https://") != 0 &&
strings.Index(bm.URL, "http://") != 0 {
return errors.New("URL must begin with http:// or https://")
}
existing := entity.Bookmark{}
err := m.db.store.FindOne(&existing, bolthold.Where("URL").Eq(bm.URL))
if err != bolthold.ErrNotFound {
@@ -138,10 +147,32 @@ func (m *BookmarkManager) Search(opts SearchOptions) ([]entity.Bookmark, error)
bhQuery = bolthold.Query(*bhQuery.And("Tags").ContainsAll(bolthold.Slice(opts.Tags)...))
}
reverse := false
sortOrder := opts.Sort
if sortOrder != "" && sortOrder[0] == '-' {
reverse = true
sortOrder = sortOrder[1:]
}
if sortOrder == "title" {
bhQuery.SortBy("Info.Title")
} else if sortOrder == "created" {
bhQuery.SortBy("TimestampCreated")
} else if sortOrder == "scraped" {
bhQuery.SortBy("TimestampLastScraped")
} else {
bhQuery.SortBy("ID")
}
if reverse {
bhQuery = *bhQuery.Reverse()
}
out := []entity.Bookmark{}
err := m.db.store.ForEach(&bhQuery,
func(bm *entity.Bookmark) error {
out = append(out, *bm)
return nil
})
if err != nil {

1
go.mod
View File

@@ -37,6 +37,7 @@ require (
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb
github.com/google/go-github/v44 v44.1.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/kennygrant/sanitize v1.2.4 // indirect

2
go.sum
View File

@@ -38,6 +38,8 @@ github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb h1:5b/eFaSaKPFG9ygDBaPKkydKU5nFJYk08g9jPIVogMg=
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=

14
meta/meta.go Normal file
View File

@@ -0,0 +1,14 @@
package meta
import (
"fmt"
"runtime"
)
func MemInfo() string {
stats := runtime.MemStats{}
runtime.ReadMemStats(&stats)
return fmt.Sprintf("%.3fMb", float64(stats.Alloc)/1024.0/1024.0)
}

View File

@@ -2,15 +2,17 @@ package version
import (
"context"
"fmt"
"strings"
"sync"
"github.com/google/go-github/v44/github"
"golang.org/x/mod/semver"
)
const Tag = "v0.0.21"
const Tag = "v0.0.29"
var versionInfo struct {
type Info struct {
Local struct {
Tag string
}
@@ -18,51 +20,58 @@ var versionInfo struct {
Valid bool
Tag string
}
m sync.Mutex
UpgradeReleaseNotes string
m sync.Mutex
}
var VersionInfo Info
func init() {
versionInfo.Remote.Valid = false
versionInfo.Local.Tag = Tag
VersionInfo.Remote.Valid = false
VersionInfo.Local.Tag = Tag
}
func Is() string {
return versionInfo.Local.Tag
}
func UpgradeAvailable() (bool, string) {
versionInfo.m.Lock()
defer versionInfo.m.Unlock()
if !versionInfo.Remote.Valid {
return false, ""
func (vi *Info) UpgradeAvailable() bool {
vi.m.Lock()
defer vi.m.Unlock()
if !vi.Remote.Valid {
return false
}
if semver.Compare(versionInfo.Local.Tag, versionInfo.Remote.Tag) < 0 {
return true, versionInfo.Remote.Tag
if semver.Compare(vi.Local.Tag, vi.Remote.Tag) < 0 {
return true
}
return false, ""
return false
}
func UpgradeAvailableString() string {
upgrade, ver := UpgradeAvailable()
if upgrade {
return ver
}
return ""
}
func UpdateVersionInfo() {
func (vi *Info) UpdateVersionInfo() {
client := github.NewClient(nil)
rels, _, err := client.Repositories.ListReleases(context.Background(), "tardisx", "linkwallet", nil)
if err != nil {
panic(err)
return
}
if len(rels) == 0 {
return
}
versionInfo.m.Lock()
versionInfo.Remote.Tag = *rels[0].TagName
versionInfo.Remote.Valid = true
versionInfo.m.Unlock()
vi.m.Lock()
vi.Remote.Tag = *rels[0].TagName
vi.Remote.Valid = true
vi.UpgradeReleaseNotes = ""
for _, r := range rels {
if semver.Compare(VersionInfo.Local.Tag, *r.TagName) < 0 {
vi.UpgradeReleaseNotes += fmt.Sprintf("*Version %s*\n\n", *r.TagName)
bodyLines := strings.Split(*r.Body, "\n")
for _, l := range bodyLines {
if strings.Index(l, "#") == 0 && strings.Contains(l, "Changelog") {
// do nothing, ignore the changelog heading
} else {
vi.UpgradeReleaseNotes += l + "\n"
}
}
}
}
vi.m.Unlock()
}

View File

@@ -34,13 +34,12 @@
</div>
<div class="top-bar-right">
<ul class="menu">
{{ if newVersion }}
<li>
<div><a href="https://github.com/tardisx/linkwallet/releases/tag/{{ newVersion }}">{{ newVersion }} available</a></div>
</li>
{{ end }}
<li class="menu-text">
{{ version }}
<a href="/releaseinfo">{{ version.Local.Tag }}
{{ if version.UpgradeAvailable }}
{{ end }}
</a>
</li>
<li>
<a href="https://github.com/tardisx/linkwallet">
@@ -64,6 +63,8 @@
{{ template "config.html" . }}
{{ else if eq .page "edit" }}
{{ template "edit.html" . }}
{{ else if eq .page "releaseinfo" }}
{{ template "release_info.html" . }}
{{ end }}
{{/* template "foundation_sample.html" . */}}
</div>

View File

@@ -1,24 +1,24 @@
<div class="large-8 medium-8 cell" id="add-url-form" >
<div>
<h5 style="display:inline-block;">Add a new URL</h5>
<p style="display:inline-block;">[<a hx-get="/bulk_add" hx-target="#add-url-form" href="#">bulk add</a>]</h5>
<div style="display:inline-block;">[<a hx-get="/bulk_add" hx-swap="outerHTML" hx-target="#add-url-form" href="#">bulk add</a>]</div></h5>
</div>
<form onsubmit="return false">
<div class="grid-x grid-padding-x">
<div class="large-6 cell">
<div class="medium-6 cell">
<label>URL</label>
<input type="text" name="url" value="{{ .url }}"
hx-trigger=""
/>
</div>
<div class="large-6 cell">
<div class="medium-6 cell">
{{ template "tags_widget.html" . }}
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="medium-6 cell">
<a href="#" class="button" hx-post="/add"
<a href="#" class="button" hx-post="/add"
hx-target="#add-url-form">add</a>
</div>
</div>

View File

@@ -1,14 +1,13 @@
<div class="large-8 medium-8 cell" id="add-url-form" >
<div>
<h5 style="display:inline-block;">Add bulk URLs</h5>
<p style="display:inline-block;">[<a hx-get="/single_add" hx-target="#add-url-form" href="#">single add</a>]</h5>
</div> <form onsubmit="return false">
<p style="display:inline-block;">[<a hx-get="/single_add" hx-swap="outerHTML" hx-target="#add-url-form" href="#">single add</a>]</h5>
</div>
<form onsubmit="return false">
<div class="grid-x grid-padding-x">
<div class="large-12 cell">
<label>Paste URL's, one per line</label>
<textarea type="text" name="urls" rows="10"
></textarea>
<textarea type="text" name="urls" rows="10"></textarea>
</div>
</div>
<button

View File

@@ -13,8 +13,9 @@
</div>
</div>
{{ template "tags_widget.html" . }}
{{ template "manage_results.html" . }}
</form>
{{ template "manage_results.html" . }}
</div>
</div>

View File

@@ -2,10 +2,10 @@
<table id="manage-results">
<tr>
<th>&nbsp;</th>
<th>title/url</th>
{{ template "manage_results_column_header.html" .column.title }}
<th>tags</th>
<th class="show-for-large">created</th>
<th class="show-for-large">scraped</th>
{{ template "manage_results_column_header.html" .column.created }}
{{ template "manage_results_column_header.html" .column.scraped }}
</tr>
{{ range .bookmarks }}
<tr>

View File

@@ -0,0 +1,3 @@
<th class="{{ .Class }}" hx-post="/manage/results?sort={{ .URLString }}" hx-target="#manage-results">{{ .Name }}&nbsp;{{ .TitleArrow }}
</th>

View File

@@ -0,0 +1,26 @@
<div class="grid-x grid-padding-x">
<div class="large-12 cell">
<h5>Memory Usage</h5>
<p>{{ meminfo }}</p>
<h5>Release info</h5>
{{ if not version.Remote.Valid }}
<p>GitHub version information not yet fetched.</p>
{{ else }}
{{ if version.UpgradeAvailable }}
<p>
A new version is available:
<a href="https://github.com/tardisx/linkwallet/releases/tag/{{ version.Remote.Tag }}">
{{ version.Remote.Tag }}
</a>
(you have {{ version.Local.Tag }}).
</p>
{{ markdown version.UpgradeReleaseNotes }}
{{ else }}
<p>You are currently running the most recent version.</p>
{{ end }}
{{ end }}
</div>

View File

@@ -1,15 +1,15 @@
<div id="label-widget" >
<div class="grid-x grid-padding-x">
<div class="small-9 medium-10 large-5 cell"
<div class="small-6 cell"
hx-post="/tags"
hx-target="#label-widget"
hx-trigger="change">
hx-trigger="change queue:first">
<label for="tag-entry"
class="">Tags</label>
<input id="tag-entry" type="text" name="tag" placeholder="enter tags" />
</div>
<div class="small-12 large-6 cell" id="tags-list">
<div class="small-6 cell" id="tags-list">
{{ range .tags }}
<a href="#"
class=""

View File

@@ -14,8 +14,10 @@ import (
"github.com/tardisx/linkwallet/db"
"github.com/tardisx/linkwallet/entity"
"github.com/tardisx/linkwallet/meta"
"github.com/tardisx/linkwallet/version"
"github.com/gomarkdown/markdown"
"github.com/hako/durafmt"
"github.com/gin-contrib/gzip"
@@ -42,6 +44,29 @@ type Server struct {
bmm *db.BookmarkManager
}
type ColumnInfo struct {
Name string
Param string
Sorted string
Class string
}
func (c ColumnInfo) URLString() string {
if c.Sorted == "asc" {
return "-" + c.Param
}
return c.Param
}
func (c ColumnInfo) TitleArrow() string {
if c.Sorted == "asc" {
return "↑"
} else if c.Sorted == "desc" {
return "↓"
}
return ""
}
// Create creates a new web server instance and sets up routing.
func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
@@ -52,7 +77,15 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
}
// templ := template.Must(template.New("").Funcs(template.FuncMap{"dict": dictHelper}).ParseFS(templateFiles, "templates/*.html"))
templ := template.Must(template.New("").Funcs(template.FuncMap{"nicetime": niceTime, "niceURL": niceURL, "join": strings.Join, "version": version.Is, "newVersion": version.UpgradeAvailableString}).ParseFS(templateFiles, "templates/*.html"))
templ := template.Must(template.New("").Funcs(
template.FuncMap{
"nicetime": niceTime,
"niceURL": niceURL,
"join": strings.Join,
"version": func() *version.Info { return &version.VersionInfo },
"meminfo": meta.MemInfo,
"markdown": func(s string) template.HTML { return template.HTML(string(markdown.ToHTML([]byte(s), nil, nil))) },
}).ParseFS(templateFiles, "templates/*.html"))
config, err := cmm.LoadConfig()
if err != nil {
@@ -92,13 +125,42 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
r.POST("/manage/results", func(c *gin.Context) {
query := c.PostForm("query")
tags := []string{}
sort := c.Query("sort")
if c.PostForm("tags_hidden") != "" {
tags = strings.Split(c.PostForm("tags_hidden"), "|")
}
allBookmarks, _ := bmm.Search(db.SearchOptions{Query: query, Tags: tags})
allBookmarks, _ := bmm.Search(db.SearchOptions{Query: query, Tags: tags, Sort: sort})
meta := gin.H{"config": config, "bookmarks": allBookmarks}
log.Printf("query is %s, tags %v", query, tags)
colTitle := &ColumnInfo{Name: "Title/URL", Param: "title"}
colCreated := &ColumnInfo{Name: "Created", Param: "created", Class: "show-for-large"}
colScraped := &ColumnInfo{Name: "Scraped", Param: "scraped", Class: "show-for-large"}
if sort == "title" {
colTitle.Sorted = "asc"
}
if sort == "-title" {
colTitle.Sorted = "desc"
}
if sort == "scraped" {
colScraped.Sorted = "asc"
}
if sort == "-scraped" {
colScraped.Sorted = "desc"
}
if sort == "created" {
colCreated.Sorted = "asc"
}
if sort == "-created" {
colCreated.Sorted = "desc"
}
cols := gin.H{
"title": colTitle,
"created": colCreated,
"scraped": colScraped,
}
meta["column"] = cols
c.HTML(http.StatusOK,
"manage_results.html", meta,
@@ -153,6 +215,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
"bm": bm,
"error": err,
}
if err != nil {
data["url"] = url
data["tags"] = tags
data["tags_hidden"] = c.PostForm("tags_hidden")
}
c.HTML(http.StatusOK, "add_url_form.html", data)
})
r.POST("/add_bulk", func(c *gin.Context) {
@@ -327,6 +396,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
)
})
r.GET("/releaseinfo", func(c *gin.Context) {
meta := gin.H{"page": "releaseinfo", "config": config}
c.HTML(http.StatusOK,
"_layout.html", meta,
)
})
return server
}
@@ -350,7 +426,10 @@ func cleanupTags(tags []string) []string {
keys := make(map[string]struct{})
for _, k := range tags {
if k != "" && k != "|" {
keys[strings.ToLower(k)] = struct{}{}
for _, subKey := range strings.Split(k, ",") {
subKey := strings.Trim(subKey, " ")
keys[strings.ToLower(subKey)] = struct{}{}
}
}
}
out := []string{}
@@ -374,6 +453,7 @@ func niceTime(t time.Time) timeVariations {
panic(err)
}
ago := durafmt.Parse(time.Since(t)).LimitFirstN(1).Format(units)
ago = strings.ReplaceAll(ago, " ", "")
return timeVariations{HumanDuration: ago}
}