Skip to content

Commit

Permalink
Adding imported properties to purge list
Browse files Browse the repository at this point in the history
Posting completion on purge to update statics
  • Loading branch information
boggydigital committed Aug 29, 2023
1 parent c322c8a commit d5d7616
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ post-completion
purge
id*^
confirm
webhook-url$

reduce-litres-details
score-data
Expand Down
19 changes: 15 additions & 4 deletions cli/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import (
func PurgeHandler(u *url.URL) error {
id := u.Query().Get("id")
confirm := u.Query().Has("confirm")
return Purge(id, confirm)
wu := u.Query().Get("webhook-url")
return Purge(id, wu, confirm)
}

// Purge will remove all book artefacts from the system:
// - details
// - covers
// - downloads
// - reductions (must be last to allow downloads to be resolved)
func Purge(id string, confirm bool) error {
func Purge(id string, webhookUrl string, confirm bool) error {

wa := nod.Begin("purge removes all book data, restoring that data will require an earlier backup")
wa.End()
Expand Down Expand Up @@ -51,7 +52,10 @@ func Purge(id string, confirm bool) error {
}
}

rxa, err := kvas.ConnectReduxAssets(data.AbsReduxDir(), data.ReduxProperties()...)
props := data.ReduxProperties()
props = append(props, data.ImportedProperties()...)

rxa, err := kvas.ConnectReduxAssets(data.AbsReduxDir(), props...)
if err != nil {
return pa.EndWithError(err)
}
Expand Down Expand Up @@ -102,7 +106,7 @@ func Purge(id string, confirm bool) error {

// reductions

for _, p := range data.ReduxProperties() {
for _, p := range props {
if rxa.HasKey(p, id) {
cra := nod.Begin(" found %s in %s...", id, p)
if confirm {
Expand All @@ -119,6 +123,13 @@ func Purge(id string, confirm bool) error {
}
}

// make sure to post completion to update static versions
if confirm {
if err := PostCompletion(webhookUrl); err != nil {
return pa.EndWithError(err)
}
}

result := fmt.Sprintf("run `purge %s -confirm` to delete all", id)
if confirm {
result = "done"
Expand Down
8 changes: 8 additions & 0 deletions data/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func ReduxProperties() []string {
MissingDetailsIdsProperty,
BookTypeProperty,
BookCompletedProperty,
ImageProperty,
GenresProperty,
TagsProperty,
LocalTagsProperty,
Expand All @@ -110,6 +111,13 @@ func ReduxProperties() []string {
}
}

func ImportedProperties() []string {
return []string{
ImportedProperty,
DataSourceProperty,
}
}

func AnyTextProperties() []string {
return []string{
TitleProperty,
Expand Down

0 comments on commit d5d7616

Please sign in to comment.