Allow delete all missing items (#151)

This commit is contained in:
Alex Ling 2021-01-28 09:55:41 +00:00
parent b5db508005
commit a389fa7178
4 changed files with 66 additions and 7 deletions

View File

@ -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({

View File

@ -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|

View File

@ -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

View File

@ -2,6 +2,7 @@
<p x-show="empty" class="uk-text-lead uk-text-center">No missing items found.</p>
<div x-show="!empty">
<p>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.</p>
<button class="uk-button uk-button-danger" @click="rmAll()">Delete All</button>
<table class="uk-table uk-table-striped uk-overflow-auto">
<thead>
<tr>