From 5e1f326fc324653ddc3e14d1ef28c554558ef305 Mon Sep 17 00:00:00 2001 From: Acelya Date: Wed, 19 Oct 2022 17:57:29 +0200 Subject: [PATCH] feat: add option to bypass document readability check Before the bookmark is cached, a test is made and can disqualify a readable document. This option allows the user to bypass this test. --- internal/core/processing.go | 11 ++++++++-- internal/model/model.go | 1 + internal/view/js/component/dialog.js | 30 ++++++++++++++++------------ internal/view/js/page/home.js | 6 ++++++ internal/webserver/handler-api.go | 3 +++ 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/internal/core/processing.go b/internal/core/processing.go index 718fa2c00..0ae72e1b3 100644 --- a/internal/core/processing.go +++ b/internal/core/processing.go @@ -8,6 +8,7 @@ import ( "image/draw" "image/jpeg" "io" + "log" "math" "net/url" "os" @@ -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) diff --git a/internal/model/model.go b/internal/model/model.go index 96f214ff1..fe56d15a4 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -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. diff --git a/internal/view/js/component/dialog.js b/internal/view/js/component/dialog.js index 4c2836a77..7da724828 100644 --- a/internal/view/js/component/dialog.js +++ b/internal/view/js/component/dialog.js @@ -109,8 +109,8 @@ 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: '', @@ -118,18 +118,22 @@ export default { 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'() { diff --git a/internal/view/js/page/home.js b/internal/view/js/page/home.js index 722ac6e50..bd2c433e7 100644 --- a/internal/view/js/page/home.js +++ b/internal/view/js/page/home.js @@ -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", @@ -619,6 +624,7 @@ export default { ids: ids, createArchive: data.createArchive, keepMetadata: data.keepMetadata, + forceCaching: data.forceCaching, }; this.dialog.loading = true; diff --git a/internal/webserver/handler-api.go b/internal/webserver/handler-api.go index 3d60e7c03..baac409c7 100644 --- a/internal/webserver/handler-api.go +++ b/internal/webserver/handler-api.go @@ -271,6 +271,7 @@ type apiInsertBookmarkPayload struct { CreateArchive bool `json:"createArchive"` MakePublic int `json:"public"` Async bool `json:"async"` + ForceCaching bool `json:"forceCaching"` } // newApiInsertBookmarkPayload @@ -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) @@ -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