aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/src/api')
-rw-r--r--vnext/src/api/index.js144
1 files changed, 72 insertions, 72 deletions
diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js
index ef753eaf..566478a9 100644
--- a/vnext/src/api/index.js
+++ b/vnext/src/api/index.js
@@ -1,7 +1,7 @@
-import axios from 'axios';
-import Cookies from 'universal-cookie';
+import axios from 'axios'
+import Cookies from 'universal-cookie'
-const apiBaseUrl = 'https://juick.com';
+const apiBaseUrl = 'https://juick.com'
/**
* @typedef {object} Token
@@ -73,17 +73,17 @@ const apiBaseUrl = 'https://juick.com';
const client = axios.create({
baseURL: apiBaseUrl
-});
+})
client.interceptors.request.use(config => {
if (config.url.startsWith('/')) {
// only local URLs
- let cookies = new Cookies();
+ let cookies = new Cookies()
config.params = Object.assign(config.params || {}, {
hash: cookies.get('hash')
- });
+ })
}
- return config;
-});
+ return config
+})
/**
* fetch my info
@@ -92,28 +92,28 @@ client.interceptors.request.use(config => {
* @returns {Promise<SecureUser, Error>} me object
*/
export function me(username = '', password = '') {
- let cookies = new Cookies();
+ let cookies = new Cookies()
return new Promise((resolve, reject) => {
client.get('/api/me', {
headers: username ? {
'Authorization': 'Basic ' + window.btoa(unescape(encodeURIComponent(username + ':' + password)))
} : {}
}).then(response => {
- let visitor = response.data;
- cookies.set('hash', visitor.hash, { path: '/' });
- resolve(visitor);
+ let visitor = response.data
+ cookies.set('hash', visitor.hash, { path: '/' })
+ resolve(visitor)
}).catch(reason => {
- cookies.remove('hash', { path: '/' });
- reject(reason);
- });
- });
+ cookies.remove('hash', { path: '/' })
+ reject(reason)
+ })
+ })
}
/**
* @param {string} username
*/
export function info(username) {
- return client.get(`/api/info/${username}`);
+ return client.get(`/api/info/${username}`)
}
@@ -121,7 +121,7 @@ export function info(username) {
*
*/
export function getChats() {
- return client.get('/api/groups_pms');
+ return client.get('/api/groups_pms')
}
/**
@@ -132,7 +132,7 @@ export function getChat(userName) {
params: {
'uname': userName
}
- });
+ })
}
/**
@@ -140,10 +140,10 @@ export function getChat(userName) {
* @param {string} body
*/
export function pm(userName, body) {
- let form = new FormData();
- form.set('uname', userName);
- form.set('body', body);
- return client.post('/api/pm', form);
+ let form = new FormData()
+ form.set('uname', userName)
+ form.set('body', body)
+ return client.post('/api/pm', form)
}
/**
@@ -153,7 +153,7 @@ export function pm(userName, body) {
export function getMessages(path, params) {
return client.get(path, {
params: params
- });
+ })
}
/**
@@ -161,10 +161,10 @@ export function getMessages(path, params) {
* @param {string} attach
*/
export function post(body, attach) {
- let form = new FormData();
- form.append('attach', attach);
- form.append('body', body);
- return client.post('/api/post', form);
+ let form = new FormData()
+ form.append('attach', attach)
+ form.append('body', body)
+ return client.post('/api/post', form)
}
/**
@@ -174,12 +174,12 @@ export function post(body, attach) {
* @param {string} attach
*/
export function comment(mid, rid, body, attach) {
- let form = new FormData();
- form.append('mid', mid.toString());
- form.append('rid', rid.toString());
- form.append('body', body);
- form.append('attach', attach);
- return client.post('/api/comment', form);
+ let form = new FormData()
+ form.append('mid', mid.toString())
+ form.append('rid', rid.toString())
+ form.append('body', body)
+ form.append('attach', attach)
+ return client.post('/api/comment', form)
}
/**
* Edit message
@@ -188,48 +188,48 @@ export function comment(mid, rid, body, attach) {
* @param {string?} body
*/
export function update(mid, rid, body) {
- let form = new FormData();
- form.append('mid', mid);
- form.append('rid', rid);
- form.append('body', body);
- return client.post('/api/update', form);
+ let form = new FormData()
+ form.append('mid', mid)
+ form.append('rid', rid)
+ form.append('body', body)
+ return client.post('/api/update', form)
}
/**
* Update user avatar
* @param {string} newAvatar
*/
export function updateAvatar(newAvatar) {
- let form = new FormData();
- form.append('avatar', newAvatar);
- return client.post('/api/me/upload', form);
+ let form = new FormData()
+ form.append('avatar', newAvatar)
+ return client.post('/api/me/upload', form)
}
/**
* @param {string} network
*/
function socialLink(network) {
- return `${apiBaseUrl}/api/_${network}login?state=${window.location.protocol}//${window.location.host}${window.location.pathname}`;
+ return `${apiBaseUrl}/api/_${network}login?state=${window.location.protocol}//${window.location.host}${window.location.pathname}`
}
/**
*
*/
export function facebookLink() {
- return socialLink('fb');
+ return socialLink('fb')
}
/**
*
*/
export function vkLink() {
- return socialLink('vk');
+ return socialLink('vk')
}
/**
*
*/
export function appleLink() {
- return socialLink('apple');
+ return socialLink('apple')
}
/**
@@ -237,10 +237,10 @@ export function appleLink() {
* @param {SecureUser} visitor
*/
export function markReadTracker(msg, visitor) {
- return `${apiBaseUrl}/api/thread/mark_read/${msg.mid}-${msg.rid || 0}.gif?hash=${visitor.hash}`;
+ return `${apiBaseUrl}/api/thread/mark_read/${msg.mid}-${msg.rid || 0}.gif?hash=${visitor.hash}`
}
-let profileCache = {};
+let profileCache = {}
/**
* Fetch user profile
@@ -249,18 +249,18 @@ let profileCache = {};
export function fetchUserUri(profileUrl) {
return new Promise((resolve, reject) => {
if (profileCache[profileUrl]) {
- resolve(profileCache[profileUrl]);
+ resolve(profileCache[profileUrl])
} else {
client.get(profileUrl, {
headers: {
'Accept': 'application/ld+json'
}
}).then(response => {
- profileCache[profileUrl] = response.data;
- resolve(response.data);
- }).catch(reject);
+ profileCache[profileUrl] = response.data
+ resolve(response.data)
+ }).catch(reject)
}
- });
+ })
}
/**
@@ -269,13 +269,13 @@ export function fetchUserUri(profileUrl) {
*/
export const trends = async () => {
try {
- const response = await client.get('/api/tags');
- return response.data;
+ const response = await client.get('/api/tags')
+ return response.data
} catch (e) {
- console.error(e);
- return [];
+ console.error(e)
+ return []
}
-};
+}
/**
* Fetch Tweet content
@@ -289,9 +289,9 @@ export function fetchUserUri(profileUrl) {
'omit_script': true,
'url': url
}
- });
- return response.data;
-};
+ })
+ return response.data
+}
/**
* Checks if HTTP error code is redirection code
@@ -299,7 +299,7 @@ export function fetchUserUri(profileUrl) {
* @returns {boolean} is HTTP request redirected or not
*/
function isHttpRedirected(code = 200) {
- return [301, 302].includes(code);
+ return [301, 302].includes(code)
}
/**
@@ -308,7 +308,7 @@ function isHttpRedirected(code = 200) {
* @returns {boolean} is HTTP request successful or not
*/
function isHttpSuccessful(code = 200) {
- return code >= 200 && code < 300;
+ return code >= 200 && code < 300
}
/**
@@ -323,25 +323,25 @@ function expandShortenedLink(url = '') {
}).then(response => {
if (isHttpSuccessful(response.status)) {
// URL is not redirected
- resolve(url);
- return;
+ resolve(url)
+ return
}
if (isHttpRedirected(response.status)) {
- resolve(/** @type { string } */ (response.headers['Location']));
- return;
+ resolve(/** @type { string } */ (response.headers['Location']))
+ return
}
// Error case
- reject('Invalid response');
+ reject('Invalid response')
}).catch(error => {
- reject(error);
- });
- });
+ reject(error)
+ })
+ })
}
export {
embeddedTweet,
expandShortenedLink
-};
+}