diff --git a/public/js/plugin-download.js b/public/js/plugin-download.js index 746dda8..e1fba96 100644 --- a/public/js/plugin-download.js +++ b/public/js/plugin-download.js @@ -33,14 +33,13 @@ const search = () => { if (searching) return; - const query = $('#search-input').val(); + const query = $.param({ + query: $('#search-input').val(), + plugin: pid + }); $.ajax({ - type: 'POST', - url: base_url + 'api/admin/plugin/list', - data: JSON.stringify({ - query: query, - plugin: pid - }), + type: 'GET', + url: `${base_url}api/admin/plugin/list?${query}`, contentType: "application/json", dataType: 'json' }) diff --git a/public/js/reader.js b/public/js/reader.js index 2b42b0a..7ff46aa 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -220,14 +220,18 @@ const saveProgress = (idx, cb) => { console.log('saving progress', idx); const url = `${base_url}api/progress/${tid}/${idx}?${$.param({eid: eid})}`; - $.post(url) - .then(data => { - if (data.error) throw new Error(data.error); + $.ajax({ + method: 'PUT', + url: url, + dataType: 'json' + }) + .done(data => { + if (data.error) + alert('danger', data.error); if (cb) cb(); }) - .catch(e => { - console.error(e); - alert('danger', e); + .fail((jqXHR, status) => { + alert('danger', `Error: [${jqXHR.status}] ${jqXHR.statusText}`); }); } }; diff --git a/public/js/title.js b/public/js/title.js index f5ddc85..876c70c 100644 --- a/public/js/title.js +++ b/public/js/title.js @@ -67,14 +67,23 @@ const updateProgress = (tid, eid, page) => { }); if (eid) url += `?${query}`; - $.post(url, (data) => { - if (data.success) { - location.reload(); - } else { - error = data.error; - alert('danger', error); - } - }); + + $.ajax({ + method: 'PUT', + url: url, + dataType: 'json' + }) + .done(data => { + if (data.success) { + location.reload(); + } else { + error = data.error; + alert('danger', error); + } + }) + .fail((jqXHR, status) => { + alert('danger', `Error: [${jqXHR.status}] ${jqXHR.statusText}`); + }); }; const renameSubmit = (name, eid) => { @@ -96,7 +105,7 @@ const renameSubmit = (name, eid) => { url += `?${query}`; $.ajax({ - type: 'POST', + type: 'PUT', url: url, contentType: "application/json", dataType: 'json' @@ -131,6 +140,7 @@ const edit = (eid) => { const displayNameField = $('#display-name-field'); displayNameField.attr('value', displayName); + console.log(displayNameField); displayNameField.keyup(event => { if (event.keyCode === 13) { renameSubmit(displayNameField.val(), eid); @@ -220,7 +230,7 @@ const bulkProgress = (action, el) => { const ids = selectedIDs(); const url = `${base_url}api/bulk_progress/${action}/${tid}`; $.ajax({ - type: 'POST', + type: 'PUT', url: url, contentType: "application/json", dataType: 'json', diff --git a/public/js/user.js b/public/js/user.js index 9d69fd4..b1b910f 100644 --- a/public/js/user.js +++ b/public/js/user.js @@ -1,11 +1,16 @@ -function remove(username) { - $.post(base_url + 'api/admin/user/delete/' + username, function(data) { - if (data.success) { - location.reload(); - } - else { - error = data.error; - alert('danger', error); - } - }); -} +const remove = (username) => { + $.ajax({ + url: `${base_url}api/admin/user/delete/${username}`, + type: 'DELETE', + dataType: 'json' + }) + .done(data => { + if (data.success) + location.reload(); + else + alert('danger', data.error); + }) + .fail((jqXHR, status) => { + alert('danger', `Failed to delete the user. Error: [${jqXHR.status}] ${jqXHR.statusText}`); + }); +}; diff --git a/src/routes/api.cr b/src/routes/api.cr index ecb2f13..8bff6b4 100644 --- a/src/routes/api.cr +++ b/src/routes/api.cr @@ -140,6 +140,10 @@ class APIRouter < Router "error" => "string?", } + Koa.object "ids", { + "ids" => "$strAry", + } + Koa.describe "Returns a page in a manga entry" Koa.path "tid", desc: "Title ID" Koa.path "eid", desc: "Entry ID" @@ -252,7 +256,7 @@ class APIRouter < Router Koa.describe "Deletes a user with `username`" Koa.tag "admin" Koa.response 200, ref: "$result" - post "/api/admin/user/delete/:username" do |env| + delete "/api/admin/user/delete/:username" do |env| begin username = env.params.url["username"] @context.storage.delete_user username @@ -279,7 +283,7 @@ class APIRouter < Router Koa.query "eid", desc: "Entry ID", required: false Koa.path "page", desc: "The new page number indicating the progress" Koa.response 200, ref: "$result" - post "/api/progress/:tid/:page" do |env| + put "/api/progress/:tid/:page" do |env| begin username = get_username env title = (@context.library.get_title env.params.url["tid"]).not_nil! @@ -309,9 +313,9 @@ class APIRouter < Router Koa.describe "Updates the reading progress of multiple entries in a title" Koa.path "action", desc: "The action to perform. Can be either `read` or `unread`" Koa.path "tid", desc: "Title ID" - Koa.body ref: "$strAry", desc: "An array of entry IDs" + Koa.body ref: "$ids", desc: "An array of entry IDs" Koa.response 200, ref: "$result" - post "/api/bulk_progress/:action/:tid" do |env| + put "/api/bulk_progress/:action/:tid" do |env| begin username = get_username env title = (@context.library.get_title env.params.url["tid"]).not_nil! @@ -341,7 +345,7 @@ class APIRouter < Router Koa.query "eid", desc: "Entry ID", required: false Koa.path "name", desc: "The new display name" Koa.response 200, ref: "$result" - post "/api/admin/display_name/:tid/:name" do |env| + put "/api/admin/display_name/:tid/:name" do |env| begin title = (@context.library.get_title env.params.url["tid"]) .not_nil! @@ -566,10 +570,10 @@ class APIRouter < Router Koa.tag "admin" Koa.body ref: "$pluginListBody" Koa.response 200, ref: "$pluginList" - post "/api/admin/plugin/list" do |env| + get "/api/admin/plugin/list" do |env| begin - query = env.params.json["query"].as String - plugin = Plugin.new env.params.json["plugin"].as String + query = env.params.query["query"].as String + plugin = Plugin.new env.params.query["plugin"].as String json = plugin.list_chapters query chapters = json["chapters"]