diff --git a/public/js/plugin-download.js b/public/js/plugin-download.js index 2e9d0a0..0f19738 100644 --- a/public/js/plugin-download.js +++ b/public/js/plugin-download.js @@ -1,6 +1,7 @@ const component = () => { return { plugins: [], + subscribable: false, info: undefined, pid: undefined, chapters: undefined, // undefined: not searched yet, []: empty @@ -60,6 +61,7 @@ const component = () => { .then((data) => { if (!data.success) throw new Error(data.error); this.info = data.info; + this.subscribable = data.subscribable; this.pid = pid; }) .catch((e) => { @@ -70,6 +72,9 @@ const component = () => { }); }, pluginChanged() { + this.manga = undefined; + this.chapters = undefined; + this.mid = undefined; this.loadPlugin(this.pid); localStorage.setItem("plugin", this.pid); }, @@ -140,6 +145,7 @@ const component = () => { if (!query) return; this.manga = undefined; + this.mid = undefined; if (this.info.version === 1) { this.searchChapters(query); } else { diff --git a/src/logger.cr b/src/logger.cr index 040e5aa..3fc5643 100644 --- a/src/logger.cr +++ b/src/logger.cr @@ -38,6 +38,7 @@ class Logger Log.setup do |c| c.bind "*", @@severity, @backend c.bind "db.*", :error, @backend + c.bind "duktape", :none, @backend end end diff --git a/src/plugin/plugin.cr b/src/plugin/plugin.cr index ef7c369..d553ae8 100644 --- a/src/plugin/plugin.cr +++ b/src/plugin/plugin.cr @@ -224,6 +224,10 @@ class Plugin raise Error.new "Missing required fields in the Page type" end + def can_subscribe? : Bool + info.version > 1 && eval_exists?("newChapters") + end + def search_manga(query : String) if info.version == 1 raise Error.new "Manga searching is only available for plugins " \ @@ -328,6 +332,15 @@ class Plugin JSON.parse eval(str).as String end + private def eval_exists?(str) : Bool + @rt.eval str + true + rescue e : Duktape::ReferenceError + false + rescue e : Duktape::Error + raise Error.new e.message + end + private def def_helper_functions(sbx) sbx.push_object diff --git a/src/routes/api.cr b/src/routes/api.cr index 89b4a30..8d31fea 100644 --- a/src/routes/api.cr +++ b/src/routes/api.cr @@ -871,13 +871,15 @@ struct APIRouter "version" => Int32, "settings" => {} of String => String, }, + "subscribable" => Bool, } get "/api/admin/plugin/info" do |env| begin plugin = Plugin.new env.params.query["plugin"].as String send_json env, { - "success" => true, - "info" => plugin.info, + "success" => true, + "info" => plugin.info, + "subscribable" => plugin.can_subscribe?, }.to_json rescue e Logger.error e diff --git a/src/views/plugin-download.html.ecr b/src/views/plugin-download.html.ecr index 7c3b4d5..3ff107b 100644 --- a/src/views/plugin-download.html.ecr +++ b/src/views/plugin-download.html.ecr @@ -133,8 +133,10 @@ - - + + + +