1
0
mirror of https://github.com/danbee/my-images synced 2025-03-04 08:49:05 +00:00
my-images/app/javascript/services/ajax_service.js
2024-03-25 20:26:50 -05:00

33 lines
618 B
JavaScript

import axios from "axios";
const csrfToken = () => {
return document
.getElementsByName("csrf-token")[0]
.attributes["content"]
.value;
}
const imageId = () => {
return document
.getElementsByClassName("show-image")[0]
.attributes["data-image-id"]
.value;
}
const config = () => ({
headers: { "X-CSRF-Token": csrfToken() }
});
export default {
createTag: (tag) => {
return axios.post(`/images/${imageId()}/tags`, { tag }, config());
},
deleteTag: (tag) => {
return axios.delete(
`/images/${imageId()}/tags/${encodeURIComponent(tag)}`,
config()
);
}
}