move packages to src
45
src/assets/assets.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
)
|
||||
|
||||
type assetsfs struct {
|
||||
embedded *embed.FS
|
||||
templates map[string]*template.Template
|
||||
}
|
||||
|
||||
var FS assetsfs
|
||||
|
||||
func (afs assetsfs) Open(name string) (fs.File, error) {
|
||||
if afs.embedded != nil {
|
||||
return afs.embedded.Open(name)
|
||||
}
|
||||
return os.DirFS("assets").Open(name)
|
||||
}
|
||||
|
||||
func Render(path string, writer io.Writer, data interface{}) {
|
||||
var tmpl *template.Template
|
||||
tmpl, found := FS.templates[path]
|
||||
if !found {
|
||||
tmpl = template.Must(template.New(path).Delims("{%", "%}").Funcs(template.FuncMap{
|
||||
"inline": func(svg string) template.HTML {
|
||||
svgfile, _ := FS.Open("graphicarts/" + svg)
|
||||
content, _ := ioutil.ReadAll(svgfile)
|
||||
svgfile.Close()
|
||||
return template.HTML(content)
|
||||
},
|
||||
}).ParseFS(FS, path))
|
||||
FS.templates[path] = tmpl
|
||||
}
|
||||
tmpl.Execute(writer, data)
|
||||
}
|
||||
|
||||
func init() {
|
||||
FS.templates = make(map[string]*template.Template)
|
||||
}
|
||||
15
src/assets/assetsfs.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// +build release
|
||||
|
||||
package assets
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed *.html
|
||||
//go:embed graphicarts
|
||||
//go:embed javascripts
|
||||
//go:embed stylesheets
|
||||
var embedded embed.FS
|
||||
|
||||
func init() {
|
||||
FS.embedded = &embedded
|
||||
}
|
||||
1
src/assets/graphicarts/alert-circle.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-alert-circle"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
|
||||
|
After Width: | Height: | Size: 356 B |
BIN
src/assets/graphicarts/anchor.png
Normal file
|
After Width: | Height: | Size: 395 B |
1
src/assets/graphicarts/anchor.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-anchor"><circle cx="12" cy="5" r="3"></circle><line x1="12" y1="22" x2="12" y2="8"></line><path d="M5 12H2a10 10 0 0 0 20 0h-3"></path></svg>
|
||||
|
After Width: | Height: | Size: 345 B |
1
src/assets/graphicarts/assorted.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-bar-chart-2"><line x1="4" y1="6" x2="14" y2="6"></line><line x1="4" y1="12" x2="20" y2="12"></line><line x1="4" y1="18" x2="8" y2="18"></line></svg>
|
||||
|
After Width: | Height: | Size: 353 B |
1
src/assets/graphicarts/book-open.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-book-open"><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"></path><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"></path></svg>
|
||||
|
After Width: | Height: | Size: 339 B |
1
src/assets/graphicarts/check.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-check"><polyline points="20 6 9 17 4 12"></polyline></svg>
|
||||
|
After Width: | Height: | Size: 262 B |
1
src/assets/graphicarts/chevron-down.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>
|
||||
|
After Width: | Height: | Size: 269 B |
1
src/assets/graphicarts/chevron-left.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-left"><polyline points="15 18 9 12 15 6"></polyline></svg>
|
||||
|
After Width: | Height: | Size: 270 B |
1
src/assets/graphicarts/chevron-right.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"></polyline></svg>
|
||||
|
After Width: | Height: | Size: 270 B |
1
src/assets/graphicarts/circle-full.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-circle"><circle cx="12" cy="12" r="10"></circle></svg>
|
||||
|
After Width: | Height: | Size: 267 B |
1
src/assets/graphicarts/circle.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-circle"><circle cx="12" cy="12" r="10"></circle></svg>
|
||||
|
After Width: | Height: | Size: 258 B |
1
src/assets/graphicarts/download.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-download"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
|
||||
|
After Width: | Height: | Size: 370 B |
1
src/assets/graphicarts/edit.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>
|
||||
|
After Width: | Height: | Size: 365 B |
1
src/assets/graphicarts/external-link.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-external-link"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>
|
||||
|
After Width: | Height: | Size: 388 B |
1
src/assets/graphicarts/folder.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-folder"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path></svg>
|
||||
|
After Width: | Height: | Size: 311 B |
BIN
src/assets/graphicarts/icon.ico
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
src/assets/graphicarts/icon.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
1
src/assets/graphicarts/layers.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-layers"><polygon points="12 2 2 7 12 12 22 7 12 2"></polygon><polyline points="2 17 12 22 22 17"></polyline><polyline points="2 12 12 17 22 12"></polyline></svg>
|
||||
|
After Width: | Height: | Size: 365 B |
1
src/assets/graphicarts/list.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-list"><line x1="8" y1="6" x2="21" y2="6"></line><line x1="8" y1="12" x2="21" y2="12"></line><line x1="8" y1="18" x2="21" y2="18"></line><line x1="3" y1="6" x2="3.01" y2="6"></line><line x1="3" y1="12" x2="3.01" y2="12"></line><line x1="3" y1="18" x2="3.01" y2="18"></line></svg>
|
||||
|
After Width: | Height: | Size: 482 B |
1
src/assets/graphicarts/log-out.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-log-out"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line></svg>
|
||||
|
After Width: | Height: | Size: 367 B |
1
src/assets/graphicarts/more-horizontal.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-more-horizontal"><circle cx="12" cy="12" r="1"></circle><circle cx="19" cy="12" r="1"></circle><circle cx="5" cy="12" r="1"></circle></svg>
|
||||
|
After Width: | Height: | Size: 343 B |
1
src/assets/graphicarts/more-vertical.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-more-vertical"><circle cx="12" cy="12" r="1"></circle><circle cx="12" cy="5" r="1"></circle><circle cx="12" cy="19" r="1"></circle></svg>
|
||||
|
After Width: | Height: | Size: 341 B |
1
src/assets/graphicarts/plus.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
|
||||
|
After Width: | Height: | Size: 304 B |
1
src/assets/graphicarts/rotate-cw.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-rotate-cw"><polyline points="23 4 23 10 17 10"></polyline><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path></svg>
|
||||
|
After Width: | Height: | Size: 321 B |
1
src/assets/graphicarts/rss.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-rss"><path d="M4 11a9 9 0 0 1 9 9"></path><path d="M4 4a16 16 0 0 1 16 16"></path><circle cx="5" cy="19" r="1"></circle></svg>
|
||||
|
After Width: | Height: | Size: 330 B |
1
src/assets/graphicarts/search.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
|
||||
|
After Width: | Height: | Size: 308 B |
1
src/assets/graphicarts/settings.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-settings"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1011 B |
1
src/assets/graphicarts/sliders.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-sliders"><line x1="4" y1="21" x2="4" y2="14"></line><line x1="4" y1="10" x2="4" y2="3"></line><line x1="12" y1="21" x2="12" y2="12"></line><line x1="12" y1="8" x2="12" y2="3"></line><line x1="20" y1="21" x2="20" y2="16"></line><line x1="20" y1="12" x2="20" y2="3"></line><line x1="1" y1="14" x2="7" y2="14"></line><line x1="9" y1="8" x2="15" y2="8"></line><line x1="17" y1="16" x2="23" y2="16"></line></svg>
|
||||
|
After Width: | Height: | Size: 611 B |
1
src/assets/graphicarts/star-full.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-star"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>
|
||||
|
After Width: | Height: | Size: 348 B |
1
src/assets/graphicarts/star.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-star"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>
|
||||
|
After Width: | Height: | Size: 339 B |
1
src/assets/graphicarts/trash-2.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
|
||||
|
After Width: | Height: | Size: 448 B |
1
src/assets/graphicarts/upload.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-upload"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg>
|
||||
|
After Width: | Height: | Size: 365 B |
1
src/assets/graphicarts/x.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
|
After Width: | Height: | Size: 299 B |
396
src/assets/index.html
Normal file
@@ -0,0 +1,396 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>yarr!</title>
|
||||
<link rel="stylesheet" href="./static/stylesheets/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="./static/stylesheets/app.css">
|
||||
<link rel="icon shortcut" href="./static/graphicarts/anchor.png">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
</head>
|
||||
<body class="theme-light">
|
||||
<div id="app" class="d-flex" :class="{'feed-selected': feedSelected !== null, 'item-selected': itemSelected !== null}" v-cloak>
|
||||
<!-- feed list -->
|
||||
<div id="col-feed-list" class="vh-100 position-relative d-flex flex-column border-right flex-shrink-0" :style="{width: feedListWidth+'px'}">
|
||||
<drag :width="feedListWidth" @resize="resizeFeedList"></drag>
|
||||
<div class="p-2 toolbar d-flex align-items-center">
|
||||
<div class="icon mx-2">{% inline "anchor.svg" %}</div>
|
||||
<div class="flex-grow-1"></div>
|
||||
<button class="toolbar-item"
|
||||
:class="{active: filterSelected == 'unread'}"
|
||||
v-b-tooltip.hover.bottom="'Unread'"
|
||||
@click="filterSelected = 'unread'">
|
||||
<span class="icon">{% inline "circle-full.svg" %}</span>
|
||||
</button>
|
||||
<button class="toolbar-item"
|
||||
:class="{active: filterSelected == 'starred'}"
|
||||
v-b-tooltip.hover.bottom="'Starred'"
|
||||
@click="filterSelected = 'starred'">
|
||||
<span class="icon">{% inline "star-full.svg" %}</span>
|
||||
</button>
|
||||
<button class="toolbar-item"
|
||||
:class="{active: filterSelected == ''}"
|
||||
v-b-tooltip.hover.bottom="'All'"
|
||||
@click="filterSelected = ''">
|
||||
<span class="icon">{% inline "assorted.svg" %}</span>
|
||||
</button>
|
||||
<div class="flex-grow-1"></div>
|
||||
<b-dropdown
|
||||
right no-caret lazy variant="link"
|
||||
class="settings-dropdown"
|
||||
toggle-class="toolbar-item px-2"
|
||||
ref="menuDropdown">
|
||||
<template v-slot:button-content class="toolbar-item">
|
||||
<span class="icon">{% inline "more-horizontal.svg" %}</span>
|
||||
</template>
|
||||
<b-dropdown-item-button @click="showSettings('create')">
|
||||
<span class="icon mr-1">{% inline "plus.svg" %}</span>
|
||||
New Feed
|
||||
</b-dropdown-item-button>
|
||||
<b-dropdown-item-button @click.stop="showSettings('manage')">
|
||||
<span class="icon mr-1">{% inline "list.svg" %}</span>
|
||||
Manage Feeds
|
||||
</b-dropdown-item-button>
|
||||
<b-dropdown-divider></b-dropdown-divider>
|
||||
<b-dropdown-item-button @click.stop="fetchAllFeeds()">
|
||||
<span class="icon mr-1">{% inline "rotate-cw.svg" %}</span>
|
||||
Refresh Feeds
|
||||
</b-dropdown-item-button>
|
||||
|
||||
<b-dropdown-divider></b-dropdown-divider>
|
||||
|
||||
<b-dropdown-header>Refresh</b-dropdown-header>
|
||||
<b-dropdown-item-button @click.stop="refreshRate = min" v-for="min in [0, 60]">
|
||||
<span class="icon mr-1" :class="{invisible: refreshRate != min}">{% inline "check.svg" %}</span>
|
||||
<span v-if="min == 0">Manually</span>
|
||||
<span v-if="min == 60">Every hour</span>
|
||||
</b-dropdown-item-button>
|
||||
|
||||
<b-dropdown-divider></b-dropdown-divider>
|
||||
|
||||
<b-dropdown-header>Sort by</b-dropdown-header>
|
||||
<b-dropdown-item-button @click.stop="itemSortNewestFirst=true">
|
||||
<span class="icon mr-1" :class="{invisible: !itemSortNewestFirst}">{% inline "check.svg" %}</span>
|
||||
Newest First
|
||||
</b-dropdown-item-button>
|
||||
<b-dropdown-item-button @click="itemSortNewestFirst=false">
|
||||
<span class="icon mr-1" :class="{invisible: itemSortNewestFirst}">{% inline "check.svg" %}</span>
|
||||
Oldest First
|
||||
</b-dropdown-item-button>
|
||||
<b-dropdown-divider></b-dropdown-divider>
|
||||
<b-dropdown-header>Subscriptions</b-dropdown-header>
|
||||
<b-dropdown-form id="opml-import-form" enctype="multipart/form-data">
|
||||
<input type="file"
|
||||
id="opml-import"
|
||||
@change="importOPML"
|
||||
name="opml"
|
||||
style="opacity: 0; width: 1px; height: 0; position: absolute; z-index: -1;">
|
||||
<label class="dropdown-item mb-0 cursor-pointer" for="opml-import">
|
||||
<span class="icon mr-1">{% inline "download.svg" %}</span>
|
||||
Import
|
||||
</label>
|
||||
</b-dropdown-form>
|
||||
<b-dropdown-item href="./opml/export">
|
||||
<span class="icon mr-1">{% inline "upload.svg" %}</span>
|
||||
Export
|
||||
</b-dropdown-item>
|
||||
<b-dropdown-divider v-if="authenticated"></b-dropdown-divider>
|
||||
<b-dropdown-item-button v-if="authenticated" @click="logout()">
|
||||
<span class="icon mr-1">{% inline "log-out.svg" %}</span>
|
||||
Log out
|
||||
</b-dropdown-item-button>
|
||||
</b-dropdown>
|
||||
</div>
|
||||
<div class="p-2 overflow-auto border-top flex-grow-1">
|
||||
<label class="selectgroup">
|
||||
<input type="radio" name="feed" value="" v-model="feedSelected">
|
||||
<div class="selectgroup-label d-flex align-items-center w-100">
|
||||
<span class="icon mr-2">{% inline "layers.svg" %}</span>
|
||||
<span class="flex-fill text-left text-truncate" v-if="filterSelected=='unread'">All Unread</span>
|
||||
<span class="flex-fill text-left text-truncate" v-if="filterSelected=='starred'">All Starred</span>
|
||||
<span class="flex-fill text-left text-truncate" v-if="filterSelected==''">All Feeds</span>
|
||||
<span class="counter text-right">{{ filteredTotalStats }}</span>
|
||||
</div>
|
||||
</label>
|
||||
<div v-for="folder in foldersWithFeeds">
|
||||
<label class="selectgroup mt-1"
|
||||
:class="{'d-none': filterSelected
|
||||
&& !filteredFolderStats[folder.id]
|
||||
&& (!itemSelected || feedsById[itemSelectedDetails.feed_id].folder_id != folder.id)}">
|
||||
<input type="radio" name="feed" :value="'folder:'+folder.id" v-model="feedSelected">
|
||||
<div class="selectgroup-label d-flex align-items-center w-100" v-if="folder.id">
|
||||
<span class="icon mr-2"
|
||||
:class="{expanded: folder.is_expanded}"
|
||||
@click.prevent="toggleFolderExpanded(folder)">
|
||||
{% inline "chevron-right.svg" %}
|
||||
</span>
|
||||
<span class="flex-fill text-left text-truncate">{{ folder.title }}</span>
|
||||
<span class="counter text-right">{{ filteredFolderStats[folder.id] || '' }}</span>
|
||||
</div>
|
||||
</label>
|
||||
<div v-show="!folder.id || folder.is_expanded" class="mt-1" :class="{'pl-3': folder.id}">
|
||||
<label class="selectgroup"
|
||||
:class="{'d-none': filterSelected
|
||||
&& !filteredFeedStats[feed.id]
|
||||
&& (!itemSelected || itemSelectedDetails.feed_id != feed.id)}"
|
||||
v-for="feed in folder.feeds">
|
||||
<input type="radio" name="feed" :value="'feed:'+feed.id" v-model="feedSelected">
|
||||
<div class="selectgroup-label d-flex align-items-center w-100">
|
||||
<span class="icon mr-2" v-if="!feed.has_icon">{% inline "rss.svg" %}</span>
|
||||
<span class="icon mr-2" v-else><img v-lazy="'./api/feeds/'+feed.id+'/icon'" alt=""></span>
|
||||
<span class="flex-fill text-left text-truncate">{{ feed.title }}</span>
|
||||
<span class="counter text-right">{{ filteredFeedStats[feed.id] || '' }}</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-2 toolbar d-flex align-items-center border-top flex-shrink-0" v-if="loading.feeds">
|
||||
<span class="icon loading mx-2"></span>
|
||||
<span class="text-truncate cursor-default noselect">Refreshing ({{ loading.feeds }} left)</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- item list -->
|
||||
<div id="col-item-list" class="vh-100 position-relative d-flex flex-column border-right flex-shrink-0" :style="{width: itemListWidth+'px'}">
|
||||
<drag :width="itemListWidth" @resize="resizeItemList"></drag>
|
||||
<div class="px-2 toolbar d-flex align-items-center">
|
||||
<button class="toolbar-item mr-2 d-block d-md-none"
|
||||
@click="feedSelected = null"
|
||||
v-b-tooltip.hover.bottom="'Show Feeds'">
|
||||
<span class="icon">{% inline "chevron-left.svg" %}</span>
|
||||
</button>
|
||||
<div class="input-icon flex-grow-1">
|
||||
<span class="icon">{% inline "search.svg" %}</span>
|
||||
<input class="d-block toolbar-search" type="" v-model="itemSearch">
|
||||
</div>
|
||||
<button class="toolbar-item ml-2"
|
||||
@click="markItemsRead()"
|
||||
v-if="filterSelected == 'unread'"
|
||||
v-b-tooltip.hover.bottom="'Mark All Read'">
|
||||
<span class="icon">{% inline "check.svg" %}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="p-2 overflow-auto border-top flex-grow-1" v-scroll="loadMoreItems" ref="itemlist">
|
||||
<label v-for="item in items" :key="item.id"
|
||||
class="selectgroup">
|
||||
<input type="radio" name="item" :value="item.id" v-model="itemSelected">
|
||||
<div class="selectgroup-label d-flex flex-column">
|
||||
<div style="line-height: 1; opacity: .7; margin-bottom: .1rem;" class="d-flex align-items-center">
|
||||
<transition name="indicator">
|
||||
<span class="icon icon-small mr-1" v-if="item.status=='unread'">{% inline "circle-full.svg" %}</span>
|
||||
<span class="icon icon-small mr-1" v-if="item.status=='starred'">{% inline "star-full.svg" %}</span>
|
||||
</transition>
|
||||
<small class="flex-fill text-truncate mr-1">
|
||||
{{ feedsById[item.feed_id].title }}
|
||||
</small>
|
||||
<small class="flex-shrink-0"><relative-time :val="item.date"/></small>
|
||||
</div>
|
||||
<div>{{ item.title || 'untitled' }}</div>
|
||||
</div>
|
||||
</label>
|
||||
<button class="btn btn-link btn-block loading my-3" v-if="itemsPage.cur < itemsPage.num"></button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- item show -->
|
||||
<div id="col-item" class="vh-100 d-flex flex-column w-100" style="min-width: 0;">
|
||||
<div class="toolbar px-2 d-flex align-items-center" v-if="itemSelected">
|
||||
<button class="toolbar-item"
|
||||
@click="toggleItemStarred(itemSelectedDetails)"
|
||||
v-b-tooltip.hover.bottom="'Mark Starred'">
|
||||
<span class="icon" v-if="itemSelectedDetails.status=='starred'" >{% inline "star-full.svg" %}</span>
|
||||
<span class="icon" v-else-if="itemSelectedDetails.status!='starred'" >{% inline "star.svg" %}</span>
|
||||
</button>
|
||||
<button class="toolbar-item"
|
||||
:disabled="itemSelectedDetails.status=='starred'"
|
||||
v-b-tooltip.hover.bottom="'Mark Unread'"
|
||||
@click="toggleItemRead(itemSelectedDetails)">
|
||||
<span class="icon" v-if="itemSelectedDetails.status=='unread'">{% inline "circle-full.svg" %}</span>
|
||||
<span class="icon" v-if="itemSelectedDetails.status!='unread'">{% inline "circle.svg" %}</span>
|
||||
</button>
|
||||
<a class="toolbar-item" id="content-appearance" v-b-tooltip.hover.bottom="'Appearance'" tabindex="0">
|
||||
<span class="icon">{% inline "sliders.svg" %}</span>
|
||||
</a>
|
||||
<button class="toolbar-item"
|
||||
:class="{active: itemSelectedReadability}"
|
||||
@click="getReadable(itemSelectedDetails)"
|
||||
v-b-tooltip.hover.bottom="'Read Here'">
|
||||
<span class="icon" :class="{'icon-loading': loading.readability}">{% inline "book-open.svg" %}</span>
|
||||
</button>
|
||||
<a class="toolbar-item" :href="itemSelectedDetails.link" target="_blank" v-b-tooltip.hover.bottom="'Open Link'">
|
||||
<span class="icon">{% inline "external-link.svg" %}</span>
|
||||
</a>
|
||||
<b-popover target="content-appearance" triggers="focus" placement="bottom">
|
||||
<div class="p-1" style="width: 200px;">
|
||||
<div class="d-flex">
|
||||
<label class="themepicker">
|
||||
<input type="radio" name="settingsTheme" value="light" v-model="theme.name">
|
||||
<div class="themepicker-label appearance-option"></div>
|
||||
</label>
|
||||
<label class="themepicker">
|
||||
<input type="radio" name="settingsTheme" value="sepia" v-model="theme.name">
|
||||
<div class="themepicker-label appearance-option"></div>
|
||||
</label>
|
||||
<label class="themepicker">
|
||||
<input type="radio" name="settingsTheme" value="night" v-model="theme.name">
|
||||
<div class="themepicker-label appearance-option"></div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="selectgroup">
|
||||
<input type="radio" name="font" value="" v-model="theme.font">
|
||||
<div class="selectgroup-label appearance-option">
|
||||
System Default
|
||||
</div>
|
||||
</label>
|
||||
<label class="selectgroup" v-for="f in fonts" :key="f">
|
||||
<input type="radio" name="font" :value="f" v-model="theme.font">
|
||||
<div class="selectgroup-label appearance-option":style="{'font-family': f}">
|
||||
{{ f }}
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="btn-group d-flex mt-2">
|
||||
<button class="btn btn-outline appearance-option"
|
||||
style="font-size: 0.8rem" @click="incrFont(-1)">A</button>
|
||||
<button class="btn btn-outline appearance-option"
|
||||
style="font-size: 1.2rem" @click="incrFont(1)">A</button>
|
||||
</div>
|
||||
</div>
|
||||
</b-popover>
|
||||
<div class="flex-grow-1"></div>
|
||||
<button class="toolbar-item" @click="itemSelected=null" v-b-tooltip.hover.bottom="'Close Article'">
|
||||
<span class="icon">{% inline "x.svg" %}</span>
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="itemSelected"
|
||||
ref="content"
|
||||
class="content px-4 pt-3 pb-5 border-top overflow-auto"
|
||||
:style="{'font-family': theme.font, 'font-size': theme.size + 'rem'}">
|
||||
<h1><b>{{ itemSelectedDetails.title }}</b></h1>
|
||||
<div class="text-muted">
|
||||
<div>{{ feedsById[itemSelectedDetails.feed_id].title }}</div>
|
||||
<time>{{ formatDate(itemSelectedDetails.date) }}</time>
|
||||
</div>
|
||||
<hr>
|
||||
<div v-html="itemSelectedContent"></div>
|
||||
</div>
|
||||
</div>
|
||||
<b-modal id="settings-modal" hide-header hide-footer lazy>
|
||||
<button class="btn btn-link outline-none float-right p-2 mr-n2 mt-n2" style="line-height: 1" @click="$bvModal.hide('settings-modal')">
|
||||
<span class="icon">{% inline "x.svg" %}</span>
|
||||
</button>
|
||||
<div v-if="settings=='create'">
|
||||
<p class="cursor-default"><b>New Feed</b></p>
|
||||
<form action="" @submit.prevent="createFeed(event)" class="mt-4">
|
||||
<label for="feed-url">URL</label>
|
||||
<input id="feed-url" name="url" type="url" class="form-control" required autocomplete="off" :readonly="feedNewChoice.length > 0">
|
||||
<label for="feed-folder" class="mt-3 d-block">
|
||||
Folder
|
||||
<a href="#" class="float-right text-decoration-none" @click.prevent="createNewFeedFolder()">new folder</a>
|
||||
</label>
|
||||
<select class="form-control" id="feed-folder" name="folder_id" ref="newFeedFolder">
|
||||
<option value="">---</option>
|
||||
<option :value="folder.id" v-for="folder in folders">{{ folder.title }}</option>
|
||||
</select>
|
||||
<div class="mt-4" v-if="feedNewChoice.length">
|
||||
<p class="mb-2">
|
||||
Multiple feeds found. Choose one below:
|
||||
<a href="#" class="float-right text-decoration-none" @click.prevent="resetFeedChoice()">cancel</a>
|
||||
</p>
|
||||
<label class="selectgroup" v-for="choice in feedNewChoice">
|
||||
<input type="radio" name="feedToAdd" :value="choice.url" v-model="feedNewChoiceSelected">
|
||||
<div class="selectgroup-label">
|
||||
<div class="text-truncate">{{ choice.title }}</div>
|
||||
<div class="text-truncate" :class="{light: choice.title}">{{ choice.url }}</div>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<button class="btn btn-block btn-default mt-3" :class="{loading: loading.newfeed}" type="submit">Add</button>
|
||||
</form>
|
||||
</div>
|
||||
<div v-else-if="settings=='manage'">
|
||||
<p class="cursor-default"><b>Manage Feeds</b></p>
|
||||
<div v-for="folder in foldersWithFeeds" class="mt-4" :key="folder.id">
|
||||
<div class="list-row d-flex align-items-center">
|
||||
<div class="w-100 text-truncate" v-if="folder.id">
|
||||
<span class="icon mr-2">{% inline "folder.svg" %}</span>
|
||||
{{ folder.title }}
|
||||
</div>
|
||||
<div class="flex-shrink-0" v-if="folder.id">
|
||||
<b-dropdown right no-caret lazy variant="link" class="settings-dropdown" toggle-class="text-decoration-none">
|
||||
<template v-slot:button-content>
|
||||
<span class="icon">{% inline "more-vertical.svg" %}</span>
|
||||
</template>
|
||||
<b-dropdown-header>{{ folder.title }}</b-dropdown-header>
|
||||
<b-dropdown-item @click.prevent="renameFolder(folder)">Rename</b-dropdown-item>
|
||||
<b-dropdown-divider></b-dropdown-divider>
|
||||
<b-dropdown-item class="dropdown-danger"
|
||||
@click.prevent="deleteFolder(folder)">
|
||||
Delete
|
||||
</b-dropdown-item>
|
||||
</b-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
<div v-for="feed in folder.feeds" class="list-row d-flex align-items-center" :key="feed.id">
|
||||
<div class="w-100 text-truncate">
|
||||
<span class="icon mr-2" v-if="!feed.has_icon">{% inline "rss.svg" %}</span>
|
||||
<span class="icon mr-2" v-else><img v-lazy="'./api/feeds/'+feed.id+'/icon'" alt=""></span>
|
||||
{{ feed.title }}
|
||||
</div>
|
||||
<span class="icon flex-shrink-0 mx-2"
|
||||
v-b-tooltip.hover.top="feed_errors[feed.id]"
|
||||
v-if="feed_errors[feed.id]">
|
||||
{% inline "alert-circle.svg" %}
|
||||
</span>
|
||||
<div class="flex-shrink-0">
|
||||
<b-dropdown right no-caret lazy variant="link" class="settings-dropdown" toggle-class="text-decoration-none">
|
||||
<template v-slot:button-content>
|
||||
<span class="icon">{% inline "more-vertical.svg" %}</span>
|
||||
</template>
|
||||
<b-dropdown-header>{{ feed.title }}</b-dropdown-header>
|
||||
<b-dropdown-item :href="feed.link" target="_blank" v-if="feed.link">Visit Website</b-dropdown-item>
|
||||
<b-dropdown-divider v-if="feed.link"></b-dropdown-divider>
|
||||
<b-dropdown-item @click.prevent="renameFeed(feed)">Rename</b-dropdown-item>
|
||||
<b-dropdown-divider v-if="folders.length"></b-dropdown-divider>
|
||||
<b-dropdown-header v-if="folders.length">Move to...</b-dropdown-header>
|
||||
<b-dropdown-item @click="moveFeed(feed, null)" v-if="feed.folder_id">
|
||||
---
|
||||
</b-dropdown-item>
|
||||
<b-dropdown-item-button
|
||||
v-if="folder.id != feed.folder_id"
|
||||
v-for="folder in folders"
|
||||
@click="moveFeed(feed, folder)">
|
||||
<span class="icon mr-1">{% inline "folder.svg" %}</span>
|
||||
{{ folder.title }}
|
||||
</b-dropdown-item-button>
|
||||
<b-dropdown-item-button @click="moveFeedToNewFolder(feed)">
|
||||
<span class="text-muted icon mr-1">{% inline "plus.svg" %}</span>
|
||||
<span class="text-muted">New Folder</span>
|
||||
</b-dropdown-item-button>
|
||||
<b-dropdown-divider></b-dropdown-divider>
|
||||
<b-dropdown-item class="dropdown-danger"
|
||||
@click.prevent="deleteFeed(feed)">
|
||||
Delete
|
||||
</b-dropdown-item>
|
||||
</b-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- polyfill -->
|
||||
<script src="./static/javascripts/fetch.umd.js"></script>
|
||||
<script src="./static/javascripts/url-polyfill.min.js"></script>
|
||||
<!-- external -->
|
||||
<script src="./static/javascripts/vue.min.js"></script>
|
||||
<script src="./static/javascripts/vue-lazyload.js"></script>
|
||||
<script src="./static/javascripts/popper.min.js"></script>
|
||||
<script src="./static/javascripts/bootstrap-vue.min.js"></script>
|
||||
<script src="./static/javascripts/Readability.min.js"></script>
|
||||
<script src="./static/javascripts/purify.min.js"></script>
|
||||
<!-- internal -->
|
||||
<script src="./static/javascripts/api.js"></script>
|
||||
<script src="./static/javascripts/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
2
src/assets/javascripts/Readability.min.js
vendored
Normal file
110
src/assets/javascripts/api.js
Normal file
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
var xfetch = function(resource, init) {
|
||||
init = init || {}
|
||||
if (['post', 'put', 'delete'].indexOf(init.method) !== -1) {
|
||||
init['headers'] = init['headers'] || {}
|
||||
init['headers']['x-requested-by'] = 'yarr'
|
||||
}
|
||||
return fetch(resource, init)
|
||||
}
|
||||
var api = function(method, endpoint, data) {
|
||||
var headers = {'Content-Type': 'application/json'}
|
||||
return xfetch(endpoint, {
|
||||
method: method,
|
||||
headers: headers,
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
var json = function(res) {
|
||||
return res.json()
|
||||
}
|
||||
|
||||
var param = function(query) {
|
||||
if (!query) return ''
|
||||
return '?' + Object.keys(query).map(function(key) {
|
||||
return encodeURIComponent(key) + '=' + encodeURIComponent(query[key])
|
||||
}).join('&')
|
||||
}
|
||||
|
||||
window.api = {
|
||||
feeds: {
|
||||
list: function() {
|
||||
return api('get', './api/feeds').then(json)
|
||||
},
|
||||
create: function(data) {
|
||||
return api('post', './api/feeds', data).then(json)
|
||||
},
|
||||
update: function(id, data) {
|
||||
return api('put', './api/feeds/' + id, data)
|
||||
},
|
||||
delete: function(id) {
|
||||
return api('delete', './api/feeds/' + id)
|
||||
},
|
||||
list_items: function(id) {
|
||||
return api('get', './api/feeds/' + id + '/items').then(json)
|
||||
},
|
||||
refresh: function() {
|
||||
return api('post', './api/feeds/refresh')
|
||||
},
|
||||
list_errors: function() {
|
||||
return api('get', './api/feeds/errors').then(json)
|
||||
},
|
||||
},
|
||||
folders: {
|
||||
list: function() {
|
||||
return api('get', './api/folders').then(json)
|
||||
},
|
||||
create: function(data) {
|
||||
return api('post', './api/folders', data).then(json)
|
||||
},
|
||||
update: function(id, data) {
|
||||
return api('put', './api/folders/' + id, data)
|
||||
},
|
||||
delete: function(id) {
|
||||
return api('delete', './api/folders/' + id)
|
||||
},
|
||||
list_items: function(id) {
|
||||
return api('get', './api/folders/' + id + '/items').then(json)
|
||||
}
|
||||
},
|
||||
items: {
|
||||
list: function(query) {
|
||||
return api('get', './api/items' + param(query)).then(json)
|
||||
},
|
||||
update: function(id, data) {
|
||||
return api('put', './api/items/' + id, data)
|
||||
},
|
||||
mark_read: function(query) {
|
||||
return api('put', './api/items' + param(query))
|
||||
},
|
||||
},
|
||||
settings: {
|
||||
get: function() {
|
||||
return api('get', './api/settings').then(json)
|
||||
},
|
||||
update: function(data) {
|
||||
return api('put', './api/settings', data)
|
||||
},
|
||||
},
|
||||
status: function() {
|
||||
return api('get', './api/status').then(json)
|
||||
},
|
||||
upload_opml: function(form) {
|
||||
return xfetch('./opml/import', {
|
||||
method: 'post',
|
||||
body: new FormData(form),
|
||||
})
|
||||
},
|
||||
logout: function() {
|
||||
return api('post', './logout')
|
||||
},
|
||||
crawl: function(url) {
|
||||
return xfetch('./page?url=' + url).then(function(res) {
|
||||
return res.text()
|
||||
})
|
||||
}
|
||||
}
|
||||
})()
|
||||
608
src/assets/javascripts/app.js
Normal file
@@ -0,0 +1,608 @@
|
||||
'use strict';
|
||||
|
||||
var TITLE = document.title
|
||||
|
||||
function authenticated() {
|
||||
return /auth=.+/g.test(document.cookie)
|
||||
|
||||
}
|
||||
|
||||
var FONTS = [
|
||||
"Arial",
|
||||
"Courier New",
|
||||
"Georgia",
|
||||
"Times New Roman",
|
||||
"Verdana",
|
||||
]
|
||||
|
||||
var debounce = function(callback, wait) {
|
||||
var timeout
|
||||
return function() {
|
||||
var ctx = this, args = arguments
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(function() {
|
||||
callback.apply(ctx, args)
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
|
||||
var sanitize = function(content, base) {
|
||||
// WILD: `item.link` may be a relative link (or some nonsense)
|
||||
try { new URL(base) } catch(err) { base = null }
|
||||
|
||||
var sanitizer = new DOMPurify
|
||||
sanitizer.addHook('afterSanitizeAttributes', function(node) {
|
||||
// set all elements owning target to target=_blank
|
||||
if ('target' in node)
|
||||
node.setAttribute('target', '_blank')
|
||||
// set non-HTML/MathML links to xlink:show=new
|
||||
if (!node.hasAttribute('target') && (node.hasAttribute('xlink:href') || node.hasAttribute('href')))
|
||||
node.setAttribute('xlink:show', 'new')
|
||||
|
||||
// set absolute urls
|
||||
if (base && node.attributes.href && node.attributes.href.value)
|
||||
node.href = new URL(node.attributes.href.value, base).toString()
|
||||
if (base && node.attributes.src && node.attributes.src.value)
|
||||
node.src = new URL(node.attributes.src.value, base).toString()
|
||||
})
|
||||
return sanitizer.sanitize(content, {FORBID_TAGS: ['style'], FORBID_ATTR: ['style', 'class']})
|
||||
}
|
||||
|
||||
Vue.use(VueLazyload)
|
||||
|
||||
Vue.directive('scroll', {
|
||||
inserted: function(el, binding) {
|
||||
el.addEventListener('scroll', debounce(function(event) {
|
||||
binding.value(event, el)
|
||||
}, 200))
|
||||
},
|
||||
})
|
||||
|
||||
Vue.component('drag', {
|
||||
props: ['width'],
|
||||
template: '<div class="drag"></div>',
|
||||
mounted: function() {
|
||||
var self = this
|
||||
var startX = undefined
|
||||
var initW = undefined
|
||||
var onMouseMove = function(e) {
|
||||
var offset = e.clientX - startX
|
||||
var newWidth = initW + offset
|
||||
self.$emit('resize', newWidth)
|
||||
}
|
||||
var onMouseUp = function(e) {
|
||||
document.removeEventListener('mousemove', onMouseMove)
|
||||
document.removeEventListener('mouseup', onMouseUp)
|
||||
}
|
||||
this.$el.addEventListener('mousedown', function(e) {
|
||||
startX = e.clientX
|
||||
initW = self.width
|
||||
document.addEventListener('mousemove', onMouseMove)
|
||||
document.addEventListener('mouseup', onMouseUp)
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
function dateRepr(d) {
|
||||
var sec = (new Date().getTime() - d.getTime()) / 1000
|
||||
var neg = sec < 0
|
||||
var out = ''
|
||||
|
||||
sec = Math.abs(sec)
|
||||
if (sec < 2700) // less than 45 minutes
|
||||
out = Math.round(sec / 60) + 'm'
|
||||
else if (sec < 86400) // less than 24 hours
|
||||
out = Math.round(sec / 3600) + 'h'
|
||||
else if (sec < 604800) // less than a week
|
||||
out = Math.round(sec / 86400) + 'd'
|
||||
else
|
||||
out = d.toLocaleDateString(undefined, {year: "numeric", month: "long", day: "numeric"})
|
||||
|
||||
if (neg) return '-' + out
|
||||
return out
|
||||
}
|
||||
|
||||
Vue.component('relative-time', {
|
||||
props: ['val'],
|
||||
data: function() {
|
||||
var d = new Date(this.val)
|
||||
return {
|
||||
'date': d,
|
||||
'formatted': dateRepr(d),
|
||||
'interval': null,
|
||||
}
|
||||
},
|
||||
template: '<time :datetime="val">{{ formatted }}</time>',
|
||||
mounted: function() {
|
||||
this.interval = setInterval(function() {
|
||||
this.formatted = dateRepr(this.date)
|
||||
}.bind(this), 600000) // every 10 minutes
|
||||
},
|
||||
destroyed: function() {
|
||||
clearInterval(this.interval)
|
||||
},
|
||||
})
|
||||
|
||||
var vm = new Vue({
|
||||
created: function() {
|
||||
this.refreshFeeds()
|
||||
this.refreshStats()
|
||||
},
|
||||
mounted: function() {
|
||||
this.$root.$on('bv::modal::hidden', function(bvEvent, modalId) {
|
||||
if (vm.settings == 'create') {
|
||||
vm.feedNewChoice = []
|
||||
vm.feedNewChoiceSelected = ''
|
||||
}
|
||||
})
|
||||
},
|
||||
data: function() {
|
||||
return {
|
||||
'filterSelected': undefined,
|
||||
'folders': [],
|
||||
'feeds': [],
|
||||
'feedSelected': undefined,
|
||||
'feedListWidth': undefined,
|
||||
'feedNewChoice': [],
|
||||
'feedNewChoiceSelected': '',
|
||||
'items': [],
|
||||
'itemsPage': {
|
||||
'cur': 1,
|
||||
'num': 1,
|
||||
},
|
||||
'itemSelected': null,
|
||||
'itemSelectedDetails': {},
|
||||
'itemSelectedReadability': '',
|
||||
'itemSearch': '',
|
||||
'itemSortNewestFirst': undefined,
|
||||
'itemListWidth': undefined,
|
||||
|
||||
'filteredFeedStats': {},
|
||||
'filteredFolderStats': {},
|
||||
'filteredTotalStats': null,
|
||||
|
||||
'settings': 'create',
|
||||
'loading': {
|
||||
'feeds': 0,
|
||||
'newfeed': false,
|
||||
'items': false,
|
||||
'readability': false,
|
||||
},
|
||||
'fonts': FONTS,
|
||||
'feedStats': {},
|
||||
'theme': {
|
||||
'name': 'light',
|
||||
'font': '',
|
||||
'size': 1,
|
||||
},
|
||||
'refreshRate': undefined,
|
||||
'authenticated': authenticated(),
|
||||
'feed_errors': {},
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
foldersWithFeeds: function() {
|
||||
var feedsByFolders = this.feeds.reduce(function(folders, feed) {
|
||||
if (!folders[feed.folder_id])
|
||||
folders[feed.folder_id] = [feed]
|
||||
else
|
||||
folders[feed.folder_id].push(feed)
|
||||
return folders
|
||||
}, {})
|
||||
var folders = this.folders.slice().map(function(folder) {
|
||||
folder.feeds = feedsByFolders[folder.id]
|
||||
return folder
|
||||
})
|
||||
folders.push({id: null, feeds: feedsByFolders[null]})
|
||||
return folders
|
||||
},
|
||||
feedsById: function() {
|
||||
return this.feeds.reduce(function(acc, feed) { acc[feed.id] = feed; return acc }, {})
|
||||
},
|
||||
itemsById: function() {
|
||||
return this.items.reduce(function(acc, item) { acc[item.id] = item; return acc }, {})
|
||||
},
|
||||
itemSelectedContent: function() {
|
||||
if (!this.itemSelected) return ''
|
||||
|
||||
if (this.itemSelectedReadability)
|
||||
return this.itemSelectedReadability
|
||||
|
||||
var content = ''
|
||||
if (this.itemSelectedDetails.content)
|
||||
content = this.itemSelectedDetails.content
|
||||
else if (this.itemSelectedDetails.description)
|
||||
content = this.itemSelectedDetails.description
|
||||
|
||||
return sanitize(content, this.itemSelectedDetails.link)
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
'theme': {
|
||||
deep: true,
|
||||
handler: function(theme) {
|
||||
document.body.classList.value = 'theme-' + theme.name
|
||||
api.settings.update({
|
||||
theme_name: theme.name,
|
||||
theme_font: theme.font,
|
||||
theme_size: theme.size,
|
||||
})
|
||||
},
|
||||
},
|
||||
'feedStats': {
|
||||
deep: true,
|
||||
handler: debounce(function() {
|
||||
var title = TITLE
|
||||
var unreadCount = Object.values(this.feedStats).reduce(function(acc, stat) {
|
||||
return acc + stat.unread
|
||||
}, 0)
|
||||
if (unreadCount) {
|
||||
title += ' ('+unreadCount+')'
|
||||
}
|
||||
document.title = title
|
||||
this.computeStats()
|
||||
}, 500),
|
||||
},
|
||||
'filterSelected': function(newVal, oldVal) {
|
||||
if (oldVal === undefined) return // do nothing, initial setup
|
||||
api.settings.update({filter: newVal}).then(this.refreshItems.bind(this))
|
||||
this.itemSelected = null
|
||||
this.computeStats()
|
||||
},
|
||||
'feedSelected': function(newVal, oldVal) {
|
||||
if (oldVal === undefined) return // do nothing, initial setup
|
||||
api.settings.update({feed: newVal}).then(this.refreshItems.bind(this))
|
||||
this.itemSelected = null
|
||||
if (this.$refs.itemlist) this.$refs.itemlist.scrollTop = 0
|
||||
},
|
||||
'itemSelected': function(newVal, oldVal) {
|
||||
this.itemSelectedReadability = ''
|
||||
if (newVal === null) {
|
||||
this.itemSelectedDetails = null
|
||||
return
|
||||
}
|
||||
if (this.$refs.content) this.$refs.content.scrollTop = 0
|
||||
|
||||
this.itemSelectedDetails = this.itemsById[newVal]
|
||||
if (this.itemSelectedDetails.status == 'unread') {
|
||||
this.itemSelectedDetails.status = 'read'
|
||||
this.feedStats[this.itemSelectedDetails.feed_id].unread -= 1
|
||||
api.items.update(this.itemSelectedDetails.id, {status: this.itemSelectedDetails.status})
|
||||
}
|
||||
},
|
||||
'itemSearch': debounce(function(newVal) {
|
||||
this.refreshItems()
|
||||
}, 500),
|
||||
'itemSortNewestFirst': function(newVal, oldVal) {
|
||||
if (oldVal === undefined) return // do nothing, initial setup
|
||||
api.settings.update({sort_newest_first: newVal}).then(this.refreshItems.bind(this))
|
||||
},
|
||||
'feedListWidth': debounce(function(newVal, oldVal) {
|
||||
if (oldVal === undefined) return // do nothing, initial setup
|
||||
api.settings.update({feed_list_width: newVal})
|
||||
}, 1000),
|
||||
'itemListWidth': debounce(function(newVal, oldVal) {
|
||||
if (oldVal === undefined) return // do nothing, initial setup
|
||||
api.settings.update({item_list_width: newVal})
|
||||
}, 1000),
|
||||
'refreshRate': function(newVal, oldVal) {
|
||||
if (oldVal === undefined) return // do nothing, initial setup
|
||||
api.settings.update({refresh_rate: newVal})
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
refreshStats: function(loopMode) {
|
||||
api.status().then(function(data) {
|
||||
if (loopMode && !vm.itemSelected) vm.refreshItems()
|
||||
|
||||
vm.loading.feeds = data.running
|
||||
if (data.running) {
|
||||
setTimeout(vm.refreshStats.bind(vm, true), 500)
|
||||
}
|
||||
vm.feedStats = data.stats.reduce(function(acc, stat) {
|
||||
acc[stat.feed_id] = stat
|
||||
return acc
|
||||
}, {})
|
||||
})
|
||||
},
|
||||
getItemsQuery: function() {
|
||||
var query = {}
|
||||
if (this.feedSelected) {
|
||||
var parts = this.feedSelected.split(':', 2)
|
||||
var type = parts[0]
|
||||
var guid = parts[1]
|
||||
if (type == 'feed') {
|
||||
query.feed_id = guid
|
||||
} else if (type == 'folder') {
|
||||
query.folder_id = guid
|
||||
}
|
||||
}
|
||||
if (this.filterSelected) {
|
||||
query.status = this.filterSelected
|
||||
}
|
||||
if (this.itemSearch) {
|
||||
query.search = this.itemSearch
|
||||
}
|
||||
if (!this.itemSortNewestFirst) {
|
||||
query.oldest_first = true
|
||||
}
|
||||
return query
|
||||
},
|
||||
refreshFeeds: function() {
|
||||
return Promise
|
||||
.all([api.folders.list(), api.feeds.list()])
|
||||
.then(function(values) {
|
||||
vm.folders = values[0]
|
||||
vm.feeds = values[1]
|
||||
})
|
||||
},
|
||||
refreshItems: function() {
|
||||
if (this.feedSelected === null) {
|
||||
vm.items = []
|
||||
vm.itemsPage = {'cur': 1, 'num': 1}
|
||||
return
|
||||
}
|
||||
var query = this.getItemsQuery()
|
||||
this.loading.items = true
|
||||
return api.items.list(query).then(function(data) {
|
||||
vm.items = data.list
|
||||
vm.itemsPage = data.page
|
||||
vm.loading.items = false
|
||||
})
|
||||
},
|
||||
loadMoreItems: function(event, el) {
|
||||
if (this.itemsPage.cur >= this.itemsPage.num) return
|
||||
if (this.loading.items) return
|
||||
var closeToBottom = (el.scrollHeight - el.scrollTop - el.offsetHeight) < 50
|
||||
if (closeToBottom) {
|
||||
this.loading.moreitems = true
|
||||
var query = this.getItemsQuery()
|
||||
query.page = this.itemsPage.cur + 1
|
||||
api.items.list(query).then(function(data) {
|
||||
vm.items = vm.items.concat(data.list)
|
||||
vm.itemsPage = data.page
|
||||
vm.loading.items = false
|
||||
})
|
||||
}
|
||||
},
|
||||
markItemsRead: function() {
|
||||
var query = this.getItemsQuery()
|
||||
api.items.mark_read(query).then(function() {
|
||||
vm.items = []
|
||||
vm.itemsPage = {'cur': 1, 'num': 1}
|
||||
vm.itemSelected = null
|
||||
vm.refreshStats()
|
||||
})
|
||||
},
|
||||
toggleFolderExpanded: function(folder) {
|
||||
folder.is_expanded = !folder.is_expanded
|
||||
api.folders.update(folder.id, {is_expanded: folder.is_expanded})
|
||||
},
|
||||
formatDate: function(datestr) {
|
||||
var options = {
|
||||
year: "numeric", month: "long", day: "numeric",
|
||||
hour: '2-digit', minute: '2-digit',
|
||||
}
|
||||
return new Date(datestr).toLocaleDateString(undefined, options)
|
||||
},
|
||||
moveFeed: function(feed, folder) {
|
||||
var folder_id = folder ? folder.id : null
|
||||
api.feeds.update(feed.id, {folder_id: folder_id}).then(function() {
|
||||
feed.folder_id = folder_id
|
||||
vm.refreshStats()
|
||||
})
|
||||
},
|
||||
moveFeedToNewFolder: function(feed) {
|
||||
var title = prompt('Enter folder name:')
|
||||
if (!title) return
|
||||
api.folders.create({'title': title}).then(function(folder) {
|
||||
api.feeds.update(feed.id, {folder_id: folder.id}).then(function() {
|
||||
vm.refreshFeeds().then(function() {
|
||||
vm.refreshStats()
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
createNewFeedFolder: function() {
|
||||
var title = prompt('Enter folder name:')
|
||||
if (!title) return
|
||||
api.folders.create({'title': title}).then(function(result) {
|
||||
vm.refreshFeeds().then(function() {
|
||||
vm.$nextTick(function() {
|
||||
if (vm.$refs.newFeedFolder) {
|
||||
vm.$refs.newFeedFolder.value = result.id
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
renameFolder: function(folder) {
|
||||
var newTitle = prompt('Enter new title', folder.title)
|
||||
if (newTitle) {
|
||||
api.folders.update(folder.id, {title: newTitle}).then(function() {
|
||||
folder.title = newTitle
|
||||
})
|
||||
}
|
||||
},
|
||||
deleteFolder: function(folder) {
|
||||
if (confirm('Are you sure you want to delete ' + folder.title + '?')) {
|
||||
api.folders.delete(folder.id).then(function() {
|
||||
if (vm.feedSelected === 'folder:'+folder.id) {
|
||||
vm.items = []
|
||||
vm.feedSelected = ''
|
||||
}
|
||||
vm.refreshStats()
|
||||
vm.refreshFeeds()
|
||||
})
|
||||
}
|
||||
},
|
||||
renameFeed: function(feed) {
|
||||
var newTitle = prompt('Enter new title', feed.title)
|
||||
if (newTitle) {
|
||||
api.feeds.update(feed.id, {title: newTitle}).then(function() {
|
||||
feed.title = newTitle
|
||||
})
|
||||
}
|
||||
},
|
||||
deleteFeed: function(feed) {
|
||||
if (confirm('Are you sure you want to delete ' + feed.title + '?')) {
|
||||
api.feeds.delete(feed.id).then(function() {
|
||||
// unselect feed to prevent reading properties of null in template
|
||||
var isSelected = !vm.feedSelected
|
||||
|| (vm.feedSelected === 'feed:'+feed.id
|
||||
|| (feed.folder_id && vm.feedSelected === 'folder:'+feed.folder_id));
|
||||
if (isSelected) vm.feedSelected = null
|
||||
|
||||
vm.refreshStats()
|
||||
vm.refreshFeeds()
|
||||
})
|
||||
}
|
||||
},
|
||||
createFeed: function(event) {
|
||||
var form = event.target
|
||||
var data = {
|
||||
url: form.querySelector('input[name=url]').value,
|
||||
folder_id: parseInt(form.querySelector('select[name=folder_id]').value) || null,
|
||||
}
|
||||
if (this.feedNewChoiceSelected) {
|
||||
data.url = this.feedNewChoiceSelected
|
||||
}
|
||||
this.loading.newfeed = true
|
||||
api.feeds.create(data).then(function(result) {
|
||||
if (result.status === 'success') {
|
||||
vm.refreshFeeds()
|
||||
vm.refreshStats()
|
||||
vm.$bvModal.hide('settings-modal')
|
||||
} else if (result.status === 'multiple') {
|
||||
vm.feedNewChoice = result.choice
|
||||
vm.feedNewChoiceSelected = result.choice[0].url
|
||||
} else {
|
||||
alert('No feeds found at the given url.')
|
||||
}
|
||||
vm.loading.newfeed = false
|
||||
})
|
||||
},
|
||||
toggleItemStarred: function(item) {
|
||||
if (item.status == 'starred') {
|
||||
item.status = 'read'
|
||||
this.feedStats[item.feed_id].starred -= 1
|
||||
} else if (item.status != 'starred') {
|
||||
item.status = 'starred'
|
||||
this.feedStats[item.feed_id].starred += 1
|
||||
}
|
||||
api.items.update(item.id, {status: item.status})
|
||||
},
|
||||
toggleItemRead: function(item) {
|
||||
if (item.status == 'unread') {
|
||||
item.status = 'read'
|
||||
this.feedStats[item.feed_id].unread -= 1
|
||||
} else if (item.status == 'read') {
|
||||
item.status = 'unread'
|
||||
this.feedStats[item.feed_id].unread += 1
|
||||
}
|
||||
api.items.update(item.id, {status: item.status})
|
||||
},
|
||||
importOPML: function(event) {
|
||||
var input = event.target
|
||||
var form = document.querySelector('#opml-import-form')
|
||||
this.$refs.menuDropdown.hide()
|
||||
api.upload_opml(form).then(function() {
|
||||
input.value = ''
|
||||
vm.refreshFeeds()
|
||||
vm.refreshStats()
|
||||
})
|
||||
},
|
||||
logout: function() {
|
||||
api.logout().then(function() {
|
||||
document.location.reload()
|
||||
})
|
||||
},
|
||||
getReadable: function(item) {
|
||||
if (this.itemSelectedReadability) {
|
||||
this.itemSelectedReadability = null
|
||||
return
|
||||
}
|
||||
if (item.link) {
|
||||
this.loading.readability = true
|
||||
api.crawl(item.link).then(function(body) {
|
||||
vm.loading.readability = false
|
||||
if (!body.length) return
|
||||
var bodyClean = sanitize(body, item.link)
|
||||
var doc = new DOMParser().parseFromString(bodyClean, 'text/html')
|
||||
var parsed = new Readability(doc).parse()
|
||||
if (parsed && parsed.content) {
|
||||
vm.itemSelectedReadability = parsed.content
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
showSettings: function(settings) {
|
||||
this.settings = settings
|
||||
this.$bvModal.show('settings-modal')
|
||||
|
||||
if (settings === 'manage') {
|
||||
api.feeds.list_errors().then(function(errors) {
|
||||
vm.feed_errors = errors
|
||||
})
|
||||
}
|
||||
},
|
||||
resizeFeedList: function(width) {
|
||||
this.feedListWidth = Math.min(Math.max(200, width), 700)
|
||||
},
|
||||
resizeItemList: function(width) {
|
||||
this.itemListWidth = Math.min(Math.max(200, width), 700)
|
||||
},
|
||||
resetFeedChoice: function() {
|
||||
this.feedNewChoice = []
|
||||
this.feedNewChoiceSelected = ''
|
||||
},
|
||||
incrFont: function(x) {
|
||||
this.theme.size = +(this.theme.size + (0.1 * x)).toFixed(1)
|
||||
},
|
||||
fetchAllFeeds: function() {
|
||||
api.feeds.refresh().then(this.refreshStats.bind(this))
|
||||
},
|
||||
computeStats: function() {
|
||||
var filter = this.filterSelected
|
||||
if (!filter) {
|
||||
this.filteredFeedStats = {}
|
||||
this.filteredFolderStats = {}
|
||||
this.filteredTotalStats = null
|
||||
return
|
||||
}
|
||||
|
||||
var statsFeeds = {}, statsFolders = {}, statsTotal = 0
|
||||
|
||||
for (var i = 0; i < this.feeds.length; i++) {
|
||||
var feed = this.feeds[i]
|
||||
if (!this.feedStats[feed.id]) continue
|
||||
|
||||
var n = vm.feedStats[feed.id][filter] || 0
|
||||
|
||||
if (!statsFolders[feed.folder_id]) statsFolders[feed.folder_id] = 0
|
||||
|
||||
statsFeeds[feed.id] = n
|
||||
statsFolders[feed.folder_id] += n
|
||||
statsTotal += n
|
||||
}
|
||||
|
||||
this.filteredFeedStats = statsFeeds
|
||||
this.filteredFolderStats = statsFolders
|
||||
this.filteredTotalStats = statsTotal
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
api.settings.get().then(function(data) {
|
||||
vm.feedSelected = data.feed
|
||||
vm.filterSelected = data.filter
|
||||
vm.itemSortNewestFirst = data.sort_newest_first
|
||||
vm.feedListWidth = data.feed_list_width || 300
|
||||
vm.itemListWidth = data.item_list_width || 300
|
||||
vm.theme.name = data.theme_name
|
||||
vm.theme.font = data.theme_font
|
||||
vm.theme.size = data.theme_size
|
||||
vm.refreshRate = data.refresh_rate
|
||||
vm.refreshItems()
|
||||
vm.$mount('#app')
|
||||
})
|
||||
11
src/assets/javascripts/bootstrap-vue.min.js
vendored
Normal file
609
src/assets/javascripts/fetch.umd.js
Normal file
@@ -0,0 +1,609 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(factory((global.WHATWGFetch = {})));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
|
||||
var global = (typeof self !== 'undefined' && self) || (typeof global !== 'undefined' && global);
|
||||
|
||||
var support = {
|
||||
searchParams: 'URLSearchParams' in global,
|
||||
iterable: 'Symbol' in global && 'iterator' in Symbol,
|
||||
blob:
|
||||
'FileReader' in global &&
|
||||
'Blob' in global &&
|
||||
(function() {
|
||||
try {
|
||||
new Blob();
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
})(),
|
||||
formData: 'FormData' in global,
|
||||
arrayBuffer: 'ArrayBuffer' in global
|
||||
};
|
||||
|
||||
function isDataView(obj) {
|
||||
return obj && DataView.prototype.isPrototypeOf(obj)
|
||||
}
|
||||
|
||||
if (support.arrayBuffer) {
|
||||
var viewClasses = [
|
||||
'[object Int8Array]',
|
||||
'[object Uint8Array]',
|
||||
'[object Uint8ClampedArray]',
|
||||
'[object Int16Array]',
|
||||
'[object Uint16Array]',
|
||||
'[object Int32Array]',
|
||||
'[object Uint32Array]',
|
||||
'[object Float32Array]',
|
||||
'[object Float64Array]'
|
||||
];
|
||||
|
||||
var isArrayBufferView =
|
||||
ArrayBuffer.isView ||
|
||||
function(obj) {
|
||||
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeName(name) {
|
||||
if (typeof name !== 'string') {
|
||||
name = String(name);
|
||||
}
|
||||
if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
|
||||
throw new TypeError('Invalid character in header field name')
|
||||
}
|
||||
return name.toLowerCase()
|
||||
}
|
||||
|
||||
function normalizeValue(value) {
|
||||
if (typeof value !== 'string') {
|
||||
value = String(value);
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// Build a destructive iterator for the value list
|
||||
function iteratorFor(items) {
|
||||
var iterator = {
|
||||
next: function() {
|
||||
var value = items.shift();
|
||||
return {done: value === undefined, value: value}
|
||||
}
|
||||
};
|
||||
|
||||
if (support.iterable) {
|
||||
iterator[Symbol.iterator] = function() {
|
||||
return iterator
|
||||
};
|
||||
}
|
||||
|
||||
return iterator
|
||||
}
|
||||
|
||||
function Headers(headers) {
|
||||
this.map = {};
|
||||
|
||||
if (headers instanceof Headers) {
|
||||
headers.forEach(function(value, name) {
|
||||
this.append(name, value);
|
||||
}, this);
|
||||
} else if (Array.isArray(headers)) {
|
||||
headers.forEach(function(header) {
|
||||
this.append(header[0], header[1]);
|
||||
}, this);
|
||||
} else if (headers) {
|
||||
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
||||
this.append(name, headers[name]);
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
|
||||
Headers.prototype.append = function(name, value) {
|
||||
name = normalizeName(name);
|
||||
value = normalizeValue(value);
|
||||
var oldValue = this.map[name];
|
||||
this.map[name] = oldValue ? oldValue + ', ' + value : value;
|
||||
};
|
||||
|
||||
Headers.prototype['delete'] = function(name) {
|
||||
delete this.map[normalizeName(name)];
|
||||
};
|
||||
|
||||
Headers.prototype.get = function(name) {
|
||||
name = normalizeName(name);
|
||||
return this.has(name) ? this.map[name] : null
|
||||
};
|
||||
|
||||
Headers.prototype.has = function(name) {
|
||||
return this.map.hasOwnProperty(normalizeName(name))
|
||||
};
|
||||
|
||||
Headers.prototype.set = function(name, value) {
|
||||
this.map[normalizeName(name)] = normalizeValue(value);
|
||||
};
|
||||
|
||||
Headers.prototype.forEach = function(callback, thisArg) {
|
||||
for (var name in this.map) {
|
||||
if (this.map.hasOwnProperty(name)) {
|
||||
callback.call(thisArg, this.map[name], name, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Headers.prototype.keys = function() {
|
||||
var items = [];
|
||||
this.forEach(function(value, name) {
|
||||
items.push(name);
|
||||
});
|
||||
return iteratorFor(items)
|
||||
};
|
||||
|
||||
Headers.prototype.values = function() {
|
||||
var items = [];
|
||||
this.forEach(function(value) {
|
||||
items.push(value);
|
||||
});
|
||||
return iteratorFor(items)
|
||||
};
|
||||
|
||||
Headers.prototype.entries = function() {
|
||||
var items = [];
|
||||
this.forEach(function(value, name) {
|
||||
items.push([name, value]);
|
||||
});
|
||||
return iteratorFor(items)
|
||||
};
|
||||
|
||||
if (support.iterable) {
|
||||
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
|
||||
}
|
||||
|
||||
function consumed(body) {
|
||||
if (body.bodyUsed) {
|
||||
return Promise.reject(new TypeError('Already read'))
|
||||
}
|
||||
body.bodyUsed = true;
|
||||
}
|
||||
|
||||
function fileReaderReady(reader) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
reader.onload = function() {
|
||||
resolve(reader.result);
|
||||
};
|
||||
reader.onerror = function() {
|
||||
reject(reader.error);
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
function readBlobAsArrayBuffer(blob) {
|
||||
var reader = new FileReader();
|
||||
var promise = fileReaderReady(reader);
|
||||
reader.readAsArrayBuffer(blob);
|
||||
return promise
|
||||
}
|
||||
|
||||
function readBlobAsText(blob) {
|
||||
var reader = new FileReader();
|
||||
var promise = fileReaderReady(reader);
|
||||
reader.readAsText(blob);
|
||||
return promise
|
||||
}
|
||||
|
||||
function readArrayBufferAsText(buf) {
|
||||
var view = new Uint8Array(buf);
|
||||
var chars = new Array(view.length);
|
||||
|
||||
for (var i = 0; i < view.length; i++) {
|
||||
chars[i] = String.fromCharCode(view[i]);
|
||||
}
|
||||
return chars.join('')
|
||||
}
|
||||
|
||||
function bufferClone(buf) {
|
||||
if (buf.slice) {
|
||||
return buf.slice(0)
|
||||
} else {
|
||||
var view = new Uint8Array(buf.byteLength);
|
||||
view.set(new Uint8Array(buf));
|
||||
return view.buffer
|
||||
}
|
||||
}
|
||||
|
||||
function Body() {
|
||||
this.bodyUsed = false;
|
||||
|
||||
this._initBody = function(body) {
|
||||
/*
|
||||
fetch-mock wraps the Response object in an ES6 Proxy to
|
||||
provide useful test harness features such as flush. However, on
|
||||
ES5 browsers without fetch or Proxy support pollyfills must be used;
|
||||
the proxy-pollyfill is unable to proxy an attribute unless it exists
|
||||
on the object before the Proxy is created. This change ensures
|
||||
Response.bodyUsed exists on the instance, while maintaining the
|
||||
semantic of setting Request.bodyUsed in the constructor before
|
||||
_initBody is called.
|
||||
*/
|
||||
this.bodyUsed = this.bodyUsed;
|
||||
this._bodyInit = body;
|
||||
if (!body) {
|
||||
this._bodyText = '';
|
||||
} else if (typeof body === 'string') {
|
||||
this._bodyText = body;
|
||||
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
||||
this._bodyBlob = body;
|
||||
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
||||
this._bodyFormData = body;
|
||||
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
||||
this._bodyText = body.toString();
|
||||
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
|
||||
this._bodyArrayBuffer = bufferClone(body.buffer);
|
||||
// IE 10-11 can't handle a DataView body.
|
||||
this._bodyInit = new Blob([this._bodyArrayBuffer]);
|
||||
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
|
||||
this._bodyArrayBuffer = bufferClone(body);
|
||||
} else {
|
||||
this._bodyText = body = Object.prototype.toString.call(body);
|
||||
}
|
||||
|
||||
if (!this.headers.get('content-type')) {
|
||||
if (typeof body === 'string') {
|
||||
this.headers.set('content-type', 'text/plain;charset=UTF-8');
|
||||
} else if (this._bodyBlob && this._bodyBlob.type) {
|
||||
this.headers.set('content-type', this._bodyBlob.type);
|
||||
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
||||
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (support.blob) {
|
||||
this.blob = function() {
|
||||
var rejected = consumed(this);
|
||||
if (rejected) {
|
||||
return rejected
|
||||
}
|
||||
|
||||
if (this._bodyBlob) {
|
||||
return Promise.resolve(this._bodyBlob)
|
||||
} else if (this._bodyArrayBuffer) {
|
||||
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
|
||||
} else if (this._bodyFormData) {
|
||||
throw new Error('could not read FormData body as blob')
|
||||
} else {
|
||||
return Promise.resolve(new Blob([this._bodyText]))
|
||||
}
|
||||
};
|
||||
|
||||
this.arrayBuffer = function() {
|
||||
if (this._bodyArrayBuffer) {
|
||||
var isConsumed = consumed(this);
|
||||
if (isConsumed) {
|
||||
return isConsumed
|
||||
}
|
||||
if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
|
||||
return Promise.resolve(
|
||||
this._bodyArrayBuffer.buffer.slice(
|
||||
this._bodyArrayBuffer.byteOffset,
|
||||
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
|
||||
)
|
||||
)
|
||||
} else {
|
||||
return Promise.resolve(this._bodyArrayBuffer)
|
||||
}
|
||||
} else {
|
||||
return this.blob().then(readBlobAsArrayBuffer)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.text = function() {
|
||||
var rejected = consumed(this);
|
||||
if (rejected) {
|
||||
return rejected
|
||||
}
|
||||
|
||||
if (this._bodyBlob) {
|
||||
return readBlobAsText(this._bodyBlob)
|
||||
} else if (this._bodyArrayBuffer) {
|
||||
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
|
||||
} else if (this._bodyFormData) {
|
||||
throw new Error('could not read FormData body as text')
|
||||
} else {
|
||||
return Promise.resolve(this._bodyText)
|
||||
}
|
||||
};
|
||||
|
||||
if (support.formData) {
|
||||
this.formData = function() {
|
||||
return this.text().then(decode)
|
||||
};
|
||||
}
|
||||
|
||||
this.json = function() {
|
||||
return this.text().then(JSON.parse)
|
||||
};
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
// HTTP methods whose capitalization should be normalized
|
||||
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
|
||||
|
||||
function normalizeMethod(method) {
|
||||
var upcased = method.toUpperCase();
|
||||
return methods.indexOf(upcased) > -1 ? upcased : method
|
||||
}
|
||||
|
||||
function Request(input, options) {
|
||||
if (!(this instanceof Request)) {
|
||||
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
var body = options.body;
|
||||
|
||||
if (input instanceof Request) {
|
||||
if (input.bodyUsed) {
|
||||
throw new TypeError('Already read')
|
||||
}
|
||||
this.url = input.url;
|
||||
this.credentials = input.credentials;
|
||||
if (!options.headers) {
|
||||
this.headers = new Headers(input.headers);
|
||||
}
|
||||
this.method = input.method;
|
||||
this.mode = input.mode;
|
||||
this.signal = input.signal;
|
||||
if (!body && input._bodyInit != null) {
|
||||
body = input._bodyInit;
|
||||
input.bodyUsed = true;
|
||||
}
|
||||
} else {
|
||||
this.url = String(input);
|
||||
}
|
||||
|
||||
this.credentials = options.credentials || this.credentials || 'same-origin';
|
||||
if (options.headers || !this.headers) {
|
||||
this.headers = new Headers(options.headers);
|
||||
}
|
||||
this.method = normalizeMethod(options.method || this.method || 'GET');
|
||||
this.mode = options.mode || this.mode || null;
|
||||
this.signal = options.signal || this.signal;
|
||||
this.referrer = null;
|
||||
|
||||
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
|
||||
throw new TypeError('Body not allowed for GET or HEAD requests')
|
||||
}
|
||||
this._initBody(body);
|
||||
|
||||
if (this.method === 'GET' || this.method === 'HEAD') {
|
||||
if (options.cache === 'no-store' || options.cache === 'no-cache') {
|
||||
// Search for a '_' parameter in the query string
|
||||
var reParamSearch = /([?&])_=[^&]*/;
|
||||
if (reParamSearch.test(this.url)) {
|
||||
// If it already exists then set the value with the current time
|
||||
this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime());
|
||||
} else {
|
||||
// Otherwise add a new '_' parameter to the end with the current time
|
||||
var reQueryString = /\?/;
|
||||
this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Request.prototype.clone = function() {
|
||||
return new Request(this, {body: this._bodyInit})
|
||||
};
|
||||
|
||||
function decode(body) {
|
||||
var form = new FormData();
|
||||
body
|
||||
.trim()
|
||||
.split('&')
|
||||
.forEach(function(bytes) {
|
||||
if (bytes) {
|
||||
var split = bytes.split('=');
|
||||
var name = split.shift().replace(/\+/g, ' ');
|
||||
var value = split.join('=').replace(/\+/g, ' ');
|
||||
form.append(decodeURIComponent(name), decodeURIComponent(value));
|
||||
}
|
||||
});
|
||||
return form
|
||||
}
|
||||
|
||||
function parseHeaders(rawHeaders) {
|
||||
var headers = new Headers();
|
||||
// Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
|
||||
// https://tools.ietf.org/html/rfc7230#section-3.2
|
||||
var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
|
||||
preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
|
||||
var parts = line.split(':');
|
||||
var key = parts.shift().trim();
|
||||
if (key) {
|
||||
var value = parts.join(':').trim();
|
||||
headers.append(key, value);
|
||||
}
|
||||
});
|
||||
return headers
|
||||
}
|
||||
|
||||
Body.call(Request.prototype);
|
||||
|
||||
function Response(bodyInit, options) {
|
||||
if (!(this instanceof Response)) {
|
||||
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
|
||||
}
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
this.type = 'default';
|
||||
this.status = options.status === undefined ? 200 : options.status;
|
||||
this.ok = this.status >= 200 && this.status < 300;
|
||||
this.statusText = 'statusText' in options ? options.statusText : '';
|
||||
this.headers = new Headers(options.headers);
|
||||
this.url = options.url || '';
|
||||
this._initBody(bodyInit);
|
||||
}
|
||||
|
||||
Body.call(Response.prototype);
|
||||
|
||||
Response.prototype.clone = function() {
|
||||
return new Response(this._bodyInit, {
|
||||
status: this.status,
|
||||
statusText: this.statusText,
|
||||
headers: new Headers(this.headers),
|
||||
url: this.url
|
||||
})
|
||||
};
|
||||
|
||||
Response.error = function() {
|
||||
var response = new Response(null, {status: 0, statusText: ''});
|
||||
response.type = 'error';
|
||||
return response
|
||||
};
|
||||
|
||||
var redirectStatuses = [301, 302, 303, 307, 308];
|
||||
|
||||
Response.redirect = function(url, status) {
|
||||
if (redirectStatuses.indexOf(status) === -1) {
|
||||
throw new RangeError('Invalid status code')
|
||||
}
|
||||
|
||||
return new Response(null, {status: status, headers: {location: url}})
|
||||
};
|
||||
|
||||
exports.DOMException = global.DOMException;
|
||||
try {
|
||||
new exports.DOMException();
|
||||
} catch (err) {
|
||||
exports.DOMException = function(message, name) {
|
||||
this.message = message;
|
||||
this.name = name;
|
||||
var error = Error(message);
|
||||
this.stack = error.stack;
|
||||
};
|
||||
exports.DOMException.prototype = Object.create(Error.prototype);
|
||||
exports.DOMException.prototype.constructor = exports.DOMException;
|
||||
}
|
||||
|
||||
function fetch(input, init) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var request = new Request(input, init);
|
||||
|
||||
if (request.signal && request.signal.aborted) {
|
||||
return reject(new exports.DOMException('Aborted', 'AbortError'))
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
function abortXhr() {
|
||||
xhr.abort();
|
||||
}
|
||||
|
||||
xhr.onload = function() {
|
||||
var options = {
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
|
||||
};
|
||||
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
|
||||
var body = 'response' in xhr ? xhr.response : xhr.responseText;
|
||||
setTimeout(function() {
|
||||
resolve(new Response(body, options));
|
||||
}, 0);
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
setTimeout(function() {
|
||||
reject(new TypeError('Network request failed'));
|
||||
}, 0);
|
||||
};
|
||||
|
||||
xhr.ontimeout = function() {
|
||||
setTimeout(function() {
|
||||
reject(new TypeError('Network request failed'));
|
||||
}, 0);
|
||||
};
|
||||
|
||||
xhr.onabort = function() {
|
||||
setTimeout(function() {
|
||||
reject(new exports.DOMException('Aborted', 'AbortError'));
|
||||
}, 0);
|
||||
};
|
||||
|
||||
function fixUrl(url) {
|
||||
try {
|
||||
return url === '' && global.location.href ? global.location.href : url
|
||||
} catch (e) {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
xhr.open(request.method, fixUrl(request.url), true);
|
||||
|
||||
if (request.credentials === 'include') {
|
||||
xhr.withCredentials = true;
|
||||
} else if (request.credentials === 'omit') {
|
||||
xhr.withCredentials = false;
|
||||
}
|
||||
|
||||
if ('responseType' in xhr) {
|
||||
if (support.blob) {
|
||||
xhr.responseType = 'blob';
|
||||
} else if (
|
||||
support.arrayBuffer &&
|
||||
request.headers.get('Content-Type') &&
|
||||
request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1
|
||||
) {
|
||||
xhr.responseType = 'arraybuffer';
|
||||
}
|
||||
}
|
||||
|
||||
if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) {
|
||||
Object.getOwnPropertyNames(init.headers).forEach(function(name) {
|
||||
xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
|
||||
});
|
||||
} else {
|
||||
request.headers.forEach(function(value, name) {
|
||||
xhr.setRequestHeader(name, value);
|
||||
});
|
||||
}
|
||||
|
||||
if (request.signal) {
|
||||
request.signal.addEventListener('abort', abortXhr);
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
// DONE (success or failure)
|
||||
if (xhr.readyState === 4) {
|
||||
request.signal.removeEventListener('abort', abortXhr);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
|
||||
})
|
||||
}
|
||||
|
||||
fetch.polyfill = true;
|
||||
|
||||
if (!global.fetch) {
|
||||
global.fetch = fetch;
|
||||
global.Headers = Headers;
|
||||
global.Request = Request;
|
||||
global.Response = Response;
|
||||
}
|
||||
|
||||
exports.Headers = Headers;
|
||||
exports.Request = Request;
|
||||
exports.Response = Response;
|
||||
exports.fetch = fetch;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
6
src/assets/javascripts/popper.min.js
vendored
Normal file
3
src/assets/javascripts/purify.min.js
vendored
Normal file
1
src/assets/javascripts/url-polyfill.min.js
vendored
Normal file
6
src/assets/javascripts/vue-lazyload.js
Normal file
6
src/assets/javascripts/vue.min.js
vendored
Normal file
38
src/assets/login.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>yarr!</title>
|
||||
<link rel="stylesheet" href="./static/stylesheets/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="./static/stylesheets/app.css">
|
||||
<link rel="icon shortcut" href="./static/graphicarts/anchor.png">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<style>
|
||||
form {
|
||||
max-width: 300px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
form img {
|
||||
width: 4rem;
|
||||
height: 4rem;
|
||||
display: block;
|
||||
margin: 3rem auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form action="" method="post">
|
||||
<img src="./static/graphicarts/anchor.svg" alt="">
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input name="username" class="form-control" id="username" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input name="password" class="form-control" id="password" type="password">
|
||||
</div>
|
||||
<button class="btn btn-block btn-default" type="submit">Login</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
605
src/assets/stylesheets/app.css
Normal file
@@ -0,0 +1,605 @@
|
||||
[v-cloak] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 15px !important;
|
||||
}
|
||||
|
||||
/* bootstrap customizations */
|
||||
|
||||
.btn-link {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.07);
|
||||
}
|
||||
|
||||
select.form-control {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
select.form-control:not([multiple]):not([size]) {
|
||||
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
||||
background: #fff url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%204%205'%3E%3Cpath%20fill='%23667189'%20d='M2%200L0%202h4zm0%205L0%203h4z'/%3E%3C/svg%3E") no-repeat right .35rem center/.6rem .6rem;
|
||||
padding-right: 1.2rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.form-control:focus, .btn:focus {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.dropdown-header {
|
||||
cursor: default;
|
||||
max-width: 180px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.dropdown-toggle-no-caret:after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#settings-modal {
|
||||
color: #212529 !important;
|
||||
}
|
||||
|
||||
.settings-dropdown .dropdown-toggle {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.dropdown-menu {
|
||||
padding: 0;
|
||||
box-shadow: 0px 1px 5px rgba(0, 0, 0, 0.07);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dropdown-item, .dropdown-header {
|
||||
padding: .375rem 1rem;
|
||||
}
|
||||
|
||||
.dropdown-divider {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-dropdown .dropdown-menu:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.settings-dropdown .dropdown-item:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.settings-dropdown.large .dropdown-item {
|
||||
padding: .5rem 1rem;
|
||||
}
|
||||
|
||||
.dropdown-danger .dropdown-item {
|
||||
color: #dc3545!important;
|
||||
}
|
||||
|
||||
.modal-backdrop {
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
.modal.fade .modal-dialog {
|
||||
transition: none !important;
|
||||
transform: none !important;
|
||||
}
|
||||
|
||||
.b-dropdown-form:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.popover:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.b-tooltip {
|
||||
opacity: 1;
|
||||
font-size: .7rem;
|
||||
}
|
||||
|
||||
.b-tooltip:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* custom elements */
|
||||
|
||||
.icon {
|
||||
height: 1rem;
|
||||
width: 1rem;
|
||||
display: inline-block;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.icon > svg , .icon > img {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.icon-small {
|
||||
width: .6rem;
|
||||
height: .6rem;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.icon-small > svg , .icon-small > img {
|
||||
width: .6rem;
|
||||
height: .6rem;
|
||||
}
|
||||
|
||||
.feed-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
min-width: 16px;
|
||||
margin-left: -18px !important;
|
||||
}
|
||||
|
||||
.counter {
|
||||
padding-left: .5rem;
|
||||
opacity: .6;
|
||||
}
|
||||
|
||||
.light {
|
||||
opacity: .6;
|
||||
}
|
||||
|
||||
.selectgroup {
|
||||
position: relative;
|
||||
display: block;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.selectgroup *, .noselect, .dropdown-menu * {
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.selectgroup input {
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
top: 0; left: 0;
|
||||
}
|
||||
|
||||
.selectgroup + .selectgroup {
|
||||
margin-top: .25rem;
|
||||
}
|
||||
|
||||
.selectgroup-label {
|
||||
padding: .375rem .5rem;
|
||||
border-radius: 4px;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.selectgroup-label:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.list-row:hover,
|
||||
.toolbar-item:hover,
|
||||
.toolbar-search:hover,
|
||||
.selectgroup-label:hover,
|
||||
.dropdown-item:hover {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
@keyframes stroke {
|
||||
from { stroke-dashoffset: 120; }
|
||||
to { stroke-dashoffset: 0; }
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
from { transform: rotate(0); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: transparent!important;
|
||||
min-height: .8rem;
|
||||
pointer-events: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.loading::after {
|
||||
animation: rotate .5s infinite linear;
|
||||
border: .1rem solid #6c757d;
|
||||
border-radius: 50%;
|
||||
border-right-color: transparent;
|
||||
border-top-color: transparent;
|
||||
content: "";
|
||||
display: block;
|
||||
height: 1rem;
|
||||
width: 1rem;
|
||||
left: 50%;
|
||||
margin-left: -.5rem;
|
||||
margin-top: -.5rem;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.icon-loading > svg {
|
||||
animation: stroke 2s infinite normal;
|
||||
stroke-dasharray: 60;
|
||||
}
|
||||
|
||||
.btn-default {
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: .25rem;
|
||||
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
||||
background: linear-gradient(#fff, #f5f7f9);
|
||||
}
|
||||
|
||||
.btn-default:active {
|
||||
background: #f5f7f9;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.btn-outline {
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: .25rem;
|
||||
}
|
||||
|
||||
.btn-outline:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.list-row {
|
||||
padding-left: .5rem;
|
||||
padding-right: .5rem;
|
||||
margin-left: -.5rem;
|
||||
margin-right: -.5rem;
|
||||
border-radius: 3px;
|
||||
user-select: none;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
min-height: 2rem !important;
|
||||
max-height: 2rem !important;
|
||||
}
|
||||
|
||||
.toolbar-item {
|
||||
display: inline-block;
|
||||
background-color: transparent;
|
||||
text-decoration: none;
|
||||
user-select: none;
|
||||
border: 1px solid transparent;
|
||||
padding: .25rem .5rem;
|
||||
font-size: 1rem;
|
||||
border-radius: .25rem;
|
||||
line-height: 1;
|
||||
color: inherit;
|
||||
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.toolbar-item:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.toolbar-item:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cursor-default {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.drag {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 6px;
|
||||
height: 100%;
|
||||
z-index: 900;
|
||||
cursor: col-resize;
|
||||
}
|
||||
|
||||
.input-icon {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.input-icon .icon {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
width: 2rem;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.input-icon input {
|
||||
padding-left: 2rem !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.toolbar-search {
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
padding: .25rem .5rem;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.toolbar-search:hover, .toolbar-search:focus {
|
||||
background-color: #f3f3f3;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.themepicker {
|
||||
position: relative;
|
||||
background: none;
|
||||
border: none;
|
||||
width: 100%;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.themepicker input {
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
top: 0; left: 0;
|
||||
}
|
||||
|
||||
.themepicker-label {
|
||||
height: 1.75rem;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.themepicker input[value=light] + .themepicker-label {
|
||||
box-shadow: inset 0 0 0px 1px #dee2e6;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.themepicker + .themepicker {
|
||||
margin-left: .5rem;
|
||||
}
|
||||
|
||||
.themepicker-label:hover {
|
||||
box-shadow: inset 0 0 0 2px rgb(1, 123, 254, .6) !important;
|
||||
}
|
||||
|
||||
.themepicker input:checked + .themepicker-label {
|
||||
box-shadow: inset 0 0 0px 2px #017bfe !important;
|
||||
}
|
||||
|
||||
.appearance-option {
|
||||
height: 2rem;
|
||||
padding-top: 0 !important;
|
||||
padding-bottom: 0 !important;
|
||||
line-height: 2rem;
|
||||
}
|
||||
|
||||
#opml-import-form input[type="file"]::-webkit-file-upload-button {
|
||||
position: absolute;
|
||||
top: -999px;
|
||||
left: -999px;
|
||||
}
|
||||
|
||||
/* content */
|
||||
|
||||
.content {
|
||||
overflow-wrap: break-word;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.content img, .content video {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.content pre {
|
||||
overflow-x: auto;
|
||||
color: inherit;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 3px;
|
||||
margin-left: -0.5rem;
|
||||
margin-right: -0.5rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.content a {
|
||||
color: inherit;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.content blockquote {
|
||||
border-left: 3px solid #22262a;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
.content h1 {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
.content h2 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
.content h3 {
|
||||
font-size: 1.17rem;
|
||||
}
|
||||
.content h4,
|
||||
.content h5,
|
||||
.content h6 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
/* theme: light */
|
||||
|
||||
a,
|
||||
.btn-link:hover,
|
||||
.toolbar-item.active {
|
||||
color: #0080d4;
|
||||
}
|
||||
|
||||
.dropdown-item.active,
|
||||
.dropdown-item:active,
|
||||
.selectgroup input:checked + .selectgroup-label {
|
||||
color: #fff;
|
||||
background-color: #0080d4 !important;
|
||||
}
|
||||
|
||||
.btn-default:focus,
|
||||
.form-control:focus {
|
||||
border-color: #0080d4;
|
||||
}
|
||||
|
||||
/* theme: sepia */
|
||||
|
||||
.themepicker input[value=sepia] + .themepicker-label,
|
||||
.theme-sepia,
|
||||
.theme-sepia .toolbar-search {
|
||||
background-color: #f4f0e5;
|
||||
}
|
||||
.theme-sepia .content hr,
|
||||
.theme-sepia .content pre,
|
||||
.theme-sepia .border-right,
|
||||
.theme-sepia .border-top {
|
||||
border-color: #e0d6ba !important;
|
||||
}
|
||||
.theme-sepia .selectgroup-label:not(.appearance-option):hover,
|
||||
.theme-sepia .toolbar-item:hover,
|
||||
.theme-sepia .toolbar-search:hover,
|
||||
.theme-sepia .toolbar-search:focus {
|
||||
background-color: #e0d6ba;
|
||||
}
|
||||
|
||||
/* theme: night */
|
||||
|
||||
.themepicker input[value=night] + .themepicker-label,
|
||||
.theme-night,
|
||||
.theme-night .toolbar-search {
|
||||
color: #d1d1d1;
|
||||
background-color: #0e0e0e;
|
||||
}
|
||||
|
||||
.theme-night .content hr,
|
||||
.theme-night .content pre,
|
||||
.theme-night .border-right,
|
||||
.theme-night .border-top {
|
||||
border-color: #1a1a1a !important;
|
||||
}
|
||||
|
||||
.theme-night .selectgroup-label:not(.appearance-option):hover,
|
||||
.theme-night .toolbar-item:hover,
|
||||
.theme-night .toolbar-search:hover,
|
||||
.theme-night .toolbar-search:focus {
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
/* animation */
|
||||
.indicator-enter-active, .indicator-leave-active {
|
||||
transition: all .3s;
|
||||
}
|
||||
.indicator-enter, .indicator-leave-to {
|
||||
width: 0;
|
||||
opacity: 0;
|
||||
margin: 0 !important;
|
||||
}
|
||||
|
||||
/* responsive layout
|
||||
|
||||
tablet:
|
||||
none selected: show feed list & item list
|
||||
feed selected: show feed list & item list
|
||||
item selected: show item
|
||||
mobile:
|
||||
none selected: show feed list
|
||||
feed selected: show item list
|
||||
item selected: show item
|
||||
*/
|
||||
|
||||
@media (min-width: 768px) and (max-width: 991.98px) {
|
||||
#app #col-feed-list {
|
||||
width: 35% !important;
|
||||
}
|
||||
#app #col-item-list {
|
||||
width: 65% !important;
|
||||
border-right-width: 0 !important;
|
||||
}
|
||||
#app #col-item {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#app.item-selected #col-feed-list {
|
||||
display: none !important;
|
||||
}
|
||||
#app.item-selected #col-item-list {
|
||||
display: none !important;
|
||||
}
|
||||
#app.item-selected #col-item {
|
||||
display: flex !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767.98px) {
|
||||
#app #col-feed-list {
|
||||
width: 100% !important;
|
||||
border-right-width: 0 !important;
|
||||
}
|
||||
#app #col-item-list {
|
||||
width: 100% !important;
|
||||
display: none !important;
|
||||
border-right-width: 0 !important;
|
||||
}
|
||||
#app #col-item {
|
||||
width: 100% !important;
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#app.feed-selected #col-feed-list {
|
||||
display: none !important;
|
||||
}
|
||||
#app.feed-selected #col-item-list {
|
||||
display: flex !important;
|
||||
}
|
||||
|
||||
#app.item-selected #col-feed-list {
|
||||
display: none !important;
|
||||
}
|
||||
#app.item-selected #col-item-list {
|
||||
display: none !important;
|
||||
}
|
||||
#app.item-selected #col-item {
|
||||
display: flex !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* styles for both mobile & tablet layout */
|
||||
|
||||
@media (max-width: 991.98px) {
|
||||
.drag {
|
||||
cursor: default;
|
||||
}
|
||||
.toolbar {
|
||||
min-height: 3rem !important;
|
||||
max-height: 3rem !important;
|
||||
}
|
||||
.toolbar-item,
|
||||
.toolbar-search {
|
||||
padding: .5rem;
|
||||
}
|
||||
}
|
||||
7
src/assets/stylesheets/bootstrap.min.css
vendored
Normal file
1
src/assets/stylesheets/bootstrap.min.css.map
Normal file
110
src/main.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/nkanaev/yarr/platform"
|
||||
"github.com/nkanaev/yarr/server"
|
||||
"github.com/nkanaev/yarr/storage"
|
||||
sdopen "github.com/skratchdot/open-golang/open"
|
||||
)
|
||||
|
||||
var Version string = "0.0"
|
||||
var GitHash string = "unknown"
|
||||
|
||||
func main() {
|
||||
var addr, db, authfile, certfile, keyfile string
|
||||
var ver, open bool
|
||||
flag.StringVar(&addr, "addr", "127.0.0.1:7070", "address to run server on")
|
||||
flag.StringVar(&authfile, "auth-file", "", "path to a file containing username:password")
|
||||
flag.StringVar(&server.BasePath, "base", "", "base path of the service url")
|
||||
flag.StringVar(&certfile, "cert-file", "", "path to cert file for https")
|
||||
flag.StringVar(&keyfile, "key-file", "", "path to key file for https")
|
||||
flag.StringVar(&db, "db", "", "storage file path")
|
||||
flag.BoolVar(&ver, "version", false, "print application version")
|
||||
flag.BoolVar(&open, "open", false, "open the server in browser")
|
||||
flag.Parse()
|
||||
|
||||
if ver {
|
||||
fmt.Printf("v%s (%s)\n", Version, GitHash)
|
||||
return
|
||||
}
|
||||
|
||||
if server.BasePath != "" && !strings.HasPrefix(server.BasePath, "/") {
|
||||
server.BasePath = "/" + server.BasePath
|
||||
}
|
||||
|
||||
if server.BasePath != "" && strings.HasSuffix(server.BasePath, "/") {
|
||||
server.BasePath = strings.TrimSuffix(server.BasePath, "/")
|
||||
}
|
||||
|
||||
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
|
||||
configPath, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
logger.Fatal("Failed to get config dir: ", err)
|
||||
}
|
||||
|
||||
if db == "" {
|
||||
storagePath := filepath.Join(configPath, "yarr")
|
||||
if err := os.MkdirAll(storagePath, 0755); err != nil {
|
||||
logger.Fatal("Failed to create app config dir: ", err)
|
||||
}
|
||||
db = filepath.Join(storagePath, "storage.db")
|
||||
}
|
||||
|
||||
logger.Printf("using db file %s", db)
|
||||
|
||||
var username, password string
|
||||
if authfile != "" {
|
||||
f, err := os.Open(authfile)
|
||||
if err != nil {
|
||||
logger.Fatal("Failed to open auth file: ", err)
|
||||
}
|
||||
defer f.Close()
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
parts := strings.Split(line, ":")
|
||||
if len(parts) != 2 {
|
||||
logger.Fatalf("Invalid auth: %v (expected `username:password`)", line)
|
||||
}
|
||||
username = parts[0]
|
||||
password = parts[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (certfile != "" || keyfile != "") && (certfile == "" || keyfile == "") {
|
||||
logger.Fatalf("Both cert & key files are required")
|
||||
}
|
||||
|
||||
store, err := storage.New(db, logger)
|
||||
if err != nil {
|
||||
logger.Fatal("Failed to initialise database: ", err)
|
||||
}
|
||||
|
||||
srv := server.New(store, logger, addr)
|
||||
|
||||
if certfile != "" && keyfile != "" {
|
||||
srv.CertFile = certfile
|
||||
srv.KeyFile = keyfile
|
||||
}
|
||||
|
||||
if username != "" && password != "" {
|
||||
srv.Username = username
|
||||
srv.Password = password
|
||||
}
|
||||
|
||||
logger.Printf("starting server at %s", srv.GetAddr())
|
||||
if open {
|
||||
sdopen.Run(srv.GetAddr())
|
||||
}
|
||||
platform.Start(srv)
|
||||
}
|
||||
33
src/platform/gui.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// +build macos windows
|
||||
|
||||
package platform
|
||||
|
||||
import (
|
||||
"github.com/getlantern/systray"
|
||||
"github.com/nkanaev/yarr/server"
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
)
|
||||
|
||||
func Start(s *server.Handler) {
|
||||
systrayOnReady := func() {
|
||||
systray.SetIcon(Icon)
|
||||
|
||||
menuOpen := systray.AddMenuItem("Open", "")
|
||||
systray.AddSeparator()
|
||||
menuQuit := systray.AddMenuItem("Quit", "")
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-menuOpen.ClickedCh:
|
||||
open.Run(s.GetAddr())
|
||||
case <-menuQuit.ClickedCh:
|
||||
systray.Quit()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
s.Start()
|
||||
}
|
||||
systray.Run(systrayOnReady, nil)
|
||||
}
|
||||
11
src/platform/guiless.go
Normal file
@@ -0,0 +1,11 @@
|
||||
// +build !windows,!macos
|
||||
|
||||
package platform
|
||||
|
||||
import (
|
||||
"github.com/nkanaev/yarr/server"
|
||||
)
|
||||
|
||||
func Start(s *server.Handler) {
|
||||
s.Start()
|
||||
}
|
||||
BIN
src/platform/icon.ico
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
src/platform/icon.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
100
src/platform/icon.svg
Normal file
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="48"
|
||||
height="48"
|
||||
viewBox="0 0 48 48"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
class="feather feather-anchor"
|
||||
version="1.1"
|
||||
id="svg905"
|
||||
sodipodi:docname="icon.svg"
|
||||
inkscape:version="1.0.1 (c497b03c, 2020-09-10)"
|
||||
inkscape:export-filename="/Users/nkanaev/Desktop/icon.png"
|
||||
inkscape:export-xdpi="2048"
|
||||
inkscape:export-ydpi="2048">
|
||||
<metadata
|
||||
id="metadata911">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs909">
|
||||
<inkscape:perspective
|
||||
sodipodi:type="inkscape:persp3d"
|
||||
inkscape:vp_x="0 : 24 : 1"
|
||||
inkscape:vp_y="0 : 1000 : 0"
|
||||
inkscape:vp_z="48 : 24 : 1"
|
||||
inkscape:persp3d-origin="24 : 16 : 1"
|
||||
id="perspective842" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1440"
|
||||
inkscape:window-height="900"
|
||||
id="namedview907"
|
||||
showgrid="false"
|
||||
inkscape:zoom="4.9128436"
|
||||
inkscape:cx="30.960444"
|
||||
inkscape:cy="52.71331"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="svg905"
|
||||
inkscape:document-rotation="0" />
|
||||
<rect
|
||||
style="fill:#212529;stroke:none;stroke-width:3;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;fill-opacity:1"
|
||||
id="rect913"
|
||||
width="48"
|
||||
height="48"
|
||||
x="0"
|
||||
y="0"
|
||||
ry="24"
|
||||
rx="0" />
|
||||
<g
|
||||
id="g940"
|
||||
transform="matrix(1.4545455,0,0,1.4545455,6.545454,6.545454)"
|
||||
style="fill:none;stroke:#ffffff;stroke-opacity:1">
|
||||
<circle
|
||||
cx="12"
|
||||
cy="5"
|
||||
id="circle899"
|
||||
r="3"
|
||||
style="fill:none;stroke:#ffffff;stroke-opacity:1" />
|
||||
<line
|
||||
x1="12"
|
||||
y1="22"
|
||||
x2="12"
|
||||
y2="8"
|
||||
id="line901"
|
||||
style="fill:none;stroke:#ffffff;stroke-opacity:1" />
|
||||
<path
|
||||
d="M 5,12 H 2 a 10,10 0 0 0 20,0 h -3"
|
||||
id="path903"
|
||||
style="fill:none;stroke:#ffffff;stroke-opacity:1" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
8
src/platform/icon_mac.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// +build macos
|
||||
|
||||
package platform
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed icon.png
|
||||
var Icon []byte
|
||||
8
src/platform/icon_win.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// +build windows
|
||||
|
||||
package platform
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed icon.ico
|
||||
var Icon []byte
|
||||
60
src/server/auth.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func userIsAuthenticated(req *http.Request, username, password string) bool {
|
||||
cookie, _ := req.Cookie("auth")
|
||||
if cookie == nil {
|
||||
return false
|
||||
}
|
||||
parts := strings.Split(cookie.Value, ":")
|
||||
if len(parts) != 2 || !stringsEqual(parts[0], username) {
|
||||
return false
|
||||
}
|
||||
return stringsEqual(parts[1], secret(username, password))
|
||||
}
|
||||
|
||||
func userAuthenticate(rw http.ResponseWriter, username, password string) {
|
||||
expires := time.Now().Add(time.Hour * 24 * 7) // 1 week
|
||||
var cookiePath string
|
||||
if BasePath != "" {
|
||||
cookiePath = BasePath
|
||||
} else {
|
||||
cookiePath = "/"
|
||||
}
|
||||
cookie := http.Cookie{
|
||||
Name: "auth",
|
||||
Value: username + ":" + secret(username, password),
|
||||
Expires: expires,
|
||||
Path: cookiePath,
|
||||
}
|
||||
http.SetCookie(rw, &cookie)
|
||||
}
|
||||
|
||||
func userLogout(rw http.ResponseWriter) {
|
||||
cookie := http.Cookie{
|
||||
Name: "auth",
|
||||
Value: "",
|
||||
MaxAge: -1,
|
||||
}
|
||||
http.SetCookie(rw, &cookie)
|
||||
}
|
||||
|
||||
func stringsEqual(p1, p2 string) bool {
|
||||
return subtle.ConstantTimeCompare([]byte(p1), []byte(p2)) == 1
|
||||
}
|
||||
|
||||
func secret(msg, key string) string {
|
||||
mac := hmac.New(sha256.New, []byte(key))
|
||||
mac.Write([]byte(msg))
|
||||
src := mac.Sum(nil)
|
||||
return hex.EncodeToString(src)
|
||||
}
|
||||
313
src/server/crawler.go
Normal file
@@ -0,0 +1,313 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/mmcdole/gofeed"
|
||||
"github.com/nkanaev/yarr/storage"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FeedSource struct {
|
||||
Title string `json:"title"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
const feedLinks = `
|
||||
link[type='application/rss+xml'],
|
||||
link[type='application/atom+xml'],
|
||||
a[href$="/feed"],
|
||||
a[href$="/feed/"],
|
||||
a[href$="feed.xml"],
|
||||
a[href$="atom.xml"],
|
||||
a[href$="rss.xml"],
|
||||
a:contains("rss"),
|
||||
a:contains("RSS"),
|
||||
a:contains("feed"),
|
||||
a:contains("FEED")
|
||||
`
|
||||
|
||||
type Client struct {
|
||||
httpClient *http.Client
|
||||
userAgent string
|
||||
}
|
||||
|
||||
func (c *Client) get(url string) (*http.Response, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
return c.httpClient.Do(req)
|
||||
}
|
||||
|
||||
func (c *Client) getConditional(url, lastModified, etag string) (*http.Response, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
req.Header.Set("If-Modified-Since", lastModified)
|
||||
req.Header.Set("If-None-Match", etag)
|
||||
return c.httpClient.Do(req)
|
||||
}
|
||||
|
||||
var defaultClient *Client
|
||||
|
||||
func searchFeedLinks(html []byte, siteurl string) ([]FeedSource, error) {
|
||||
sources := make([]FeedSource, 0, 0)
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(html))
|
||||
if err != nil {
|
||||
return sources, err
|
||||
}
|
||||
base, err := url.Parse(siteurl)
|
||||
if err != nil {
|
||||
return sources, err
|
||||
}
|
||||
|
||||
// feed {url: title} map
|
||||
feeds := make(map[string]string)
|
||||
|
||||
doc.Find(feedLinks).Each(func(i int, s *goquery.Selection) {
|
||||
// Unlikely to happen, but don't get more than N links
|
||||
if len(feeds) > 10 {
|
||||
return
|
||||
}
|
||||
if href, ok := s.Attr("href"); ok {
|
||||
feedUrl, err := url.Parse(href)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
title := s.AttrOr("title", "")
|
||||
url := base.ResolveReference(feedUrl).String()
|
||||
|
||||
if _, alreadyExists := feeds[url]; alreadyExists {
|
||||
if feeds[url] == "" {
|
||||
feeds[url] = title
|
||||
}
|
||||
} else {
|
||||
feeds[url] = title
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
for url, title := range feeds {
|
||||
sources = append(sources, FeedSource{Title: title, Url: url})
|
||||
}
|
||||
return sources, nil
|
||||
}
|
||||
|
||||
func discoverFeed(candidateUrl string) (*gofeed.Feed, *[]FeedSource, error) {
|
||||
// Query URL
|
||||
res, err := defaultClient.get(candidateUrl)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
errmsg := fmt.Sprintf("Failed to fetch feed %s (status: %d)", candidateUrl, res.StatusCode)
|
||||
return nil, nil, errors.New(errmsg)
|
||||
}
|
||||
content, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Try to feed into parser
|
||||
feedparser := gofeed.NewParser()
|
||||
feed, err := feedparser.Parse(bytes.NewReader(content))
|
||||
if err == nil {
|
||||
// WILD: feeds may not always have link to themselves
|
||||
if len(feed.FeedLink) == 0 {
|
||||
feed.FeedLink = candidateUrl
|
||||
}
|
||||
|
||||
// WILD: resolve relative links (path, without host)
|
||||
base, _ := url.Parse(candidateUrl)
|
||||
if link, err := url.Parse(feed.Link); err == nil && link.Host == "" {
|
||||
feed.Link = base.ResolveReference(link).String()
|
||||
}
|
||||
if link, err := url.Parse(feed.FeedLink); err == nil && link.Host == "" {
|
||||
feed.FeedLink = base.ResolveReference(link).String()
|
||||
}
|
||||
|
||||
return feed, nil, nil
|
||||
}
|
||||
|
||||
// Possibly an html link. Search for feed links
|
||||
sources, err := searchFeedLinks(content, candidateUrl)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
} else if len(sources) == 0 {
|
||||
return nil, nil, errors.New("No feeds found at the given url")
|
||||
} else if len(sources) == 1 {
|
||||
if sources[0].Url == candidateUrl {
|
||||
return nil, nil, errors.New("Recursion!")
|
||||
}
|
||||
return discoverFeed(sources[0].Url)
|
||||
}
|
||||
return nil, &sources, nil
|
||||
}
|
||||
|
||||
func findFavicon(websiteUrl, feedUrl string) (*[]byte, error) {
|
||||
candidateUrls := make([]string, 0)
|
||||
|
||||
favicon := func(link string) string {
|
||||
u, err := url.Parse(link)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s://%s/favicon.ico", u.Scheme, u.Host)
|
||||
}
|
||||
|
||||
if len(websiteUrl) != 0 {
|
||||
base, err := url.Parse(websiteUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := defaultClient.get(websiteUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc.Find(`link[rel=icon]`).EachWithBreak(func(i int, s *goquery.Selection) bool {
|
||||
if href, ok := s.Attr("href"); ok {
|
||||
if hrefUrl, err := url.Parse(href); err == nil {
|
||||
faviconUrl := base.ResolveReference(hrefUrl).String()
|
||||
candidateUrls = append(candidateUrls, faviconUrl)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if c := favicon(websiteUrl); len(c) != 0 {
|
||||
candidateUrls = append(candidateUrls, c)
|
||||
}
|
||||
}
|
||||
if c := favicon(feedUrl); len(c) != 0 {
|
||||
candidateUrls = append(candidateUrls, c)
|
||||
}
|
||||
|
||||
imageTypes := [4]string{
|
||||
"image/x-icon",
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/gif",
|
||||
}
|
||||
for _, url := range candidateUrls {
|
||||
res, err := defaultClient.get(url)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode == 200 {
|
||||
if content, err := ioutil.ReadAll(res.Body); err == nil {
|
||||
ctype := http.DetectContentType(content)
|
||||
for _, itype := range imageTypes {
|
||||
if ctype == itype {
|
||||
return &content, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func convertItems(items []*gofeed.Item, feed storage.Feed) []storage.Item {
|
||||
result := make([]storage.Item, len(items))
|
||||
for i, item := range items {
|
||||
imageURL := ""
|
||||
if item.Image != nil {
|
||||
imageURL = item.Image.URL
|
||||
}
|
||||
author := ""
|
||||
if item.Author != nil {
|
||||
author = item.Author.Name
|
||||
}
|
||||
result[i] = storage.Item{
|
||||
GUID: item.GUID,
|
||||
FeedId: feed.Id,
|
||||
Title: item.Title,
|
||||
Link: item.Link,
|
||||
Description: item.Description,
|
||||
Content: item.Content,
|
||||
Author: author,
|
||||
Date: item.PublishedParsed,
|
||||
DateUpdated: item.UpdatedParsed,
|
||||
Status: storage.UNREAD,
|
||||
Image: imageURL,
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func listItems(f storage.Feed, db *storage.Storage) ([]storage.Item, error) {
|
||||
var res *http.Response
|
||||
var err error
|
||||
|
||||
httpState := db.GetHTTPState(f.Id)
|
||||
if httpState != nil {
|
||||
res, err = defaultClient.getConditional(f.FeedLink, httpState.LastModified, httpState.Etag)
|
||||
} else {
|
||||
res, err = defaultClient.get(f.FeedLink)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode/100 == 4 || res.StatusCode/100 == 5 {
|
||||
errmsg := fmt.Sprintf("Failed to list feed items for %s (status: %d)", f.FeedLink, res.StatusCode)
|
||||
return nil, errors.New(errmsg)
|
||||
}
|
||||
|
||||
if res.StatusCode == 304 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
lastModified := res.Header.Get("Last-Modified")
|
||||
etag := res.Header.Get("Etag")
|
||||
if lastModified != "" || etag != "" {
|
||||
db.SetHTTPState(f.Id, lastModified, etag)
|
||||
}
|
||||
|
||||
feedparser := gofeed.NewParser()
|
||||
feed, err := feedparser.Parse(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertItems(feed.Items, f), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
transport := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 10 * time.Second,
|
||||
}).DialContext,
|
||||
DisableKeepAlives: true,
|
||||
TLSHandshakeTimeout: time.Second * 10,
|
||||
}
|
||||
httpClient := &http.Client{
|
||||
Timeout: time.Second * 30,
|
||||
Transport: transport,
|
||||
}
|
||||
defaultClient = &Client{
|
||||
httpClient: httpClient,
|
||||
userAgent: "Yarr/1.0",
|
||||
}
|
||||
}
|
||||
477
src/server/handlers.go
Normal file
@@ -0,0 +1,477 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/nkanaev/yarr/storage"
|
||||
"github.com/nkanaev/yarr/assets"
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TODO: gzip?
|
||||
var StaticHandler = http.StripPrefix("/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP
|
||||
|
||||
var routes []Route = []Route{
|
||||
p("/", IndexHandler).ManualAuth(),
|
||||
p("/static/*path", StaticHandler).ManualAuth(),
|
||||
|
||||
p("/api/status", StatusHandler),
|
||||
p("/api/folders", FolderListHandler),
|
||||
p("/api/folders/:id", FolderHandler),
|
||||
p("/api/feeds", FeedListHandler),
|
||||
p("/api/feeds/find", FeedHandler),
|
||||
p("/api/feeds/refresh", FeedRefreshHandler),
|
||||
p("/api/feeds/errors", FeedErrorsHandler),
|
||||
p("/api/feeds/:id/icon", FeedIconHandler),
|
||||
p("/api/feeds/:id", FeedHandler),
|
||||
p("/api/items", ItemListHandler),
|
||||
p("/api/items/:id", ItemHandler),
|
||||
p("/api/settings", SettingsHandler),
|
||||
p("/opml/import", OPMLImportHandler),
|
||||
p("/opml/export", OPMLExportHandler),
|
||||
p("/page", PageCrawlHandler),
|
||||
p("/logout", LogoutHandler),
|
||||
}
|
||||
|
||||
type FolderCreateForm struct {
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type FolderUpdateForm struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
IsExpanded *bool `json:"is_expanded,omitempty"`
|
||||
}
|
||||
|
||||
type FeedCreateForm struct {
|
||||
Url string `json:"url"`
|
||||
FolderID *int64 `json:"folder_id,omitempty"`
|
||||
}
|
||||
|
||||
type ItemUpdateForm struct {
|
||||
Status *storage.ItemStatus `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
h := handler(req)
|
||||
if h.requiresAuth() && !userIsAuthenticated(req, h.Username, h.Password) {
|
||||
if req.Method == "POST" {
|
||||
username := req.FormValue("username")
|
||||
password := req.FormValue("password")
|
||||
if stringsEqual(username, h.Username) && stringsEqual(password, h.Password) {
|
||||
userAuthenticate(rw, username, password)
|
||||
http.Redirect(rw, req, req.URL.Path, http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
rw.Header().Set("Content-Type", "text/html")
|
||||
assets.Render("login.html", rw, nil)
|
||||
return
|
||||
}
|
||||
rw.Header().Set("Content-Type", "text/html")
|
||||
assets.Render("index.html", rw, nil)
|
||||
}
|
||||
|
||||
/*
|
||||
func StaticHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
http.StripPrefix("/static/", http.FileServer(http.FS(assets.FS))).ServeHTTP(rw, req)
|
||||
ctype := mime.TypeByExtension(filepath.Ext(path))
|
||||
|
||||
if assets != nil {
|
||||
if asset, ok := assets[path]; ok {
|
||||
if req.Header.Get("if-none-match") == asset.etag {
|
||||
rw.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
rw.Header().Set("Content-Type", ctype)
|
||||
rw.Header().Set("Content-Encoding", "gzip")
|
||||
rw.Header().Set("Etag", asset.etag)
|
||||
rw.Write(*asset.gzip())
|
||||
}
|
||||
}
|
||||
|
||||
f, err := os.Open("assets/" + path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
rw.Header().Set("Content-Type", ctype)
|
||||
io.Copy(rw, f)
|
||||
}
|
||||
*/
|
||||
|
||||
func StatusHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
writeJSON(rw, map[string]interface{}{
|
||||
"running": *handler(req).queueSize,
|
||||
"stats": db(req).FeedStats(),
|
||||
})
|
||||
}
|
||||
|
||||
func FolderListHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "GET" {
|
||||
list := db(req).ListFolders()
|
||||
writeJSON(rw, list)
|
||||
} else if req.Method == "POST" {
|
||||
var body FolderCreateForm
|
||||
if err := json.NewDecoder(req.Body).Decode(&body); err != nil {
|
||||
handler(req).log.Print(err)
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if len(body.Title) == 0 {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
writeJSON(rw, map[string]string{"error": "Folder title missing."})
|
||||
return
|
||||
}
|
||||
folder := db(req).CreateFolder(body.Title)
|
||||
rw.WriteHeader(http.StatusCreated)
|
||||
writeJSON(rw, folder)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func FolderHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
id, err := strconv.ParseInt(Vars(req)["id"], 10, 64)
|
||||
if err != nil {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if req.Method == "PUT" {
|
||||
var body FolderUpdateForm
|
||||
if err := json.NewDecoder(req.Body).Decode(&body); err != nil {
|
||||
handler(req).log.Print(err)
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if body.Title != nil {
|
||||
db(req).RenameFolder(id, *body.Title)
|
||||
}
|
||||
if body.IsExpanded != nil {
|
||||
db(req).ToggleFolderExpanded(id, *body.IsExpanded)
|
||||
}
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
} else if req.Method == "DELETE" {
|
||||
db(req).DeleteFolder(id)
|
||||
rw.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
|
||||
func FeedRefreshHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "POST" {
|
||||
handler(req).fetchAllFeeds()
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func FeedErrorsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
errors := db(req).GetFeedErrors()
|
||||
writeJSON(rw, errors)
|
||||
}
|
||||
|
||||
func FeedIconHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
id, err := strconv.ParseInt(Vars(req)["id"], 10, 64)
|
||||
if err != nil {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
feed := db(req).GetFeed(id)
|
||||
if feed != nil && feed.Icon != nil {
|
||||
rw.Header().Set("Content-Type", http.DetectContentType(*feed.Icon))
|
||||
rw.Header().Set("Content-Length", strconv.Itoa(len(*feed.Icon)))
|
||||
rw.Write(*feed.Icon)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
func FeedListHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "GET" {
|
||||
list := db(req).ListFeeds()
|
||||
writeJSON(rw, list)
|
||||
} else if req.Method == "POST" {
|
||||
var form FeedCreateForm
|
||||
if err := json.NewDecoder(req.Body).Decode(&form); err != nil {
|
||||
handler(req).log.Print(err)
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
feed, sources, err := discoverFeed(form.Url)
|
||||
if err != nil {
|
||||
handler(req).log.Print(err)
|
||||
writeJSON(rw, map[string]string{"status": "notfound"})
|
||||
return
|
||||
}
|
||||
|
||||
if feed != nil {
|
||||
storedFeed := db(req).CreateFeed(
|
||||
feed.Title,
|
||||
feed.Description,
|
||||
feed.Link,
|
||||
feed.FeedLink,
|
||||
form.FolderID,
|
||||
)
|
||||
db(req).CreateItems(convertItems(feed.Items, *storedFeed))
|
||||
|
||||
icon, err := findFavicon(storedFeed.Link, storedFeed.FeedLink)
|
||||
if icon != nil {
|
||||
db(req).UpdateFeedIcon(storedFeed.Id, icon)
|
||||
}
|
||||
if err != nil {
|
||||
handler(req).log.Printf("Failed to find favicon for %s (%d): %s", storedFeed.FeedLink, storedFeed.Id, err)
|
||||
}
|
||||
|
||||
writeJSON(rw, map[string]string{"status": "success"})
|
||||
} else if sources != nil {
|
||||
writeJSON(rw, map[string]interface{}{"status": "multiple", "choice": sources})
|
||||
} else {
|
||||
writeJSON(rw, map[string]string{"status": "notfound"})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FeedHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
id, err := strconv.ParseInt(Vars(req)["id"], 10, 64)
|
||||
if err != nil {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if req.Method == "PUT" {
|
||||
feed := db(req).GetFeed(id)
|
||||
if feed == nil {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
body := make(map[string]interface{})
|
||||
if err := json.NewDecoder(req.Body).Decode(&body); err != nil {
|
||||
handler(req).log.Print(err)
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if title, ok := body["title"]; ok {
|
||||
if reflect.TypeOf(title).Kind() == reflect.String {
|
||||
db(req).RenameFeed(id, title.(string))
|
||||
}
|
||||
}
|
||||
if f_id, ok := body["folder_id"]; ok {
|
||||
if f_id == nil {
|
||||
db(req).UpdateFeedFolder(id, nil)
|
||||
} else if reflect.TypeOf(f_id).Kind() == reflect.Float64 {
|
||||
folderId := int64(f_id.(float64))
|
||||
db(req).UpdateFeedFolder(id, &folderId)
|
||||
}
|
||||
}
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
} else if req.Method == "DELETE" {
|
||||
db(req).DeleteFeed(id)
|
||||
rw.WriteHeader(http.StatusNoContent)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func ItemHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "PUT" {
|
||||
id, err := strconv.ParseInt(Vars(req)["id"], 10, 64)
|
||||
if err != nil {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var body ItemUpdateForm
|
||||
if err := json.NewDecoder(req.Body).Decode(&body); err != nil {
|
||||
handler(req).log.Print(err)
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if body.Status != nil {
|
||||
db(req).UpdateItemStatus(id, *body.Status)
|
||||
}
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func ItemListHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "GET" {
|
||||
perPage := 20
|
||||
curPage := 1
|
||||
query := req.URL.Query()
|
||||
if page, err := strconv.ParseInt(query.Get("page"), 10, 64); err == nil {
|
||||
curPage = int(page)
|
||||
}
|
||||
filter := storage.ItemFilter{}
|
||||
if folderID, err := strconv.ParseInt(query.Get("folder_id"), 10, 64); err == nil {
|
||||
filter.FolderID = &folderID
|
||||
}
|
||||
if feedID, err := strconv.ParseInt(query.Get("feed_id"), 10, 64); err == nil {
|
||||
filter.FeedID = &feedID
|
||||
}
|
||||
if status := query.Get("status"); len(status) != 0 {
|
||||
statusValue := storage.StatusValues[status]
|
||||
filter.Status = &statusValue
|
||||
}
|
||||
if search := query.Get("search"); len(search) != 0 {
|
||||
filter.Search = &search
|
||||
}
|
||||
newestFirst := query.Get("oldest_first") != "true"
|
||||
items := db(req).ListItems(filter, (curPage-1)*perPage, perPage, newestFirst)
|
||||
count := db(req).CountItems(filter)
|
||||
writeJSON(rw, map[string]interface{}{
|
||||
"page": map[string]int{
|
||||
"cur": curPage,
|
||||
"num": int(math.Ceil(float64(count) / float64(perPage))),
|
||||
},
|
||||
"list": items,
|
||||
})
|
||||
} else if req.Method == "PUT" {
|
||||
query := req.URL.Query()
|
||||
filter := storage.MarkFilter{}
|
||||
if folderID, err := strconv.ParseInt(query.Get("folder_id"), 10, 64); err == nil {
|
||||
filter.FolderID = &folderID
|
||||
}
|
||||
if feedID, err := strconv.ParseInt(query.Get("feed_id"), 10, 64); err == nil {
|
||||
filter.FeedID = &feedID
|
||||
}
|
||||
db(req).MarkItemsRead(filter)
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func SettingsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "GET" {
|
||||
writeJSON(rw, db(req).GetSettings())
|
||||
} else if req.Method == "PUT" {
|
||||
settings := make(map[string]interface{})
|
||||
if err := json.NewDecoder(req.Body).Decode(&settings); err != nil {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if db(req).UpdateSettings(settings) {
|
||||
if _, ok := settings["refresh_rate"]; ok {
|
||||
handler(req).refreshRate <- db(req).GetSettingsValueInt64("refresh_rate")
|
||||
}
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func OPMLImportHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "POST" {
|
||||
file, _, err := req.FormFile("opml")
|
||||
if err != nil {
|
||||
handler(req).log.Print(err)
|
||||
return
|
||||
}
|
||||
doc, err := parseOPML(file)
|
||||
if err != nil {
|
||||
handler(req).log.Print(err)
|
||||
return
|
||||
}
|
||||
for _, outline := range doc.Outlines {
|
||||
if outline.Type == "rss" {
|
||||
db(req).CreateFeed(outline.Title, outline.Description, outline.SiteURL, outline.FeedURL, nil)
|
||||
} else {
|
||||
folder := db(req).CreateFolder(outline.Title)
|
||||
for _, o := range outline.AllFeeds() {
|
||||
db(req).CreateFeed(o.Title, o.Description, o.SiteURL, o.FeedURL, &folder.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
handler(req).fetchAllFeeds()
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func OPMLExportHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "GET" {
|
||||
rw.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
rw.Header().Set("Content-Disposition", `attachment; filename="subscriptions.opml"`)
|
||||
|
||||
builder := strings.Builder{}
|
||||
|
||||
line := func(s string, args ...string) {
|
||||
if len(args) > 0 {
|
||||
escapedargs := make([]interface{}, len(args))
|
||||
for idx, arg := range args {
|
||||
escapedargs[idx] = html.EscapeString(arg)
|
||||
}
|
||||
s = fmt.Sprintf(s, escapedargs...)
|
||||
}
|
||||
builder.WriteString(s)
|
||||
builder.WriteString("\n")
|
||||
}
|
||||
|
||||
feedline := func(feed storage.Feed, indent int) {
|
||||
line(
|
||||
strings.Repeat(" ", indent)+
|
||||
`<outline type="rss" text="%s" description="%s" xmlUrl="%s" htmlUrl="%s"/>`,
|
||||
feed.Title, feed.Description,
|
||||
feed.FeedLink, feed.Link,
|
||||
)
|
||||
}
|
||||
line(`<?xml version="1.0" encoding="UTF-8"?>`)
|
||||
line(`<opml version="1.1">`)
|
||||
line(`<head>`)
|
||||
line(` <title>subscriptions.opml</title>`)
|
||||
line(`</head>`)
|
||||
line(`<body>`)
|
||||
feedsByFolderID := make(map[int64][]storage.Feed)
|
||||
for _, feed := range db(req).ListFeeds() {
|
||||
var folderId = int64(0)
|
||||
if feed.FolderId != nil {
|
||||
folderId = *feed.FolderId
|
||||
}
|
||||
if feedsByFolderID[folderId] == nil {
|
||||
feedsByFolderID[folderId] = make([]storage.Feed, 0)
|
||||
}
|
||||
feedsByFolderID[folderId] = append(feedsByFolderID[folderId], feed)
|
||||
}
|
||||
for _, folder := range db(req).ListFolders() {
|
||||
line(` <outline text="%s">`, folder.Title)
|
||||
for _, feed := range feedsByFolderID[folder.Id] {
|
||||
feedline(feed, 4)
|
||||
}
|
||||
line(` </outline>`)
|
||||
}
|
||||
for _, feed := range feedsByFolderID[0] {
|
||||
feedline(feed, 2)
|
||||
}
|
||||
line(`</body>`)
|
||||
line(`</opml>`)
|
||||
rw.Write([]byte(builder.String()))
|
||||
}
|
||||
}
|
||||
|
||||
func PageCrawlHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
query := req.URL.Query()
|
||||
if url := query.Get("url"); len(url) > 0 {
|
||||
res, err := http.Get(url)
|
||||
if err == nil {
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err == nil {
|
||||
rw.Write(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func LogoutHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
userLogout(rw)
|
||||
rw.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
42
src/server/opml.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
)
|
||||
|
||||
type opml struct {
|
||||
XMLName xml.Name `xml:"opml"`
|
||||
Version string `xml:"version,attr"`
|
||||
Outlines []outline `xml:"body>outline"`
|
||||
}
|
||||
|
||||
type outline struct {
|
||||
Type string `xml:"type,attr,omitempty"`
|
||||
Title string `xml:"text,attr"`
|
||||
FeedURL string `xml:"xmlUrl,attr,omitempty"`
|
||||
SiteURL string `xml:"htmlUrl,attr,omitempty"`
|
||||
Description string `xml:"description,attr,omitempty"`
|
||||
Outlines []outline `xml:"outline,omitempty"`
|
||||
}
|
||||
|
||||
func (o outline) AllFeeds() []outline {
|
||||
result := make([]outline, 0)
|
||||
for _, sub := range o.Outlines {
|
||||
if sub.Type == "rss" {
|
||||
result = append(result, sub)
|
||||
} else {
|
||||
result = append(result, sub.AllFeeds()...)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func parseOPML(r io.Reader) (*opml, error) {
|
||||
feeds := new(opml)
|
||||
decoder := xml.NewDecoder(r)
|
||||
decoder.Entity = xml.HTMLEntity
|
||||
decoder.Strict = false
|
||||
err := decoder.Decode(&feeds)
|
||||
return feeds, err
|
||||
}
|
||||
17
src/server/response.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func writeJSON(rw http.ResponseWriter, data interface{}) {
|
||||
rw.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
reply, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
rw.Write(reply)
|
||||
rw.Write([]byte("\n"))
|
||||
}
|
||||
50
src/server/router.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var BasePath string = ""
|
||||
|
||||
type Route struct {
|
||||
url string
|
||||
urlRegex *regexp.Regexp
|
||||
handler func(http.ResponseWriter, *http.Request)
|
||||
manualAuth bool
|
||||
}
|
||||
|
||||
func (r Route) ManualAuth() Route {
|
||||
r.manualAuth = true
|
||||
return r
|
||||
}
|
||||
|
||||
func p(path string, handler http.HandlerFunc) Route {
|
||||
var urlRegexp string
|
||||
urlRegexp = regexp.MustCompile(`[\*\:]\w+`).ReplaceAllStringFunc(path, func(m string) string {
|
||||
if m[0:1] == `*` {
|
||||
return "(?P<" + m[1:] + ">.+)"
|
||||
}
|
||||
return "(?P<" + m[1:] + ">[^/]+)"
|
||||
})
|
||||
urlRegexp = "^" + urlRegexp + "$"
|
||||
return Route{
|
||||
url: path,
|
||||
urlRegex: regexp.MustCompile(urlRegexp),
|
||||
handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func getRoute(reqPath string) (*Route, map[string]string) {
|
||||
vars := make(map[string]string)
|
||||
for _, route := range routes {
|
||||
if route.urlRegex.MatchString(reqPath) {
|
||||
matches := route.urlRegex.FindStringSubmatchIndex(reqPath)
|
||||
for i, key := range route.urlRegex.SubexpNames()[1:] {
|
||||
vars[key] = reqPath[matches[i*2+2]:matches[i*2+3]]
|
||||
}
|
||||
return &route, vars
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
226
src/server/server.go
Normal file
@@ -0,0 +1,226 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/nkanaev/yarr/storage"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
Addr string
|
||||
db *storage.Storage
|
||||
log *log.Logger
|
||||
feedQueue chan storage.Feed
|
||||
queueSize *int32
|
||||
refreshRate chan int64
|
||||
// auth
|
||||
Username string
|
||||
Password string
|
||||
// https
|
||||
CertFile string
|
||||
KeyFile string
|
||||
}
|
||||
|
||||
func New(db *storage.Storage, logger *log.Logger, addr string) *Handler {
|
||||
queueSize := int32(0)
|
||||
return &Handler{
|
||||
db: db,
|
||||
log: logger,
|
||||
feedQueue: make(chan storage.Feed, 3000),
|
||||
queueSize: &queueSize,
|
||||
Addr: addr,
|
||||
refreshRate: make(chan int64),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) GetAddr() string {
|
||||
proto := "http"
|
||||
if h.CertFile != "" && h.KeyFile != "" {
|
||||
proto = "https"
|
||||
}
|
||||
return proto + "://" + h.Addr + BasePath
|
||||
}
|
||||
|
||||
func (h *Handler) Start() {
|
||||
h.startJobs()
|
||||
s := &http.Server{Addr: h.Addr, Handler: h}
|
||||
|
||||
var err error
|
||||
if h.CertFile != "" && h.KeyFile != "" {
|
||||
err = s.ListenAndServeTLS(h.CertFile, h.KeyFile)
|
||||
} else {
|
||||
err = s.ListenAndServe()
|
||||
}
|
||||
if err != http.ErrServerClosed {
|
||||
h.log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func unsafeMethod(method string) bool {
|
||||
return method == "POST" || method == "PUT" || method == "DELETE"
|
||||
}
|
||||
|
||||
func (h Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
reqPath := req.URL.Path
|
||||
if BasePath != "" {
|
||||
if !strings.HasPrefix(reqPath, BasePath) {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
reqPath = strings.TrimPrefix(req.URL.Path, BasePath)
|
||||
if reqPath == "" {
|
||||
http.Redirect(rw, req, BasePath+"/", http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
route, vars := getRoute(reqPath)
|
||||
if route == nil {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
if h.requiresAuth() && !route.manualAuth {
|
||||
if unsafeMethod(req.Method) && req.Header.Get("X-Requested-By") != "yarr" {
|
||||
rw.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
if !userIsAuthenticated(req, h.Username, h.Password) {
|
||||
rw.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx := context.WithValue(req.Context(), ctxHandler, &h)
|
||||
ctx = context.WithValue(ctx, ctxVars, vars)
|
||||
route.handler(rw, req.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (h *Handler) startJobs() {
|
||||
delTicker := time.NewTicker(time.Hour * 24)
|
||||
|
||||
syncSearchChannel := make(chan bool, 10)
|
||||
var syncSearchTimer *time.Timer // TODO: should this be atomic?
|
||||
|
||||
syncSearch := func() {
|
||||
if syncSearchTimer == nil {
|
||||
syncSearchTimer = time.AfterFunc(time.Second*2, func() {
|
||||
syncSearchChannel <- true
|
||||
})
|
||||
} else {
|
||||
syncSearchTimer.Reset(time.Second * 2)
|
||||
}
|
||||
}
|
||||
|
||||
worker := func() {
|
||||
for {
|
||||
select {
|
||||
case feed := <-h.feedQueue:
|
||||
items, err := listItems(feed, h.db)
|
||||
atomic.AddInt32(h.queueSize, -1)
|
||||
if err != nil {
|
||||
h.log.Printf("Failed to fetch %s (%d): %s", feed.FeedLink, feed.Id, err)
|
||||
h.db.SetFeedError(feed.Id, err)
|
||||
continue
|
||||
}
|
||||
h.db.CreateItems(items)
|
||||
syncSearch()
|
||||
if !feed.HasIcon {
|
||||
icon, err := findFavicon(feed.Link, feed.FeedLink)
|
||||
if icon != nil {
|
||||
h.db.UpdateFeedIcon(feed.Id, icon)
|
||||
}
|
||||
if err != nil {
|
||||
h.log.Printf("Failed to search favicon for %s (%s): %s", feed.Link, feed.FeedLink, err)
|
||||
}
|
||||
}
|
||||
case <-delTicker.C:
|
||||
h.db.DeleteOldItems()
|
||||
case <-syncSearchChannel:
|
||||
h.db.SyncSearch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
num := runtime.NumCPU() - 1
|
||||
if num < 1 {
|
||||
num = 1
|
||||
}
|
||||
for i := 0; i < num; i++ {
|
||||
go worker()
|
||||
}
|
||||
go h.db.DeleteOldItems()
|
||||
go h.db.SyncSearch()
|
||||
|
||||
go func() {
|
||||
var refreshTicker *time.Ticker
|
||||
refreshTick := make(<-chan time.Time)
|
||||
for {
|
||||
select {
|
||||
case <-refreshTick:
|
||||
h.fetchAllFeeds()
|
||||
case val := <-h.refreshRate:
|
||||
if refreshTicker != nil {
|
||||
refreshTicker.Stop()
|
||||
if val == 0 {
|
||||
refreshTick = make(<-chan time.Time)
|
||||
}
|
||||
}
|
||||
if val > 0 {
|
||||
refreshTicker = time.NewTicker(time.Duration(val) * time.Minute)
|
||||
refreshTick = refreshTicker.C
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
refreshRate := h.db.GetSettingsValueInt64("refresh_rate")
|
||||
h.refreshRate <- refreshRate
|
||||
if refreshRate > 0 {
|
||||
h.fetchAllFeeds()
|
||||
}
|
||||
}
|
||||
|
||||
func (h Handler) requiresAuth() bool {
|
||||
return h.Username != "" && h.Password != ""
|
||||
}
|
||||
|
||||
func (h *Handler) fetchAllFeeds() {
|
||||
h.log.Print("Refreshing all feeds")
|
||||
h.db.ResetFeedErrors()
|
||||
for _, feed := range h.db.ListFeeds() {
|
||||
h.fetchFeed(feed)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) fetchFeed(feed storage.Feed) {
|
||||
atomic.AddInt32(h.queueSize, 1)
|
||||
h.feedQueue <- feed
|
||||
}
|
||||
|
||||
func Vars(req *http.Request) map[string]string {
|
||||
if rv := req.Context().Value(ctxVars); rv != nil {
|
||||
return rv.(map[string]string)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func db(req *http.Request) *storage.Storage {
|
||||
if h := handler(req); h != nil {
|
||||
return h.db
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handler(req *http.Request) *Handler {
|
||||
return req.Context().Value(ctxHandler).(*Handler)
|
||||
}
|
||||
|
||||
const (
|
||||
ctxVars = 2
|
||||
ctxHandler = 3
|
||||
)
|
||||
172
src/storage/feed.go
Normal file
@@ -0,0 +1,172 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"html"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
Id int64 `json:"id"`
|
||||
FolderId *int64 `json:"folder_id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Link string `json:"link"`
|
||||
FeedLink string `json:"feed_link"`
|
||||
Icon *[]byte `json:"icon,omitempty"`
|
||||
HasIcon bool `json:"has_icon"`
|
||||
}
|
||||
|
||||
func (s *Storage) CreateFeed(title, description, link, feedLink string, folderId *int64) *Feed {
|
||||
title = html.UnescapeString(title)
|
||||
// WILD: fallback to `feed.link` -> `feed.feed_link` -> "<???>" if title is missing
|
||||
if title == "" {
|
||||
title = link
|
||||
// use domain if possible
|
||||
linkUrl, err := url.Parse(link)
|
||||
if err == nil && linkUrl.Host != "" && len(linkUrl.Path) <= 1 {
|
||||
title = linkUrl.Host
|
||||
}
|
||||
}
|
||||
if title == "" {
|
||||
title = feedLink
|
||||
}
|
||||
if title == "" {
|
||||
title = "<???>"
|
||||
}
|
||||
result, err := s.db.Exec(`
|
||||
insert into feeds (title, description, link, feed_link, folder_id)
|
||||
values (?, ?, ?, ?, ?)
|
||||
on conflict (feed_link) do update set folder_id=?`,
|
||||
title, description, link, feedLink, folderId,
|
||||
folderId,
|
||||
)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
id, idErr := result.LastInsertId()
|
||||
if idErr != nil {
|
||||
return nil
|
||||
}
|
||||
return &Feed{
|
||||
Id: id,
|
||||
Title: title,
|
||||
Description: description,
|
||||
Link: link,
|
||||
FeedLink: feedLink,
|
||||
FolderId: folderId,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteFeed(feedId int64) bool {
|
||||
_, err1 := s.db.Exec(`delete from items where feed_id = ?`, feedId)
|
||||
_, err2 := s.db.Exec(`delete from feeds where id = ?`, feedId)
|
||||
return err1 == nil && err2 == nil
|
||||
}
|
||||
|
||||
func (s *Storage) RenameFeed(feedId int64, newTitle string) bool {
|
||||
_, err := s.db.Exec(`update feeds set title = ? where id = ?`, newTitle, feedId)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (s *Storage) UpdateFeedFolder(feedId int64, newFolderId *int64) bool {
|
||||
_, err := s.db.Exec(`update feeds set folder_id = ? where id = ?`, newFolderId, feedId)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (s *Storage) UpdateFeedIcon(feedId int64, icon *[]byte) bool {
|
||||
_, err := s.db.Exec(`update feeds set icon = ? where id = ?`, icon, feedId)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (s *Storage) ListFeeds() []Feed {
|
||||
result := make([]Feed, 0, 0)
|
||||
rows, err := s.db.Query(`
|
||||
select id, folder_id, title, description, link, feed_link,
|
||||
ifnull(icon, '') != '' as has_icon
|
||||
from feeds
|
||||
order by title collate nocase
|
||||
`)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
for rows.Next() {
|
||||
var f Feed
|
||||
err = rows.Scan(
|
||||
&f.Id,
|
||||
&f.FolderId,
|
||||
&f.Title,
|
||||
&f.Description,
|
||||
&f.Link,
|
||||
&f.FeedLink,
|
||||
&f.HasIcon,
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
result = append(result, f)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *Storage) GetFeed(id int64) *Feed {
|
||||
row := s.db.QueryRow(`
|
||||
select id, folder_id, title, description, link, feed_link, icon,
|
||||
ifnull(icon, '') != '' as has_icon
|
||||
from feeds where id = ?
|
||||
`, id)
|
||||
if row != nil {
|
||||
var f Feed
|
||||
row.Scan(
|
||||
&f.Id,
|
||||
&f.FolderId,
|
||||
&f.Title,
|
||||
&f.Description,
|
||||
&f.Link,
|
||||
&f.FeedLink,
|
||||
&f.Icon,
|
||||
&f.HasIcon,
|
||||
)
|
||||
return &f
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Storage) ResetFeedErrors() {
|
||||
if _, err := s.db.Exec(`delete from feed_errors`); err != nil {
|
||||
s.log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) SetFeedError(feedID int64, lastError error) {
|
||||
_, err := s.db.Exec(`
|
||||
insert into feed_errors (feed_id, error)
|
||||
values (?, ?)
|
||||
on conflict (feed_id) do update set error = excluded.error`,
|
||||
feedID, lastError.Error(),
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) GetFeedErrors() map[int64]string {
|
||||
errors := make(map[int64]string)
|
||||
|
||||
rows, err := s.db.Query(`select feed_id, error from feed_errors`)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return errors
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
var error string
|
||||
if err = rows.Scan(&id, &error); err != nil {
|
||||
s.log.Print(err)
|
||||
}
|
||||
errors[id] = error
|
||||
}
|
||||
return errors
|
||||
}
|
||||
84
src/storage/folder.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Folder struct {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
IsExpanded bool `json:"is_expanded"`
|
||||
}
|
||||
|
||||
func (s *Storage) CreateFolder(title string) *Folder {
|
||||
expanded := true
|
||||
result, err := s.db.Exec(`
|
||||
insert into folders (title, is_expanded) values (?, ?)
|
||||
on conflict (title) do nothing`,
|
||||
title, expanded,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
var id int64
|
||||
numrows, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return nil
|
||||
}
|
||||
if numrows == 1 {
|
||||
id, err = result.LastInsertId()
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
err = s.db.QueryRow(`select id, is_expanded from folders where title=?`, title).Scan(&id, &expanded)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return &Folder{Id: id, Title: title, IsExpanded: expanded}
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteFolder(folderId int64) bool {
|
||||
_, err1 := s.db.Exec(`update feeds set folder_id = null where folder_id = ?`, folderId)
|
||||
_, err2 := s.db.Exec(`delete from folders where id = ?`, folderId)
|
||||
return err1 == nil && err2 == nil
|
||||
}
|
||||
|
||||
func (s *Storage) RenameFolder(folderId int64, newTitle string) bool {
|
||||
_, err := s.db.Exec(`update folders set title = ? where id = ?`, newTitle, folderId)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (s *Storage) ToggleFolderExpanded(folderId int64, isExpanded bool) bool {
|
||||
_, err := s.db.Exec(`update folders set is_expanded = ? where id = ?`, isExpanded, folderId)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (s *Storage) ListFolders() []Folder {
|
||||
result := make([]Folder, 0, 0)
|
||||
rows, err := s.db.Query(`
|
||||
select id, title, is_expanded
|
||||
from folders
|
||||
order by title collate nocase
|
||||
`)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
for rows.Next() {
|
||||
var f Folder
|
||||
err = rows.Scan(&f.Id, &f.Title, &f.IsExpanded)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
result = append(result, f)
|
||||
}
|
||||
return result
|
||||
}
|
||||
72
src/storage/http.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type HTTPState struct {
|
||||
FeedID int64
|
||||
LastRefreshed time.Time
|
||||
|
||||
LastModified string
|
||||
Etag string
|
||||
}
|
||||
|
||||
func (s *Storage) ListHTTPStates() map[int64]HTTPState {
|
||||
result := make(map[int64]HTTPState)
|
||||
rows, err := s.db.Query(`select feed_id, last_refreshed, last_modified, etag from http_states`)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
for rows.Next() {
|
||||
var state HTTPState
|
||||
err = rows.Scan(
|
||||
&state.FeedID,
|
||||
&state.LastRefreshed,
|
||||
&state.LastModified,
|
||||
&state.Etag,
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
result[state.FeedID] = state
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *Storage) GetHTTPState(feedID int64) *HTTPState {
|
||||
row := s.db.QueryRow(`
|
||||
select feed_id, last_refreshed, last_modified, etag
|
||||
from http_states where feed_id = ?
|
||||
`, feedID)
|
||||
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var state HTTPState
|
||||
row.Scan(
|
||||
&state.FeedID,
|
||||
&state.LastRefreshed,
|
||||
&state.LastModified,
|
||||
&state.Etag,
|
||||
)
|
||||
return &state
|
||||
}
|
||||
|
||||
func (s *Storage) SetHTTPState(feedID int64, lastModified, etag string) {
|
||||
_, err := s.db.Exec(`
|
||||
insert into http_states (feed_id, last_modified, etag, last_refreshed)
|
||||
values (?, ?, ?, datetime())
|
||||
on conflict (feed_id) do update set last_modified = ?, etag = ?, last_refreshed = datetime()`,
|
||||
// insert
|
||||
feedID, lastModified, etag,
|
||||
// upsert
|
||||
lastModified, etag,
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
}
|
||||
}
|
||||
382
src/storage/item.go
Normal file
@@ -0,0 +1,382 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"strings"
|
||||
"time"
|
||||
xhtml "golang.org/x/net/html"
|
||||
)
|
||||
|
||||
type ItemStatus int
|
||||
|
||||
const (
|
||||
UNREAD ItemStatus = 0
|
||||
READ ItemStatus = 1
|
||||
STARRED ItemStatus = 2
|
||||
)
|
||||
|
||||
var StatusRepresentations = map[ItemStatus]string{
|
||||
UNREAD: "unread",
|
||||
READ: "read",
|
||||
STARRED: "starred",
|
||||
}
|
||||
|
||||
var StatusValues = map[string]ItemStatus{
|
||||
"unread": UNREAD,
|
||||
"read": READ,
|
||||
"starred": STARRED,
|
||||
}
|
||||
|
||||
func (s ItemStatus) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(StatusRepresentations[s])
|
||||
}
|
||||
|
||||
func (s *ItemStatus) UnmarshalJSON(b []byte) error {
|
||||
var str string
|
||||
if err := json.Unmarshal(b, &str); err != nil {
|
||||
return err
|
||||
}
|
||||
*s = StatusValues[str]
|
||||
return nil
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
Id int64 `json:"id"`
|
||||
GUID string `json:"guid"`
|
||||
FeedId int64 `json:"feed_id"`
|
||||
Title string `json:"title"`
|
||||
Link string `json:"link"`
|
||||
Description string `json:"description"`
|
||||
Content string `json:"content"`
|
||||
Author string `json:"author"`
|
||||
Date *time.Time `json:"date"`
|
||||
DateUpdated *time.Time `json:"date_updated"`
|
||||
Status ItemStatus `json:"status"`
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
type ItemFilter struct {
|
||||
FolderID *int64
|
||||
FeedID *int64
|
||||
Status *ItemStatus
|
||||
Search *string
|
||||
}
|
||||
|
||||
type MarkFilter struct {
|
||||
FolderID *int64
|
||||
FeedID *int64
|
||||
}
|
||||
|
||||
func (s *Storage) CreateItems(items []Item) bool {
|
||||
tx, err := s.db.Begin()
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return false
|
||||
}
|
||||
now := time.Now()
|
||||
|
||||
for _, item := range items {
|
||||
// WILD: some feeds provide only `item.date_updated` (without `item.date_created`)
|
||||
if item.Date == nil {
|
||||
item.Date = item.DateUpdated
|
||||
}
|
||||
// WILD: `item.guid` is not always present
|
||||
if item.GUID == "" {
|
||||
item.GUID = item.Link
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
insert into items (
|
||||
guid, feed_id, title, link, description,
|
||||
content, author,
|
||||
date, date_updated, date_arrived,
|
||||
status, image
|
||||
)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
on conflict (feed_id, guid) do update set
|
||||
date_updated = ?, date_arrived = ?`,
|
||||
item.GUID, item.FeedId, html.UnescapeString(item.Title), item.Link, item.Description,
|
||||
item.Content, item.Author,
|
||||
item.Date, item.DateUpdated, now,
|
||||
UNREAD, item.Image,
|
||||
// upsert values
|
||||
item.DateUpdated, now,
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
if err = tx.Rollback(); err != nil {
|
||||
s.log.Print(err)
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
s.log.Print(err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func listQueryPredicate(filter ItemFilter) (string, []interface{}) {
|
||||
cond := make([]string, 0)
|
||||
args := make([]interface{}, 0)
|
||||
if filter.FolderID != nil {
|
||||
cond = append(cond, "f.folder_id = ?")
|
||||
args = append(args, *filter.FolderID)
|
||||
}
|
||||
if filter.FeedID != nil {
|
||||
cond = append(cond, "i.feed_id = ?")
|
||||
args = append(args, *filter.FeedID)
|
||||
}
|
||||
if filter.Status != nil {
|
||||
cond = append(cond, "i.status = ?")
|
||||
args = append(args, *filter.Status)
|
||||
}
|
||||
if filter.Search != nil {
|
||||
words := strings.Fields(*filter.Search)
|
||||
terms := make([]string, len(words))
|
||||
for idx, word := range words {
|
||||
terms[idx] = word + "*"
|
||||
}
|
||||
|
||||
cond = append(cond, "i.search_rowid in (select rowid from search where search match ?)")
|
||||
args = append(args, strings.Join(terms, " "))
|
||||
}
|
||||
|
||||
predicate := "1"
|
||||
if len(cond) > 0 {
|
||||
predicate = strings.Join(cond, " and ")
|
||||
}
|
||||
|
||||
return predicate, args
|
||||
}
|
||||
|
||||
func (s *Storage) ListItems(filter ItemFilter, offset, limit int, newestFirst bool) []Item {
|
||||
predicate, args := listQueryPredicate(filter)
|
||||
result := make([]Item, 0, 0)
|
||||
|
||||
order := "date desc"
|
||||
if !newestFirst {
|
||||
order = "date asc"
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`
|
||||
select
|
||||
i.id, i.guid, i.feed_id, i.title, i.link, i.description,
|
||||
i.content, i.author, i.date, i.date_updated, i.status, i.image
|
||||
from items i
|
||||
join feeds f on f.id = i.feed_id
|
||||
where %s
|
||||
order by %s
|
||||
limit %d offset %d
|
||||
`, predicate, order, limit, offset)
|
||||
rows, err := s.db.Query(query, args...)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
for rows.Next() {
|
||||
var x Item
|
||||
err = rows.Scan(
|
||||
&x.Id,
|
||||
&x.GUID,
|
||||
&x.FeedId,
|
||||
&x.Title,
|
||||
&x.Link,
|
||||
&x.Description,
|
||||
&x.Content,
|
||||
&x.Author,
|
||||
&x.Date,
|
||||
&x.DateUpdated,
|
||||
&x.Status,
|
||||
&x.Image,
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
result = append(result, x)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *Storage) CountItems(filter ItemFilter) int64 {
|
||||
predicate, args := listQueryPredicate(filter)
|
||||
query := fmt.Sprintf(`
|
||||
select count(i.id)
|
||||
from items i
|
||||
join feeds f on f.id = i.feed_id
|
||||
where %s`, predicate)
|
||||
row := s.db.QueryRow(query, args...)
|
||||
if row != nil {
|
||||
var result int64
|
||||
row.Scan(&result)
|
||||
return result
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *Storage) UpdateItemStatus(item_id int64, status ItemStatus) bool {
|
||||
_, err := s.db.Exec(`update items set status = ? where id = ?`, status, item_id)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (s *Storage) MarkItemsRead(filter MarkFilter) bool {
|
||||
cond := make([]string, 0)
|
||||
args := make([]interface{}, 0)
|
||||
|
||||
if filter.FolderID != nil {
|
||||
cond = append(cond, "f.folder_id = ?")
|
||||
args = append(args, *filter.FolderID)
|
||||
}
|
||||
if filter.FeedID != nil {
|
||||
cond = append(cond, "i.feed_id = ?")
|
||||
args = append(args, *filter.FeedID)
|
||||
}
|
||||
predicate := "1"
|
||||
if len(cond) > 0 {
|
||||
predicate = strings.Join(cond, " and ")
|
||||
}
|
||||
query := fmt.Sprintf(`
|
||||
update items set status = %d
|
||||
where id in (
|
||||
select i.id from items i
|
||||
join feeds f on f.id = i.feed_id
|
||||
where %s and i.status != %d
|
||||
)
|
||||
`, READ, predicate, STARRED)
|
||||
_, err := s.db.Exec(query, args...)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
}
|
||||
return err == nil
|
||||
}
|
||||
|
||||
type FeedStat struct {
|
||||
FeedId int64 `json:"feed_id"`
|
||||
UnreadCount int64 `json:"unread"`
|
||||
StarredCount int64 `json:"starred"`
|
||||
}
|
||||
|
||||
func (s *Storage) FeedStats() []FeedStat {
|
||||
result := make([]FeedStat, 0)
|
||||
rows, err := s.db.Query(fmt.Sprintf(`
|
||||
select
|
||||
feed_id,
|
||||
sum(case status when %d then 1 else 0 end),
|
||||
sum(case status when %d then 1 else 0 end)
|
||||
from items
|
||||
group by feed_id
|
||||
`, UNREAD, STARRED))
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
for rows.Next() {
|
||||
stat := FeedStat{}
|
||||
rows.Scan(&stat.FeedId, &stat.UnreadCount, &stat.StarredCount)
|
||||
result = append(result, stat)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func HTMLText(s string) string {
|
||||
tokenizer := xhtml.NewTokenizer(strings.NewReader(s))
|
||||
contents := make([]string, 0)
|
||||
for {
|
||||
token := tokenizer.Next()
|
||||
if token == xhtml.ErrorToken {
|
||||
break
|
||||
}
|
||||
if token == xhtml.TextToken {
|
||||
content := strings.TrimSpace(xhtml.UnescapeString(string(tokenizer.Text())))
|
||||
if len(content) > 0 {
|
||||
contents = append(contents, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
return strings.Join(contents, " ")
|
||||
}
|
||||
|
||||
func (s *Storage) SyncSearch() {
|
||||
rows, err := s.db.Query(`
|
||||
select id, title, content, description
|
||||
from items
|
||||
where search_rowid is null;
|
||||
`)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
items := make([]Item, 0)
|
||||
for rows.Next() {
|
||||
var item Item
|
||||
rows.Scan(&item.Id, &item.Title, &item.Content, &item.Description)
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
result, err := s.db.Exec(`
|
||||
insert into search (title, description, content) values (?, ?, ?)`,
|
||||
item.Title, HTMLText(item.Description), HTMLText(item.Content),
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return
|
||||
}
|
||||
if numrows, err := result.RowsAffected(); err == nil && numrows == 1 {
|
||||
if rowId, err := result.LastInsertId(); err == nil {
|
||||
s.db.Exec(
|
||||
`update items set search_rowid = ? where id = ?`,
|
||||
rowId, item.Id,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) DeleteOldItems() {
|
||||
rows, err := s.db.Query(fmt.Sprintf(`
|
||||
select feed_id, count(*) as num_items
|
||||
from items
|
||||
where status != %d
|
||||
group by feed_id
|
||||
having num_items > 50
|
||||
`, STARRED))
|
||||
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
feedIds := make([]int64, 0)
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
rows.Scan(&id, nil)
|
||||
feedIds = append(feedIds, id)
|
||||
}
|
||||
|
||||
for _, feedId := range feedIds {
|
||||
result, err := s.db.Exec(`
|
||||
delete from items where feed_id = ? and status != ? and date_arrived < ?`,
|
||||
feedId,
|
||||
STARRED,
|
||||
time.Now().Add(-time.Hour*24*90), // 90 days
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return
|
||||
}
|
||||
num, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return
|
||||
}
|
||||
if num > 0 {
|
||||
s.log.Printf("Deleted %d old items (%d)", num, feedId)
|
||||
}
|
||||
}
|
||||
}
|
||||
91
src/storage/settings.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package storage
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
func settingsDefaults() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"filter": "",
|
||||
"feed": "",
|
||||
"feed_list_width": 300,
|
||||
"item_list_width": 300,
|
||||
"sort_newest_first": true,
|
||||
"theme_name": "light",
|
||||
"theme_font": "",
|
||||
"theme_size": 1,
|
||||
"refresh_rate": 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) GetSettingsValue(key string) interface{} {
|
||||
row := s.db.QueryRow(`select val from settings where key=?`, key)
|
||||
if row == nil {
|
||||
return settingsDefaults()[key]
|
||||
}
|
||||
var val []byte
|
||||
row.Scan(&val)
|
||||
if len(val) == 0 {
|
||||
return nil
|
||||
}
|
||||
var valDecoded interface{}
|
||||
if err := json.Unmarshal([]byte(val), &valDecoded); err != nil {
|
||||
s.log.Print(err)
|
||||
return nil
|
||||
}
|
||||
return valDecoded
|
||||
}
|
||||
|
||||
func (s *Storage) GetSettingsValueInt64(key string) int64 {
|
||||
val := s.GetSettingsValue(key)
|
||||
if val != nil {
|
||||
if fval, ok := val.(float64); ok {
|
||||
return int64(fval)
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *Storage) GetSettings() map[string]interface{} {
|
||||
result := settingsDefaults()
|
||||
rows, err := s.db.Query(`select key, val from settings;`)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return result
|
||||
}
|
||||
for rows.Next() {
|
||||
var key string
|
||||
var val []byte
|
||||
var valDecoded interface{}
|
||||
|
||||
rows.Scan(&key, &val)
|
||||
if err = json.Unmarshal([]byte(val), &valDecoded); err != nil {
|
||||
s.log.Print(err)
|
||||
continue
|
||||
}
|
||||
result[key] = valDecoded
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *Storage) UpdateSettings(kv map[string]interface{}) bool {
|
||||
defaults := settingsDefaults()
|
||||
for key, val := range kv {
|
||||
if defaults[key] == nil {
|
||||
continue
|
||||
}
|
||||
valEncoded, err := json.Marshal(val)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return false
|
||||
}
|
||||
_, err = s.db.Exec(`
|
||||
insert into settings (key, val) values (?, ?)
|
||||
on conflict (key) do update set val=?`,
|
||||
key, valEncoded, valEncoded,
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
103
src/storage/storage.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var initQuery string = `
|
||||
create table if not exists folders (
|
||||
id integer primary key autoincrement,
|
||||
title text not null,
|
||||
is_expanded boolean not null default false
|
||||
);
|
||||
|
||||
create unique index if not exists idx_folder_title on folders(title);
|
||||
|
||||
create table if not exists feeds (
|
||||
id integer primary key autoincrement,
|
||||
folder_id references folders(id),
|
||||
title text not null,
|
||||
description text,
|
||||
link text,
|
||||
feed_link text not null,
|
||||
icon blob
|
||||
);
|
||||
|
||||
create index if not exists idx_feed_folder_id on feeds(folder_id);
|
||||
create unique index if not exists idx_feed_feed_link on feeds(feed_link);
|
||||
|
||||
create table if not exists items (
|
||||
id integer primary key autoincrement,
|
||||
guid string not null,
|
||||
feed_id references feeds(id),
|
||||
title text,
|
||||
link text,
|
||||
description text,
|
||||
content text,
|
||||
author text,
|
||||
date datetime,
|
||||
date_updated datetime,
|
||||
date_arrived datetime,
|
||||
status integer,
|
||||
image text,
|
||||
search_rowid integer
|
||||
);
|
||||
|
||||
create index if not exists idx_item_feed_id on items(feed_id);
|
||||
create index if not exists idx_item_status on items(status);
|
||||
create index if not exists idx_item_search_rowid on items(search_rowid);
|
||||
create unique index if not exists idx_item_guid on items(feed_id, guid);
|
||||
|
||||
create table if not exists settings (
|
||||
key string primary key,
|
||||
val blob
|
||||
);
|
||||
|
||||
create virtual table if not exists search using fts4(title, description, content);
|
||||
|
||||
create trigger if not exists del_item_search after delete on items begin
|
||||
delete from search where rowid = old.search_rowid;
|
||||
end;
|
||||
|
||||
create table if not exists http_states (
|
||||
feed_id references feeds(id) unique,
|
||||
last_refreshed datetime not null,
|
||||
|
||||
-- http header fields --
|
||||
last_modified string not null,
|
||||
etag string not null
|
||||
);
|
||||
|
||||
create table if not exists feed_errors (
|
||||
feed_id references feeds(id) unique,
|
||||
error string
|
||||
);
|
||||
`
|
||||
|
||||
type Storage struct {
|
||||
db *sql.DB
|
||||
log *log.Logger
|
||||
}
|
||||
|
||||
func New(path string, logger *log.Logger) (*Storage, error) {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
db, err := sql.Open("sqlite3", path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
db.SetMaxOpenConns(1)
|
||||
|
||||
if _, err := db.Exec(initQuery); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Storage{db: db, log: logger}, nil
|
||||
}
|
||||