Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ jobs:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: set up QEMU
uses: docker/setup-qemu-action@v3
uses: docker/setup-qemu-action@v4

- name: set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v4

- name: available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
Expand Down
3 changes: 2 additions & 1 deletion backend/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ linters:
- unparam
- unused
- whitespace
- modernize
settings:
goconst:
min-len: 2
Expand Down Expand Up @@ -80,4 +81,4 @@ formatters:
paths:
- third_party$
- builtin$
- examples$
- examples$
7 changes: 4 additions & 3 deletions backend/extractor/pics.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package extractor

import (
"cmp"
"io"
"net/http"
"sort"
"slices"
"sync"
"time"

Expand Down Expand Up @@ -39,7 +40,7 @@ func (f *UReadability) extractPics(iselect *goquery.Selection, url string) (main
images[r.size] = r.url
allImages = append(allImages, r.url)
}
sort.Strings(allImages)
slices.Sort(allImages)
if len(images) == 0 {
return "", nil, false
}
Expand All @@ -49,7 +50,7 @@ func (f *UReadability) extractPics(iselect *goquery.Selection, url string) (main
for k := range images {
keys = append(keys, k)
}
sort.Sort(sort.Reverse(sort.IntSlice(keys)))
slices.SortFunc(keys, func(a, b int) int { return cmp.Compare(b, a) })
mainImage = images[keys[0]]
log.Printf("[DEBUG] total images from %s = %d, main=%s (%d)", url, len(images), mainImage, keys[0])
return mainImage, allImages, true
Expand Down
5 changes: 1 addition & 4 deletions backend/extractor/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ func (f *UReadability) getText(content, title string) string {
// get snippet from clean text content
func (f *UReadability) getSnippet(cleanText string) string {
cleanText = strings.ReplaceAll(cleanText, "\n", " ")
size := len([]rune(cleanText))
if size > f.SnippetSize {
size = f.SnippetSize
}
size := min(len([]rune(cleanText)), f.SnippetSize)
snippet := []rune(cleanText)[:size]
// go back in snippet and found first space
for i := len(snippet) - 1; i >= 0; i-- {
Expand Down
16 changes: 10 additions & 6 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ func main() {
if _, err := flags.Parse(&opts); err != nil {
os.Exit(1)
}
var options []log.Option
if opts.Debug {
options = []log.Option{log.Debug, log.CallerFile}
}
options = append(options, log.Msec, log.LevelBraces)
log.Setup(options...)
setupLog(opts.Debug, opts.MongoURI, opts.Token)

log.Printf("[INFO] started ukeeper-readability service %s", revision)
db, err := datastore.New(opts.MongoURI, opts.MongoDB, opts.MongoDelay)
Expand Down Expand Up @@ -69,3 +64,12 @@ func main() {

srv.Run(ctx, opts.Address, opts.Port, opts.FrontendDir)
}

func setupLog(dbg bool, secrets ...string) { //nolint:revive // control flag is fine for init helper
log.Secret(secrets...)
if dbg {
log.Setup(log.Debug, log.CallerFile, log.Msec, log.LevelBraces)
return
}
log.Setup(log.Msec, log.LevelBraces)
Comment on lines +69 to +74
}
11 changes: 5 additions & 6 deletions backend/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ func (s *Server) extractArticleEmulateReadability(w http.ResponseWriter, r *http

// generates previews for the provided test URLs
func (s *Server) handlePreview(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
r.Body = http.MaxBytesReader(w, r.Body, 64<<20) // limit to 64MB
if err := r.ParseForm(); err != nil {
http.Error(w, "Failed to parse form", http.StatusBadRequest)
return
}
Expand Down Expand Up @@ -268,17 +268,16 @@ func (s *Server) handlePreview(w http.ResponseWriter, r *http.Request) {
Results: results,
}

err = s.rulePage.ExecuteTemplate(w, "preview.gohtml", data)
if err != nil {
if err := s.rulePage.ExecuteTemplate(w, "preview.gohtml", data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

// saveRule upsert rule, forcing enabled=true
func (s *Server) saveRule(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
r.Body = http.MaxBytesReader(w, r.Body, 64<<20) // limit to 64MB
if err := r.ParseForm(); err != nil {
http.Error(w, "Failed to parse form", http.StatusBadRequest)
return
}
Expand Down
Loading