aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/api/index.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-27 14:33:34 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:53 +0300
commit40b8cd9853dd87deb90afdda0f5af78faa414f2b (patch)
treef4beb12efd422f178cfe168367ef91b17f6131b8 /vnext/src/api/index.js
parent8307e220c4fdddbc0a9740ad4b43fc2e205864bd (diff)
fetch -> axios
Diffstat (limited to 'vnext/src/api/index.js')
-rw-r--r--vnext/src/api/index.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js
new file mode 100644
index 00000000..130a5dc2
--- /dev/null
+++ b/vnext/src/api/index.js
@@ -0,0 +1,63 @@
+import axios from 'axios';
+
+const client = axios.create({
+ baseURL: 'https://api.juick.com/'
+});
+client.interceptors.request.use(config => {
+ if (localStorage.visitor) {
+ config.params = Object.assign(config.params || {}, {
+ hash: JSON.parse(localStorage.visitor).hash
+ });
+ }
+ return config;
+})
+
+export function auth(username, password) {
+ return new Promise((resolve, reject) => {
+ client.get('/me', {
+ headers: {
+ 'Authorization': 'Basic ' + window.btoa(unescape(encodeURIComponent(username + ":" + password)))
+ }
+ }).then(response => {
+ localStorage.visitor = JSON.stringify(response.data);
+ resolve(response.data)
+ }).catch(reason => {
+ localStorage.clear()
+ reject(reason)
+ })
+ });
+}
+
+export function getChats() {
+ return client.get('/groups_pms')
+}
+
+export function getChat(userName) {
+ return client.get('/pm', {
+ params: {
+ 'uname': userName
+ }
+ })
+}
+
+export function pm(userName, body) {
+ let form = new FormData();
+ form.set('uname', userName);
+ form.set('body', body);
+ return client.post('/pm', form)
+}
+
+export function getMessages(path, params) {
+ return client.get(path, {
+ params: params
+ })
+}
+
+export function comment(mid, rid, body, attach) {
+ let form = new FormData();
+ form.append('mid', mid);
+ form.append('rid', rid);
+ form.append('body', body);
+ form.append('attach', attach);
+ return client.post('/comment', form)
+} \ No newline at end of file