summaryrefslogtreecommitdiff
path: root/client/client.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/client.js')
-rw-r--r--client/client.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/client/client.js b/client/client.js
new file mode 100644
index 0000000..a48b53e
--- /dev/null
+++ b/client/client.js
@@ -0,0 +1,82 @@
+function get() {
+ return {
+ method: 'GET',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ }
+}
+function post(data) {
+ return {
+ method: 'POST',
+ body: JSON.stringify(data),
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ }
+}
+function postBody(data) {
+ return {
+ method: 'POST',
+ headers: {
+ 'Accept': 'application/json',
+ },
+ body: data,
+ }
+}
+function put(data) {
+ return {
+ method: 'PUT',
+ body: data,
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ }
+}
+function error(err) {
+ console.warn(err)
+}
+
+export default {
+ folder: {
+ index: () => {
+ return fetch('/folders/')
+ .then(req => req.json())
+ .catch(error)
+ },
+
+ show: (id) => {
+ return fetch('/folders/' + id)
+ .then(req => req.json())
+ .catch(error)
+ },
+
+ create: (data) => {
+ return fetch('/folders/new', post(data))
+ .then(req => req.json())
+ .catch(error)
+ },
+
+ update: (data) => {
+ return fetch('/folders/' + data.id, put(data))
+ .then(req => req.json())
+ .catch(error)
+ },
+ },
+
+ file: {
+ upload: (folder_id, files) => {
+ var data = new FormData()
+ for (var i = 0; i < files.length; i++) {
+ data.append('file', files[i])
+ }
+ return fetch('/folders/' + folder_id, postBody(files))
+ .then(req => req.json())
+ .catch(error)
+ },
+ },
+
+} \ No newline at end of file