mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-05-21 05:08:35 +00:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
import { instance, wrapper } from "./Api";
|
|
|
|
const config = require('../config.js');
|
|
|
|
let domain = "";
|
|
if (config.serverURL) domain = config.serverURL+"/"
|
|
|
|
export default {
|
|
// TODO: add ?continue=id
|
|
get(channelID, continueMessageID, beforeMessageID) {
|
|
return wrapper(
|
|
instance().get(
|
|
domain+`messages/channels/${channelID}${
|
|
continueMessageID
|
|
? "?continue=" + continueMessageID
|
|
: beforeMessageID
|
|
? "?before=" + beforeMessageID
|
|
: ""
|
|
}`
|
|
)
|
|
);
|
|
},
|
|
delete(messageID, channelID) {
|
|
return wrapper(
|
|
instance().delete(domain+`messages/${messageID}/channels/${channelID}`)
|
|
);
|
|
},
|
|
update(messageID, channelID, data) {
|
|
return wrapper(
|
|
instance().patch(domain+`messages/${messageID}/channels/${channelID}`, data)
|
|
);
|
|
},
|
|
|
|
post(channelID, data, onProgress) {
|
|
const url = `messages/channels/${channelID}`;
|
|
|
|
//var start = +new Date();
|
|
|
|
let config = {
|
|
onUploadProgress(progressEvent) {
|
|
const percentCompleted = Math.round(
|
|
(progressEvent.loaded * 100) / progressEvent.total
|
|
);
|
|
|
|
// execute the callback
|
|
if (onProgress) onProgress(percentCompleted);
|
|
|
|
return percentCompleted;
|
|
}
|
|
};
|
|
|
|
return wrapper(instance().post(domain+url, data, config));
|
|
}
|
|
};
|