Trigger subscription update from manager page

This commit is contained in:
Alex Ling 2022-01-23 09:45:45 +00:00
parent 968f6246de
commit 2c7c29fef9
5 changed files with 30 additions and 6 deletions

View File

@ -104,24 +104,26 @@ const component = () => {
this.loading = true; this.loading = true;
const id = $(event.currentTarget).closest("tr").attr("sid"); const id = $(event.currentTarget).closest("tr").attr("sid");
fetch( fetch(
`${base_url}api/admin/plugin/subscriptions?${new URLSearchParams( `${base_url}api/admin/plugin/subscriptions${type === 'update' ? '/update' : ''}?${new URLSearchParams(
{ {
plugin: this.pid, plugin: this.pid,
subscription: id, subscription: id,
} }
)}`, )}`,
{ {
method: "DELETE", method: type === 'delete' ? "DELETE" : 'POST'
} }
) )
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
if (!data.success) throw new Error(data.error); 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) => { .catch((e) => {
alert( alert(
"danger", "danger",
`Failed to delete subscription. Error: ${e}` `Failed to ${type} subscription. Error: ${e}`
); );
}) })
.finally(() => { .finally(() => {

View File

@ -61,7 +61,7 @@ class CLI < Clim
Library.load_instance Library.load_instance
Library.default Library.default
Plugin::Downloader.default Plugin::Downloader.default
Plugin::Updater.new Plugin::Updater.default
spawn do spawn do
begin begin

View File

@ -153,6 +153,11 @@ class Plugin
list.save list.save
end end
def check_subscription(id : String)
sub = list_subscriptions_raw.find &.id.== id
Plugin::Updater.default.check_subscription self, sub.not_nil!
end
def initialize(id : String) def initialize(id : String)
Plugin.build_info_ary Plugin.build_info_ary

View File

@ -1,7 +1,7 @@
require "../config"
class Plugin class Plugin
class Updater class Updater
use_default
def initialize def initialize
interval = Config.current.plugin_update_interval_hours interval = Config.current.plugin_update_interval_hours
return if interval <= 0 return if interval <= 0

View File

@ -721,6 +721,23 @@ struct APIRouter
end end
end end
post "/api/admin/plugin/subscriptions/update" do |env|
pid = env.params.query["plugin"].as String
sid = env.params.query["subscription"].as String
Plugin.new(pid).check_subscription sid
send_json env, {
"success" => true,
}.to_json
rescue e
Logger.error e
send_json env, {
"success" => false,
"error" => e.message,
}.to_json
end
Koa.describe "Lists the chapters in a title from a plugin" Koa.describe "Lists the chapters in a title from a plugin"
Koa.tags ["admin", "downloader"] Koa.tags ["admin", "downloader"]
Koa.query "plugin", schema: String Koa.query "plugin", schema: String