Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to bypass document readability check #525

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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) => {
fmartingr marked this conversation as resolved.
Show resolved Hide resolved
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