summaryrefslogtreecommitdiff
path: root/client/client.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-06-29 01:18:06 +0200
committerJules Laplace <julescarbon@gmail.com>2017-06-29 01:18:06 +0200
commit50904f4b010c417d558174005a7b4c5868e7d8d9 (patch)
tree2fb9bad10e09ff66ccc5313289a62367843326a3 /client/client.js
parenta190d638c608f4352e3f01d72ed419a5ab5129ed (diff)
sketch folder stuff
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