Skip to content

Commit

Permalink
feat: add option to bypass document readability check
Browse files Browse the repository at this point in the history
Before the bookmark is cached, a test is made and can disqualify a
readable document. This option allows the user to bypass this test.
  • Loading branch information
Acelya-9028 committed Oct 19, 2022
1 parent 77269b7 commit 5e1f326
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
11 changes: 9 additions & 2 deletions internal/core/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"image/draw"
"image/jpeg"
"io"
"log"
"math"
"net/url"
"os"
Expand Down Expand Up @@ -67,11 +68,17 @@ func ProcessBookmark(req ProcessRequest) (book model.Bookmark, isFatalErr bool,
// If this is HTML, parse for readable content
var imageURLs []string
if strings.Contains(contentType, "text/html") {
isReadable := readability.Check(readabilityCheckInput)
isReadable := true
if !book.ForceCaching && !book.HasContent {
isReadable = readability.Check(readabilityCheckInput)
if !isReadable {
log.Printf("%s is not readable", book.URL)
}
}

nurl, err := url.Parse(book.URL)
if err != nil {
return book, true, fmt.Errorf("Failed to parse url: %v", err)
return book, true, fmt.Errorf("failed to parse url: %v", err)
}

article, err := readability.FromReader(readabilityInput, nurl)
Expand Down
1 change: 1 addition & 0 deletions internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Bookmark struct {
HasArchive bool `json:"hasArchive"`
Tags []Tag `json:"tags"`
CreateArchive bool `json:"createArchive"`
ForceCaching bool `json:"forceCaching"`
}

// Account is person that allowed to access web interface.
Expand Down
30 changes: 17 additions & 13 deletions internal/view/js/component/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,31 @@ export default {
fields: {
immediate: true,
handler() {
this.formFields = this.fields.map(field => {
if (typeof field === 'string') return {
this.formFields = this.fields.reduce((fields, field) => {
if (typeof field === 'string') fields.push({
name: field,
label: field,
value: '',
type: 'text',
dictionary: [],
separator: ' ',
suggestion: undefined
})

if (typeof field === 'object') {
if (field.visible === false) return fields;
fields.push({
name: field.name || '',
label: field.label || '',
value: field.value || '',
type: field.type || 'text',
dictionary: field.dictionary instanceof Array ? field.dictionary : [],
separator: field.separator || ' ',
suggestion: undefined
})
}

if (typeof field === 'object') return {
name: field.name || '',
label: field.label || '',
value: field.value || '',
type: field.type || 'text',
dictionary: field.dictionary instanceof Array ? field.dictionary : [],
separator: field.separator || ' ',
suggestion: undefined
}
});
return fields;
}, []);
}
},
'fields.length'() {
Expand Down
6 changes: 6 additions & 0 deletions internal/view/js/page/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@ export default {
label: "Update archive as well",
type: "check",
value: this.appOptions.useArchive,
}, {
name: "forceCaching",
label: "Force bookmark caching",
type: "check",
visible: items.length > 1 ? true : !this.bookmarks[items[0].index].hasContent,
}],
mainText: "Yes",
secondText: "No",
Expand All @@ -619,6 +624,7 @@ export default {
ids: ids,
createArchive: data.createArchive,
keepMetadata: data.keepMetadata,
forceCaching: data.forceCaching,
};

this.dialog.loading = true;
Expand Down
3 changes: 3 additions & 0 deletions internal/webserver/handler-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ type apiInsertBookmarkPayload struct {
CreateArchive bool `json:"createArchive"`
MakePublic int `json:"public"`
Async bool `json:"async"`
ForceCaching bool `json:"forceCaching"`
}

// newApiInsertBookmarkPayload
Expand Down Expand Up @@ -471,6 +472,7 @@ func (h *handler) apiUpdateCache(w http.ResponseWriter, r *http.Request, ps http
IDs []int `json:"ids"`
KeepMetadata bool `json:"keepMetadata"`
CreateArchive bool `json:"createArchive"`
ForceCaching bool `json:"forceCaching"`
}{}

err = json.NewDecoder(r.Body).Decode(&request)
Expand Down Expand Up @@ -508,6 +510,7 @@ func (h *handler) apiUpdateCache(w http.ResponseWriter, r *http.Request, ps http

// Mark whether book will be archived
book.CreateArchive = request.CreateArchive
book.ForceCaching = request.ForceCaching

go func(i int, book model.Bookmark, keepMetadata bool) {
// Make sure to finish the WG
Expand Down

0 comments on commit 5e1f326

Please sign in to comment.