Skip to content

Commit

Permalink
add create ebook by default in settings (#761)
Browse files Browse the repository at this point in the history
* add create ebook by default in settings

* ebook automatic generate for new bookmark

* fix empty ebook for new bookmark
  • Loading branch information
Monirzadeh committed Oct 22, 2023
1 parent 106bf16 commit f82b97d
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/swagger/docs.go
Expand Up @@ -252,6 +252,9 @@ const docTemplate = `{
"model.UserConfig": {
"type": "object",
"properties": {
"CreateEbook": {
"type": "boolean"
},
"HideExcerpt": {
"type": "boolean"
},
Expand Down
3 changes: 3 additions & 0 deletions docs/swagger/swagger.json
Expand Up @@ -241,6 +241,9 @@
"model.UserConfig": {
"type": "object",
"properties": {
"CreateEbook": {
"type": "boolean"
},
"HideExcerpt": {
"type": "boolean"
},
Expand Down
2 changes: 2 additions & 0 deletions docs/swagger/swagger.yaml
Expand Up @@ -51,6 +51,8 @@ definitions:
type: object
model.UserConfig:
properties:
CreateEbook:
type: boolean
HideExcerpt:
type: boolean
HideThumbnail:
Expand Down
1 change: 1 addition & 0 deletions internal/core/processing.go
Expand Up @@ -142,6 +142,7 @@ func ProcessBookmark(req ProcessRequest) (book model.Bookmark, isFatalErr bool,
// If needed, create ebook as well
if book.CreateEbook {
ebookPath := fp.Join(req.DataDir, "ebook", strID+".epub")
req.Bookmark = book

if strings.Contains(contentType, "application/pdf") {
return book, false, errors.Wrap(err, "can't create ebook from pdf")
Expand Down
2 changes: 2 additions & 0 deletions internal/http/routes/api/v1/auth_test.go
Expand Up @@ -253,6 +253,7 @@ func TestSettingsHandler(t *testing.T) {
NightMode: true,
KeepMetadata: true,
UseArchive: true,
CreateEbook: true,
MakePublic: true,
},
}
Expand All @@ -276,6 +277,7 @@ func TestSettingsHandler(t *testing.T) {
"NightMode": false,
"KeepMetadata": false,
"UseArchive": false,
"CreateEbook": false,
"MakePublic": false
}
}`)
Expand Down
1 change: 1 addition & 0 deletions internal/model/account.go
Expand Up @@ -23,6 +23,7 @@ type UserConfig struct {
NightMode bool `json:"NightMode"`
KeepMetadata bool `json:"KeepMetadata"`
UseArchive bool `json:"UseArchive"`
CreateEbook bool `json:"CreateEbook"`
MakePublic bool `json:"MakePublic"`
}

Expand Down
6 changes: 6 additions & 0 deletions internal/view/assets/js/page/home.js
Expand Up @@ -382,6 +382,11 @@ export default {
label: "Create archive",
type: "check",
value: this.appOptions.UseArchive,
}, {
name: "createEbook",
label: "Create Ebook",
type: "check",
value: this.appOptions.CreateEbook,
}, {
name: "makePublic",
label: "Make archive publicly available",
Expand Down Expand Up @@ -417,6 +422,7 @@ export default {
public: data.makePublic ? 1 : 0,
tags: tags,
createArchive: data.createArchive,
createEbook: data.createEbook,
};

this.dialog.loading = true;
Expand Down
5 changes: 5 additions & 0 deletions internal/view/assets/js/page/setting.js
Expand Up @@ -35,6 +35,10 @@ var template = `
<input type="checkbox" v-model="appOptions.UseArchive" @change="saveSetting">
Create archive by default
</label>
<label>
<input type="checkbox" v-model="appOptions.CreateEbook" @change="saveSetting">
Create ebook by default
</label>
<label>
<input type="checkbox" v-model="appOptions.MakePublic" @change="saveSetting">
Make archive publicly available by default
Expand Down Expand Up @@ -96,6 +100,7 @@ export default {
...options,
KeepMetadata: this.appOptions.KeepMetadata,
UseArchive: this.appOptions.UseArchive,
CreateEbook: this.appOptions.CreateEbook,
MakePublic: this.appOptions.MakePublic,
};
}
Expand Down
2 changes: 2 additions & 0 deletions internal/view/content.html
Expand Up @@ -64,12 +64,14 @@
ListMode = (typeof opts.config.ListMode === "boolean") ? opts.config.ListMode : false,
NightMode = (typeof opts.config.NightMode === "boolean") ? opts.config.NightMode : false,
UseArchive = (typeof opts.config.UseArchive === "boolean") ? opts.config.UseArchive : false;
CreateEbook = (typeof opts.config.CreateEbook === "boolean") ? opts.config.CreateEbook : false;

this.appOptions = {
ShowId: ShowId,
ListMode: ListMode,
NightMode: NightMode,
UseArchive: UseArchive,
CreateEbook: CreateEbook,
};

document.body.className = NightMode ? "night" : "";
Expand Down
2 changes: 2 additions & 0 deletions internal/view/index.html
Expand Up @@ -113,6 +113,7 @@
NightMode = (typeof opts.config.NightMode === "boolean") ? opts.config.NightMode : false,
KeepMetadata = (typeof opts.config.KeepMetadata === "boolean") ? opts.config.KeepMetadata : false,
UseArchive = (typeof opts.config.UseArchive === "boolean") ? opts.config.UseArchive : false,
CreateEbook = (typeof opts.config.CreateEbook === "boolean") ? opts.config.CreateEbook : false,
MakePublic = (typeof opts.config.MakePublic === "boolean") ? opts.config.MakePublic : false;

this.appOptions = {
Expand All @@ -123,6 +124,7 @@
NightMode: NightMode,
KeepMetadata: KeepMetadata,
UseArchive: UseArchive,
CreateEbook: CreateEbook,
MakePublic: MakePublic,
};

Expand Down
3 changes: 3 additions & 0 deletions internal/webserver/handler-api.go
Expand Up @@ -180,6 +180,7 @@ type apiInsertBookmarkPayload struct {
Excerpt string `json:"excerpt"`
Tags []model.Tag `json:"tags"`
CreateArchive bool `json:"createArchive"`
CreateEbook bool `json:"createEbook"`
MakePublic int `json:"public"`
Async bool `json:"async"`
}
Expand All @@ -189,6 +190,7 @@ type apiInsertBookmarkPayload struct {
func newAPIInsertBookmarkPayload() *apiInsertBookmarkPayload {
return &apiInsertBookmarkPayload{
CreateArchive: false,
CreateEbook: false,
Async: true,
}
}
Expand All @@ -213,6 +215,7 @@ func (h *Handler) ApiInsertBookmark(w http.ResponseWriter, r *http.Request, ps h
Tags: payload.Tags,
Public: payload.MakePublic,
CreateArchive: payload.CreateArchive,
CreateEbook: payload.CreateEbook,
}

// Clean up bookmark URL
Expand Down

0 comments on commit f82b97d

Please sign in to comment.