Merge pull request #311 from hkalexling/fix/hide-subscribe-btn

Hide subscribe btn
This commit is contained in:
Alex Ling 2022-07-18 20:03:10 +08:00 committed by GitHub
commit 98a0c54499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 4 deletions

View File

@ -1,6 +1,7 @@
const component = () => { const component = () => {
return { return {
plugins: [], plugins: [],
subscribable: false,
info: undefined, info: undefined,
pid: undefined, pid: undefined,
chapters: undefined, // undefined: not searched yet, []: empty chapters: undefined, // undefined: not searched yet, []: empty
@ -60,6 +61,7 @@ const component = () => {
.then((data) => { .then((data) => {
if (!data.success) throw new Error(data.error); if (!data.success) throw new Error(data.error);
this.info = data.info; this.info = data.info;
this.subscribable = data.subscribable;
this.pid = pid; this.pid = pid;
}) })
.catch((e) => { .catch((e) => {
@ -70,6 +72,9 @@ const component = () => {
}); });
}, },
pluginChanged() { pluginChanged() {
this.manga = undefined;
this.chapters = undefined;
this.mid = undefined;
this.loadPlugin(this.pid); this.loadPlugin(this.pid);
localStorage.setItem("plugin", this.pid); localStorage.setItem("plugin", this.pid);
}, },
@ -140,6 +145,7 @@ const component = () => {
if (!query) return; if (!query) return;
this.manga = undefined; this.manga = undefined;
this.mid = undefined;
if (this.info.version === 1) { if (this.info.version === 1) {
this.searchChapters(query); this.searchChapters(query);
} else { } else {

View File

@ -38,6 +38,7 @@ class Logger
Log.setup do |c| Log.setup do |c|
c.bind "*", @@severity, @backend c.bind "*", @@severity, @backend
c.bind "db.*", :error, @backend c.bind "db.*", :error, @backend
c.bind "duktape", :none, @backend
end end
end end

View File

@ -224,6 +224,10 @@ class Plugin
raise Error.new "Missing required fields in the Page type" raise Error.new "Missing required fields in the Page type"
end end
def can_subscribe? : Bool
info.version > 1 && eval_exists?("newChapters")
end
def search_manga(query : String) def search_manga(query : String)
if info.version == 1 if info.version == 1
raise Error.new "Manga searching is only available for plugins " \ raise Error.new "Manga searching is only available for plugins " \
@ -328,6 +332,15 @@ class Plugin
JSON.parse eval(str).as String JSON.parse eval(str).as String
end 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) private def def_helper_functions(sbx)
sbx.push_object sbx.push_object

View File

@ -871,13 +871,15 @@ struct APIRouter
"version" => Int32, "version" => Int32,
"settings" => {} of String => String, "settings" => {} of String => String,
}, },
"subscribable" => Bool,
} }
get "/api/admin/plugin/info" do |env| get "/api/admin/plugin/info" do |env|
begin begin
plugin = Plugin.new env.params.query["plugin"].as String plugin = Plugin.new env.params.query["plugin"].as String
send_json env, { send_json env, {
"success" => true, "success" => true,
"info" => plugin.info, "info" => plugin.info,
"subscribable" => plugin.can_subscribe?,
}.to_json }.to_json
rescue e rescue e
Logger.error e Logger.error e

View File

@ -133,8 +133,10 @@
</template> </template>
<button class="uk-button uk-button-primary" @click.prevent="applyFilters()">Apply</button> <button class="uk-button uk-button-primary" @click.prevent="applyFilters()">Apply</button>
<button class="uk-button uk-button-default" @click.prevent="clearFilters()">Clear</button> <button class="uk-button uk-button-default" @click.prevent="clearFilters()">Clear</button>
<span class="uk-divider-vertical uk-margin-left uk-margin-right"></span> <span x-show="subscribable">
<button class="uk-button uk-button-default" @click.prevent="UIkit.modal($refs.modal).show()" :disable="subscribing">Subscribe</button> <span class="uk-divider-vertical uk-margin-left uk-margin-right"></span>
<button class="uk-button uk-button-default" @click.prevent="UIkit.modal($refs.modal).show()" :disable="subscribing">Subscribe</button>
</span>
</form> </form>
<p class="uk-text-meta" x-show="chapters && chapters.length > chaptersLimit" x-text="`The manga has ${chapters ? chapters.length : 0} chapters, but Mango can only list up to ${chaptersLimit}. Please use the filters to narrow down your search.`"></p> <p class="uk-text-meta" x-show="chapters && chapters.length > chaptersLimit" x-text="`The manga has ${chapters ? chapters.length : 0} chapters, but Mango can only list up to ${chaptersLimit}. Please use the filters to narrow down your search.`"></p>