diff options
Diffstat (limited to 'vnext/src/api')
-rw-r--r-- | vnext/src/api/index.js | 102 |
1 files changed, 100 insertions, 2 deletions
diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js index e6b1d2efd..330b3f9e3 100644 --- a/vnext/src/api/index.js +++ b/vnext/src/api/index.js @@ -3,6 +3,63 @@ import cookies from 'react-cookies'; const apiBaseUrl = 'https://juick.com'; +/** + * @typedef {Object} Token + * @property {string} type + * @property {string} token + */ + +/** + * @typedef {Object} User + * @property {string} uname + * @property {number} uid + * @property {number=} unreadCount + * @property {string=} avatar + * @property {User[]=} read + * @property {User[]=} readers + * @property {number=} statsMyBL + * @property {string=} uri + */ + +/** + * @typedef {Object} SecureUserProperties + * @property {string} hash + * @property {Token[]} tokens + */ + +/** + * @typedef {User & SecureUserProperties} SecureUser + */ + +/** + * @typedef {Object} ChatProperties + * @property {number=} unreadCount + * @property {string=} lastMessageText + */ + +/** + * @typedef {User & ChatProperties} Chat + */ + +/** + * @typedef {Object} Message + * @property {string} body + * @property {number=} mid + * @property {number=} rid + * @property {boolean=} service + * @property {User} user + * @property {User=} to + * @property {string=} replyQuote + * @property {string[]=} tags + * @property {number=} likes + * @property {number=} replies + * @property {string=} photo + * @property {string=} attach + * @property {string=} timestamp + * @property {boolean=} ReadOnly + */ + + const client = axios.create({ baseURL: apiBaseUrl }); @@ -13,6 +70,12 @@ client.interceptors.request.use(config => { return config; }); +/** + * fetch my info + * @param {string} username + * @param {string} password + * @return {Promise<SecureUser, Error>} me object + */ export function me(username = '', password = '') { return new Promise((resolve, reject) => { client.get('/api/me', { @@ -30,14 +93,21 @@ export function me(username = '', password = '') { }); } +/** + * @param {string} username + */ export function info(username) { return client.get(`/api/info/${username}`); } + export function getChats() { return client.get('/api/groups_pms'); } +/** + * @param {string} userName + */ export function getChat(userName) { return client.get('/api/pm', { params: { @@ -46,6 +116,10 @@ export function getChat(userName) { }); } +/** + * @param {string} userName + * @param {string} body + */ export function pm(userName, body) { let form = new FormData(); form.set('uname', userName); @@ -53,12 +127,20 @@ export function pm(userName, body) { return client.post('/api/pm', form); } +/** + * @param {string} path + * @param {{ mid: any; }} params + */ export function getMessages(path, params) { return client.get(path, { params: params }); } +/** + * @param {string} body + * @param {string} attach + */ export function post(body, attach) { let form = new FormData(); form.append('attach', attach); @@ -66,10 +148,16 @@ export function post(body, attach) { return client.post('/api/post', form); } +/** + * @param {number} mid + * @param {number} rid + * @param {string} body + * @param {string} attach + */ export function comment(mid, rid, body, attach) { let form = new FormData(); - form.append('mid', mid); - form.append('rid', rid); + form.append('mid', mid.toString()); + form.append('rid', rid.toString()); form.append('body', body); form.append('attach', attach); return client.post('/api/comment', form); @@ -89,6 +177,9 @@ export function updateAvatar(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}`; } @@ -101,10 +192,17 @@ export function vkLink() { return socialLink('vk'); } +/** + * @param {Message} msg + * @param {SecureUser} visitor + */ export function markReadTracker(msg, visitor) { return `${apiBaseUrl}/api/thread/mark_read/${msg.mid}-${msg.rid || 0}.gif?hash=${visitor.hash}`; } +/** + * @param {string} dataUri + */ export function fetchUserUri(dataUri) { return new Promise((resolve, reject) => { let form = new FormData(); |