From a389fa7178266ac36442326d4151738c5448a0a8 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Thu, 28 Jan 2021 09:55:41 +0000 Subject: [PATCH] Allow delete all missing items (#151) --- public/js/missing-items.js | 14 ++++++++++ src/routes/api.cr | 44 ++++++++++++++++++++++++++++++-- src/storage.cr | 14 ++++++---- src/views/missing-items.html.ecr | 1 + 4 files changed, 66 insertions(+), 7 deletions(-) diff --git a/public/js/missing-items.js b/public/js/missing-items.js index 0d7fa08..0babb24 100644 --- a/public/js/missing-items.js +++ b/public/js/missing-items.js @@ -24,6 +24,20 @@ const component = () => { this.load(); }); }, + rmAll() { + UIkit.modal.confirm('Are you sure? All metadata associated with these items, including their tags and thumbnails, will be deleted from the database.', { + labels: { + ok: 'Yes, delete them', + cancel: 'Cancel' + } + }).then(() => { + this.request('DELETE', `${base_url}api/admin/titles/missing`, () => { + this.request('DELETE', `${base_url}api/admin/entries/missing`, () => { + this.load(); + }); + }); + }); + }, request(method, url, cb) { console.log(url); $.ajax({ diff --git a/src/routes/api.cr b/src/routes/api.cr index cc61ba0..7fc8b46 100644 --- a/src/routes/api.cr +++ b/src/routes/api.cr @@ -828,7 +828,45 @@ struct APIRouter end end - Koa.describe "Deletes a missing title with `tid`" + Koa.describe "Deletes all missing titles" + Koa.response 200, ref: "$result" + Koa.tag "admin" + delete "/api/admin/titles/missing" do |env| + begin + Storage.default.delete_missing_title + send_json env, { + "success" => true, + "error" => nil, + }.to_json + rescue e + send_json env, { + "success" => false, + "error" => e.message, + }.to_json + end + end + + Koa.describe "Deletes all missing entries" + Koa.response 200, ref: "$result" + Koa.tag "admin" + delete "/api/admin/entries/missing" do |env| + begin + Storage.default.delete_missing_entry + send_json env, { + "success" => true, + "error" => nil, + }.to_json + rescue e + send_json env, { + "success" => false, + "error" => e.message, + }.to_json + end + end + + Koa.describe "Deletes a missing title identified by `tid`", <<-MD + Does nothing if the given `tid` is not found or if the title is not missing. + MD Koa.response 200, ref: "$result" Koa.tag "admin" delete "/api/admin/titles/missing/:tid" do |env| @@ -847,7 +885,9 @@ struct APIRouter end end - Koa.describe "Deletes a missing entry with `eid`" + Koa.describe "Deletes a missing entry identified by `eid`", <<-MD + Does nothing if the given `eid` is not found or if the entry is not missing. + MD Koa.response 200, ref: "$result" Koa.tag "admin" delete "/api/admin/entries/missing/:eid" do |env| diff --git a/src/storage.cr b/src/storage.cr index 548c9fc..2bc6daa 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -493,11 +493,15 @@ class Storage ary end - private def delete_missing(tablename, id) + private def delete_missing(tablename, id : String? = nil) MainFiber.run do get_db do |db| - db.exec "delete from #{tablename} where id = (?) and unavailable = 1", - id + if id + db.exec "delete from #{tablename} where id = (?) " \ + "and unavailable = 1", id + else + db.exec "delete from #{tablename} where unavailable = 1" + end end end end @@ -510,11 +514,11 @@ class Storage get_missing "titles" end - def delete_missing_entry(id) + def delete_missing_entry(id = nil) delete_missing "ids", id end - def delete_missing_title(id) + def delete_missing_title(id = nil) delete_missing "titles", id end diff --git a/src/views/missing-items.html.ecr b/src/views/missing-items.html.ecr index 878aada..334e185 100644 --- a/src/views/missing-items.html.ecr +++ b/src/views/missing-items.html.ecr @@ -2,6 +2,7 @@

No missing items found.

The following items were present in your library, but now we can't find them anymore. If you deleted them mistakenly, try to recover the files or folders, put them back to where they were, and rescan the library. Otherwise, you can safely delete them and the associated metadata using the buttons below to free up database space.

+