diff --git a/public/js/title.js b/public/js/title.js index fb4f4c1..7ddd093 100644 --- a/public/js/title.js +++ b/public/js/title.js @@ -256,11 +256,13 @@ const bulkProgress = (action, el) => { const tagsComponent = () => { return { loading: true, + isAdmin: false, tags: [], newTag: '', inputShown: false, tid: $('.upload-field').attr('data-title-id'), - load() { + load(admin) { + this.isAdmin = admin; const url = `${base_url}api/tags/${this.tid}`; this.request(url, 'GET', (data) => { this.tags = data.tags; @@ -269,7 +271,7 @@ const tagsComponent = () => { }, add() { const tag = this.newTag.trim(); - const url = `${base_url}api/tags/${this.tid}/${encodeURIComponent(tag)}`; + const url = `${base_url}api/admin/tags/${this.tid}/${encodeURIComponent(tag)}`; this.request(url, 'PUT', () => { this.tags.push(tag); this.newTag = ''; @@ -281,7 +283,7 @@ const tagsComponent = () => { }, rm(event) { const tag = event.currentTarget.id.split('-')[0]; - const url = `${base_url}api/tags/${this.tid}/${encodeURIComponent(tag)}`; + const url = `${base_url}api/admin/tags/${this.tid}/${encodeURIComponent(tag)}`; this.request(url, 'DELETE', () => { const idx = this.tags.indexOf(tag); if (idx < 0) return; @@ -295,9 +297,6 @@ const tagsComponent = () => { $('#tag-input').get(0).focus(); }); } - }, - buildURL(tid, tag) { - }, request(url, method, cb) { $.ajax({ diff --git a/src/routes/api.cr b/src/routes/api.cr index 9a85215..4ec7407 100644 --- a/src/routes/api.cr +++ b/src/routes/api.cr @@ -715,7 +715,8 @@ class APIRouter < Router Koa.describe "Adds a new tag to a title" Koa.path "tid", desc: "A title ID" Koa.response 200, ref: "$result" - put "/api/tags/:tid/:tag" do |env| + Koa.tag "admin" + put "/api/admin/tags/:tid/:tag" do |env| begin title = (@context.library.get_title env.params.url["tid"]).not_nil! tag = env.params.url["tag"] @@ -737,7 +738,8 @@ class APIRouter < Router Koa.describe "Deletes a tag from a title" Koa.path "tid", desc: "A title ID" Koa.response 200, ref: "$result" - delete "/api/tags/:tid/:tag" do |env| + Koa.tag "admin" + delete "/api/admin/tags/:tid/:tag" do |env| begin title = (@context.library.get_title env.params.url["tid"]).not_nil! tag = env.params.url["tag"] diff --git a/src/views/components/tags.html.ecr b/src/views/components/tags.html.ecr index 4385569..67588a5 100644 --- a/src/views/components/tags.html.ecr +++ b/src/views/components/tags.html.ecr @@ -1,12 +1,12 @@ -