mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
code cleanup
This commit is contained in:
parent
c04f54619b
commit
b223233318
70
main.go
70
main.go
@ -1,80 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
//"github.com/nkanaev/yarr/storage"
|
||||
//"github.com/nkanaev/yarr/worker"
|
||||
"github.com/nkanaev/yarr/server"
|
||||
//"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
/*
|
||||
store, err := storage.New()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Print(store)
|
||||
*/
|
||||
/*
|
||||
folder := store.CreateFolder("foo")
|
||||
store.RenameFolder(folder.Id, "bar")
|
||||
store.ToggleFolderExpanded(folder.Id, false)
|
||||
log.Print(store.ListFolders())
|
||||
*/
|
||||
/*
|
||||
feed := store.CreateFeed(
|
||||
"title", "description", "link", "feedlink", "icon", 1)
|
||||
store.RenameFeed(feed.Id, "newtitle")
|
||||
log.Print(store.ListFeeds())
|
||||
*/
|
||||
/*;
|
||||
items := make([]storage.Item, 3, 3)
|
||||
items = append(items, storage.Item{
|
||||
Id: "id",
|
||||
FeedId: 0,
|
||||
Title: "title",
|
||||
Link: "link",
|
||||
Description: "description",
|
||||
Content: "content",
|
||||
Author: "author",
|
||||
Date: 1,
|
||||
DateUpdated: 1,
|
||||
Status: storage.UNREAD,
|
||||
Image: "image",
|
||||
})
|
||||
items = append(items, storage.Item{
|
||||
Id: "id2",
|
||||
FeedId: 0,
|
||||
Title: "title",
|
||||
Link: "link",
|
||||
Description: "description",
|
||||
Content: "content",
|
||||
Author: "author",
|
||||
Date: 1,
|
||||
DateUpdated: 50,
|
||||
Status: storage.UNREAD,
|
||||
Image: "image",
|
||||
})
|
||||
items = append(items, storage.Item{
|
||||
Id: "id",
|
||||
FeedId: 0,
|
||||
Title: "title",
|
||||
Link: "link",
|
||||
Description: "description",
|
||||
Content: "content",
|
||||
Author: "author",
|
||||
Date: 1,
|
||||
DateUpdated: 100,
|
||||
Status: storage.UNREAD,
|
||||
Image: "image",
|
||||
})
|
||||
log.Print(store.CreateItems(items))
|
||||
log.Print(store.ListItems())
|
||||
*/
|
||||
/*
|
||||
log.Print(worker.FindFeeds("https://horriblesubs.info/"))
|
||||
log.Print(worker.FindFeeds("http://daringfireball.net/"))
|
||||
*/
|
||||
srv := server.New()
|
||||
srv.ListenAndServe()
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"net/http"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type FeedSource struct {
|
||||
@ -13,7 +13,6 @@ type FeedSource struct {
|
||||
|
||||
const feedLinks = `link[type='application/rss+xml'],link[type='application/atom+xml']`
|
||||
|
||||
|
||||
func FindFeeds(r *http.Response) ([]FeedSource, error) {
|
||||
sources := make([]FeedSource, 0, 0)
|
||||
doc, err := goquery.NewDocumentFromResponse(r)
|
||||
|
@ -1,23 +1,23 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/nkanaev/yarr/storage"
|
||||
"github.com/mmcdole/gofeed"
|
||||
"net/http"
|
||||
"html/template"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"os"
|
||||
"log"
|
||||
"fmt"
|
||||
"github.com/mmcdole/gofeed"
|
||||
"github.com/nkanaev/yarr/storage"
|
||||
"html"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"mime"
|
||||
"strings"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"math"
|
||||
"html"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
@ -78,7 +78,6 @@ func FolderListHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type UpdateFolder struct {
|
||||
Title *string `json:"title,omitempty"`
|
||||
IsExpanded *bool `json:"is_expanded,omitempty"`
|
||||
@ -437,7 +436,7 @@ func OPMLExportHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
feedline := func(feed storage.Feed, indent int) {
|
||||
line(
|
||||
strings.Repeat(" ", indent) +
|
||||
strings.Repeat(" ", indent)+
|
||||
`<outline type="rss" text="%s" description="%s" xmlUrl="%s" htmlUrl="%s"/>`,
|
||||
feed.Title, feed.Description,
|
||||
feed.FeedLink, feed.Link,
|
||||
|
@ -1,12 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"context"
|
||||
"regexp"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"github.com/nkanaev/yarr/storage"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Route struct {
|
||||
|
@ -1,11 +1,11 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"golang.org/x/net/html"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ItemStatus int
|
||||
@ -16,13 +16,13 @@ const (
|
||||
STARRED ItemStatus = 2
|
||||
)
|
||||
|
||||
var StatusRepresentations = map[ItemStatus]string {
|
||||
var StatusRepresentations = map[ItemStatus]string{
|
||||
UNREAD: "unread",
|
||||
READ: "read",
|
||||
STARRED: "starred",
|
||||
}
|
||||
|
||||
var StatusValues = map[string]ItemStatus {
|
||||
var StatusValues = map[string]ItemStatus{
|
||||
"unread": UNREAD,
|
||||
"read": READ,
|
||||
"starred": STARRED,
|
||||
@ -314,7 +314,7 @@ func (s *Storage) SyncSearch() {
|
||||
func (s *Storage) DeleteOldItems() {
|
||||
result, err := s.db.Exec(
|
||||
`delete from items where status = ? and date < ?`,
|
||||
READ, time.Now().Add(-time.Hour * 24 * 90) /* 90 days */)
|
||||
READ, time.Now().Add(-time.Hour*24*90) /* 90 days */)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return
|
||||
|
@ -1,10 +1,10 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"os"
|
||||
"log"
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var initQuery string = `
|
||||
@ -77,7 +77,7 @@ func New() (*Storage, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logger := log.New(os.Stdout, "storage: ", log.Ldate | log.Ltime | log.Lshortfile)
|
||||
logger := log.New(os.Stdout, "storage: ", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
return &Storage{db: db, log: logger}, nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user