mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
go fmt
This commit is contained in:
parent
012b58bbe4
commit
632412c10e
@ -1,3 +1,4 @@
|
|||||||
|
//go:build release
|
||||||
// +build release
|
// +build release
|
||||||
|
|
||||||
package assets
|
package assets
|
||||||
|
@ -60,9 +60,9 @@ func ExtractContent(page io.Reader) (string, error) {
|
|||||||
best = body
|
best = body
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if best == nil {
|
if best == nil {
|
||||||
return "", errors.New("failed to extract content")
|
return "", errors.New("failed to extract content")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//log.Printf("[Readability] TopCandidate: %v", topCandidate)
|
//log.Printf("[Readability] TopCandidate: %v", topCandidate)
|
||||||
|
|
||||||
|
@ -364,7 +364,6 @@ func isBlockedTag(tagName string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
One or more strings separated by commas, indicating possible image sources for the user agent to use.
|
One or more strings separated by commas, indicating possible image sources for the user agent to use.
|
||||||
|
|
||||||
Each string is composed of:
|
Each string is composed of:
|
||||||
@ -372,7 +371,6 @@ Each string is composed of:
|
|||||||
- Optionally, whitespace followed by one of:
|
- Optionally, whitespace followed by one of:
|
||||||
- A width descriptor (a positive integer directly followed by w). The width descriptor is divided by the source size given in the sizes attribute to calculate the effective pixel density.
|
- A width descriptor (a positive integer directly followed by w). The width descriptor is divided by the source size given in the sizes attribute to calculate the effective pixel density.
|
||||||
- A pixel density descriptor (a positive floating point number directly followed by x).
|
- A pixel density descriptor (a positive floating point number directly followed by x).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
func sanitizeSrcsetAttr(baseURL, value string) string {
|
func sanitizeSrcsetAttr(baseURL, value string) string {
|
||||||
var sanitizedSources []string
|
var sanitizedSources []string
|
||||||
|
@ -6,12 +6,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func RedirectURL(link string) string {
|
func RedirectURL(link string) string {
|
||||||
if strings.HasPrefix(link, "https://www.google.com/url?") {
|
if strings.HasPrefix(link, "https://www.google.com/url?") {
|
||||||
if u, err := url.Parse(link); err == nil {
|
if u, err := url.Parse(link); err == nil {
|
||||||
if u2 := u.Query().Get("url"); u2 != "" {
|
if u2 := u.Query().Get("url"); u2 != "" {
|
||||||
return u2
|
return u2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return link
|
return link
|
||||||
}
|
}
|
||||||
|
@ -3,22 +3,22 @@ package silo
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestRedirectURL(t *testing.T) {
|
func TestRedirectURL(t *testing.T) {
|
||||||
link := "https://www.google.com/url?rct=j&sa=t&url=https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/&ct=ga&cd=CAIyGjlkMjI1NjUyODE3ODFjMDQ6Y29tOmVuOlVT&usg=AOvVaw16C2fJtw6m8QVEbto2HCKK"
|
link := "https://www.google.com/url?rct=j&sa=t&url=https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/&ct=ga&cd=CAIyGjlkMjI1NjUyODE3ODFjMDQ6Y29tOmVuOlVT&usg=AOvVaw16C2fJtw6m8QVEbto2HCKK"
|
||||||
want := "https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/"
|
want := "https://www.cryptoglobe.com/latest/2022/08/investment-strategist-lyn-alden-explains-why-she-is-still-bullish-on-bitcoin-long-term/"
|
||||||
have := RedirectURL(link)
|
have := RedirectURL(link)
|
||||||
if have != want {
|
if have != want {
|
||||||
t.Logf("want: %s", want)
|
t.Logf("want: %s", want)
|
||||||
t.Logf("have: %s", have)
|
t.Logf("have: %s", have)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
link = "https://example.com"
|
link = "https://example.com"
|
||||||
if RedirectURL(link) != link {
|
if RedirectURL(link) != link {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
link = "https://example.com/url?url=test.com"
|
link = "https://example.com/url?url=test.com"
|
||||||
if RedirectURL(link) != link {
|
if RedirectURL(link) != link {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build !windows
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -58,17 +58,20 @@ var oldStdin, oldStdout, oldStderr *os.File
|
|||||||
//
|
//
|
||||||
// Net result is as follows.
|
// Net result is as follows.
|
||||||
// Before:
|
// Before:
|
||||||
// SHELL NON-REDIRECTED REDIRECTED
|
//
|
||||||
// explorer.exe no console n/a
|
// SHELL NON-REDIRECTED REDIRECTED
|
||||||
// cmd.exe broken works
|
// explorer.exe no console n/a
|
||||||
// powershell broken broken
|
// cmd.exe broken works
|
||||||
// WSL bash broken works
|
// powershell broken broken
|
||||||
|
// WSL bash broken works
|
||||||
|
//
|
||||||
// After
|
// After
|
||||||
// SHELL NON-REDIRECTED REDIRECTED
|
//
|
||||||
// explorer.exe no console n/a
|
// SHELL NON-REDIRECTED REDIRECTED
|
||||||
// cmd.exe works works
|
// explorer.exe no console n/a
|
||||||
// powershell works broken
|
// cmd.exe works works
|
||||||
// WSL bash works works
|
// powershell works broken
|
||||||
|
// WSL bash works works
|
||||||
//
|
//
|
||||||
// We don't seem to make anything worse, at least.
|
// We don't seem to make anything worse, at least.
|
||||||
func FixConsoleIfNeeded() error {
|
func FixConsoleIfNeeded() error {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build macos || windows
|
||||||
// +build macos windows
|
// +build macos windows
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build !windows && !macos
|
||||||
// +build !windows,!macos
|
// +build !windows,!macos
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build macos
|
||||||
// +build macos
|
// +build macos
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build windows
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build !windows && !darwin
|
||||||
// +build !windows,!darwin
|
// +build !windows,!darwin
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build darwin
|
||||||
// +build darwin
|
// +build darwin
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//go:build windows
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
@ -244,7 +244,7 @@ func (s *Server) handleFeedList(c *router.Context) {
|
|||||||
if len(items) > 0 {
|
if len(items) > 0 {
|
||||||
s.db.CreateItems(items)
|
s.db.CreateItems(items)
|
||||||
s.db.SetFeedSize(feed.Id, len(items))
|
s.db.SetFeedSize(feed.Id, len(items))
|
||||||
s.db.SyncSearch()
|
s.db.SyncSearch()
|
||||||
}
|
}
|
||||||
s.worker.FindFeedFavicon(*feed)
|
s.worker.FindFeedFavicon(*feed)
|
||||||
|
|
||||||
@ -476,9 +476,9 @@ func (s *Server) handleOPMLExport(c *router.Context) {
|
|||||||
func (s *Server) handlePageCrawl(c *router.Context) {
|
func (s *Server) handlePageCrawl(c *router.Context) {
|
||||||
url := c.Req.URL.Query().Get("url")
|
url := c.Req.URL.Query().Get("url")
|
||||||
|
|
||||||
if newUrl := silo.RedirectURL(url); newUrl != "" {
|
if newUrl := silo.RedirectURL(url); newUrl != "" {
|
||||||
url = newUrl
|
url = newUrl
|
||||||
}
|
}
|
||||||
if content := silo.VideoIFrame(url); content != "" {
|
if content := silo.VideoIFrame(url); content != "" {
|
||||||
c.JSON(http.StatusOK, map[string]string{
|
c.JSON(http.StatusOK, map[string]string{
|
||||||
"content": sanitizer.Sanitize(url, content),
|
"content": sanitizer.Sanitize(url, content),
|
||||||
@ -494,9 +494,9 @@ func (s *Server) handlePageCrawl(c *router.Context) {
|
|||||||
}
|
}
|
||||||
content, err := readability.ExtractContent(strings.NewReader(body))
|
content, err := readability.ExtractContent(strings.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, map[string]string{
|
c.JSON(http.StatusOK, map[string]string{
|
||||||
"content": "error: " + err.Error(),
|
"content": "error: " + err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content = sanitizer.Sanitize(url, content)
|
content = sanitizer.Sanitize(url, content)
|
||||||
|
@ -300,11 +300,11 @@ var (
|
|||||||
// Delete old articles from the database to cleanup space.
|
// Delete old articles from the database to cleanup space.
|
||||||
//
|
//
|
||||||
// The rules:
|
// The rules:
|
||||||
// * Never delete starred entries.
|
// - Never delete starred entries.
|
||||||
// * Keep at least the same amount of articles the feed provides (default: 50).
|
// - Keep at least the same amount of articles the feed provides (default: 50).
|
||||||
// This prevents from deleting items for rarely updated and/or ever-growing
|
// This prevents from deleting items for rarely updated and/or ever-growing
|
||||||
// feeds which might eventually reappear as unread.
|
// feeds which might eventually reappear as unread.
|
||||||
// * Keep entries for a certain period (default: 90 days).
|
// - Keep entries for a certain period (default: 90 days).
|
||||||
func (s *Storage) DeleteOldItems() {
|
func (s *Storage) DeleteOldItems() {
|
||||||
rows, err := s.db.Query(`
|
rows, err := s.db.Query(`
|
||||||
select
|
select
|
||||||
|
Loading…
x
Reference in New Issue
Block a user