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

Feature/plugin v2 #284

Merged
merged 42 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
23541f4
Add "title_title" to slim JSON
hkalexling May 15, 2021
a571d21
WIP
hkalexling May 15, 2021
e0713cc
WIP
hkalexling May 22, 2021
87c479b
WIP
hkalexling May 30, 2021
59bcb4d
WIP
hkalexling Jun 5, 2021
9eb699e
Add plugin subscription types
hkalexling Jun 7, 2021
6844860
Revert "Subscription manager"
hkalexling Jun 7, 2021
3b19883
Use auto overflow tables
hkalexling Jun 7, 2021
259f6cb
Add endpoint for plugin subscription
hkalexling Jul 11, 2021
f56ce23
WIP
hkalexling Jul 11, 2021
b7aee1e
WIP
hkalexling Aug 17, 2021
ae1c362
Merge branch 'dev' into feature/plugin-v2
hkalexling Sep 4, 2021
238860d
Simplify subscription JSON parsing
hkalexling Sep 4, 2021
198913d
Remove MangaDex files that are no longer needed
hkalexling Sep 4, 2021
a45bea0
Fix linter
hkalexling Sep 4, 2021
87e54aa
Merge branch 'dev' into feature/plugin-v2
hkalexling Nov 18, 2021
e442139
Refactor date filtering and use native date picker
hkalexling Nov 20, 2021
352236a
Delete unnecessary raise for debugging
hkalexling Nov 20, 2021
5442d12
Subscription management API endpoints
hkalexling Nov 20, 2021
fe6f884
Store manga ID with subscriptions
hkalexling Nov 20, 2021
b76d464
Add subscription manager page (WIP)
hkalexling Nov 21, 2021
031ea7e
Finish subscription manager page
hkalexling Nov 25, 2021
748386f
WIP
hkalexling Dec 31, 2021
5fac8c6
Merge branch 'dev' into feature/plugin-v2
hkalexling Jan 21, 2022
031df3a
Finish plugin updater
hkalexling Jan 22, 2022
d862c38
Base64 encode chapter IDs
hkalexling Jan 23, 2022
968f624
Fix actions on download manager
hkalexling Jan 23, 2022
2c7c29f
Trigger subscription update from manager page
hkalexling Jan 23, 2022
cae8329
Fix timestamp precision issue in plugin
hkalexling Jan 23, 2022
be3babd
Show target API version
hkalexling Jan 23, 2022
f6bd3fa
Update last checked from manager page
hkalexling Jan 23, 2022
0adcd3a
Update last checked even when no chapters found
hkalexling Jan 23, 2022
c80855b
Merge branch 'dev' into feature/plugin-v2
hkalexling Feb 20, 2022
fd650bd
Fix null pid
hkalexling Feb 20, 2022
b56a9cb
Clean up
hkalexling Feb 20, 2022
2ade6eb
Document the subscription endpoints
hkalexling Feb 20, 2022
c290eee
Fix BigFloat conversion issue
hkalexling Mar 15, 2022
8dfe580
Merge branch 'dev' into feature/plugin-v2
hkalexling Mar 15, 2022
acefa00
Merge branch 'dev' into feature/plugin-v2
hkalexling Mar 18, 2022
95eb208
Confirmation before deleting subscriptions
hkalexling Mar 19, 2022
2cc1a06
Reset table sort options
hkalexling Mar 19, 2022
cdfc9f3
Show manga title on subscription manager
hkalexling Mar 19, 2022
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
566 changes: 434 additions & 132 deletions public/js/plugin-download.js

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions public/js/subscription-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
const component = () => {
return {
subscriptions: [],
plugins: [],
pid: undefined,
subscription: undefined, // selected subscription
loading: false,

init() {
fetch(`${base_url}api/admin/plugin`)
.then((res) => res.json())
.then((data) => {
if (!data.success) throw new Error(data.error);
this.plugins = data.plugins;

const pid = localStorage.getItem("plugin");
if (pid && this.plugins.map((p) => p.id).includes(pid))
this.pid = pid;
else if (this.plugins.length > 0)
this.pid = this.plugins[0].id;

this.list(pid);
})
.catch((e) => {
alert(
"danger",
`Failed to list the available plugins. Error: ${e}`
);
});
},
pluginChanged() {
localStorage.setItem("plugin", this.pid);
this.list(this.pid);
},
list(pid) {
if (!pid) return;
fetch(
`${base_url}api/admin/plugin/subscriptions?${new URLSearchParams(
{
plugin: pid,
}
)}`,
{
method: "GET",
}
)
.then((response) => response.json())
.then((data) => {
if (!data.success) throw new Error(data.error);
this.subscriptions = data.subscriptions;
})
.catch((e) => {
alert(
"danger",
`Failed to list subscriptions. Error: ${e}`
);
});
},
renderStrCell(str) {
const maxLength = 40;
if (str.length > maxLength)
return `<td><span>${str.substring(
0,
maxLength
)}...</span><div uk-dropdown>${str}</div></td>`;
return `<td>${str}</td>`;
},
renderDateCell(timestamp) {
return `<td>${moment
.duration(moment.unix(timestamp).diff(moment()))
.humanize(true)}</td>`;
},
selected(event, modal) {
const id = event.currentTarget.getAttribute("sid");
this.subscription = this.subscriptions.find((s) => s.id === id);
UIkit.modal(modal).show();
},
renderFilterRow(ft) {
const key = ft.key;
let type = ft.type;
switch (type) {
case "number-min":
type = "number (minimum value)";
break;
case "number-max":
type = "number (maximum value)";
break;
case "date-min":
type = "minimum date";
break;
case "date-max":
type = "maximum date";
break;
}
let value = ft.value;

if (ft.type.startsWith("number") && isNaN(value)) value = "";
else if (ft.type.startsWith("date") && value)
value = moment(Number(value)).format("MMM D, YYYY");

return `<td>${key}</td><td>${type}</td><td>${value}</td>`;
},
actionHandler(event, type) {
const id = $(event.currentTarget).closest("tr").attr("sid");
if (type !== 'delete') return this.action(id, type);
UIkit.modal.confirm('Are you sure you want to delete the subscription? This cannot be undone.', {
labels: {
ok: 'Yes, delete it',
cancel: 'Cancel'
}
}).then(() => {
this.action(id, type);
});
},
action(id, type) {
if (this.loading) return;
this.loading = true;
fetch(
`${base_url}api/admin/plugin/subscriptions${type === 'update' ? '/update' : ''}?${new URLSearchParams(
{
plugin: this.pid,
subscription: id,
}
)}`,
{
method: type === 'delete' ? "DELETE" : 'POST'
}
)
.then((response) => response.json())
.then((data) => {
if (!data.success) throw new Error(data.error);
if (type === 'update')
alert("success", `Checking updates for subscription ${id}. Check the log for the progress or come back to this page later.`);
})
.catch((e) => {
alert(
"danger",
`Failed to ${type} subscription. Error: ${e}`
);
})
.finally(() => {
this.loading = false;
this.list(this.pid);
});
},
};
};
1 change: 1 addition & 0 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Config
property disable_login = false
property default_username = ""
property auth_proxy_header_name = ""
property plugin_update_interval_hours : Int32 = 24

@@singlet : Config?

Expand Down
1 change: 1 addition & 0 deletions src/library/entry.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Entry
json.field {{str}}, @{{str.id}}
{% end %}
json.field "title_id", @book.id
json.field "title_title", @book.title
json.field "sort_title", sort_title
json.field "pages" { json.number @pages }
unless slim
Expand Down
1 change: 1 addition & 0 deletions src/mango.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class CLI < Clim
Library.load_instance
Library.default
Plugin::Downloader.default
Plugin::Updater.default

spawn do
begin
Expand Down
Loading