pyload-client
Version:
A node wrapper module for pyLoad API
246 lines • 8.5 kB
JavaScript
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
const qs_1 = require("qs");
const axios_1 = require("axios");
const api_1 = require("./api");
__export(require("./api"));
class PyloadClient {
constructor(config) {
this.config = config;
}
async postQueryWithoutEncoding(url, data) {
const options = {
baseURL: this.config.apiUrl,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
const request = Object.assign({ session: this._session }, data);
return (await axios_1.default.post(url, request && qs_1.stringify(request), options)).data;
}
async postQuery(url, data) {
const requestEncoded = data &&
Object.keys(data).reduce((request, key) => {
request[key] = JSON.stringify(data[key]);
return request;
}, {});
return await this.postQueryWithoutEncoding(url, requestEncoded);
}
async connect() {
const result = await this.postQueryWithoutEncoding('login', {
username: this.config.username,
password: this.config.password,
remoteip: this.config.remoteip,
});
if (typeof result === 'string') {
this._session = result;
}
else if (result !== true) {
throw new Error('Unable to connect. Bad credentials ?');
}
}
async getConfigValue(category, option, section = api_1.ConfigSectionEnum.CORE) {
return await this.postQuery('getConfigValue', { category, option, section });
}
async setConfigValue(category, option, value, section = api_1.ConfigSectionEnum.CORE) {
await this.postQuery('setConfigValue', { category, option, section, value });
}
async getConfig() {
return await this.postQuery('getConfig');
}
async getPluginConfig() {
return await this.postQuery('getPluginConfig');
}
async pauseServer() {
return await this.postQuery('pauseServer');
}
async unpauseServer() {
return await this.postQuery('unpauseServer');
}
async togglePause() {
return await this.postQuery('togglePause');
}
async toggleReconnect() {
return await this.postQuery('toggleReconnect');
}
async statusServer() {
return await this.postQuery('statusServer');
}
async freeSpace() {
return await this.postQuery('freeSpace');
}
async getServerVersion() {
return await this.postQuery('getServerVersion');
}
async kill() {
return await this.postQuery('kill');
}
async restart() {
return await this.postQuery('restart');
}
async getLog(offset = 0) {
return await this.postQuery('getLog', { offset });
}
async isTimeDownload() {
return await this.postQuery('isTimeDownload');
}
async isTimeReconnect() {
return await this.postQuery('isTimeReconnect');
}
async statusDownloads() {
return await this.postQuery('statusDownloads');
}
async addPackage(name, links, dest = 1) {
return await this.postQuery('addPackage', { name, links, dest });
}
async parseURLs(params) {
return await this.postQuery('parseURLs', params);
}
async checkURLs(urls) {
return await this.postQuery('checkURLs', { urls });
}
async checkOnlineStatus(urls) {
return await this.postQuery('checkOnlineStatus', { urls });
}
async generatePackages(links) {
return await this.postQuery('generatePackages', { links });
}
async generateAndAddPackages(links, dest = 1) {
return await this.postQuery('generateAndAddPackages', { links, dest });
}
async checkAndAddPackages(links, dest = 1) {
await this.postQuery('checkAndAddPackages', { links, dest });
}
async getPackageData(pid) {
return await this.postQuery('getPackageData', { pid });
}
async getPackageInfo(pid) {
return await this.postQuery('getPackageInfo', { pid });
}
async getFileData(fid) {
return await this.postQuery('getFileData', { fid });
}
async deletePackages(pids) {
await this.postQuery('deletePackages', { pids });
}
async deleteFiles(fids) {
await this.postQuery('deleteFiles', { fids });
}
async getQueue() {
return await this.postQuery('getQueue');
}
async getQueueData() {
return await this.postQuery('getQueueData');
}
async getCollector() {
return await this.postQuery('getCollector');
}
async getCollectorData() {
return await this.postQuery('getCollectorData');
}
async addFiles(pid, links) {
return await this.postQuery('addFiles', { pid, links });
}
async pushToQueue(pid) {
return await this.postQuery('pushToQueue', { pid });
}
async pullFromQueue(pid) {
return await this.postQuery('pullFromQueue', { pid });
}
async restartPackage(pid) {
return await this.postQuery('restartPackage', { pid });
}
async restartFile(fid) {
return await this.postQuery('restartFile', { fid });
}
async recheckPackage(pid) {
return await this.postQuery('recheckPackage', { pid });
}
async stopAllDownloads() {
return await this.postQuery('stopAllDownloads');
}
async stopDownloads(fids) {
return await this.postQuery('stopDownloads', { fids });
}
async setPackageName(pid, name) {
return await this.postQuery('setPackageName', { pid, name });
}
async movePackage(destination, pid) {
return await this.postQuery('movePackage', { pid, destination });
}
async moveFiles(fids, pid) {
return await this.postQuery('moveFiles', { pid, fids });
}
async orderPackage(pid, position) {
return await this.postQuery('orderPackage', { pid, position });
}
async orderFile(fid, position) {
return await this.postQuery('orderFile', { fid, position });
}
async setPackageData(pid, data) {
return await this.postQuery('setPackageData', { pid, data });
}
async deleteFinished() {
return await this.postQuery('deleteFinished');
}
async restartFailed() {
return await this.postQuery('restartFailed');
}
async getPackageOrder(destination) {
return await this.postQuery('getPackageOrder', { destination });
}
async getFileOrder(pid) {
return await this.postQuery('getFileOrder', { pid });
}
async isCaptchaWaiting() {
return await this.postQuery('isCaptchaWaiting');
}
async getCaptchaTask(exclusive = false) {
return await this.postQuery('getCaptchaTask', { exclusive });
}
async getCaptchaTaskStatus(tid) {
return await this.postQuery('getCaptchaTaskStatus', { tid });
}
async setCaptchaTaskStatus(tid, result) {
return await this.postQuery('setCaptchaTaskStatus', { tid, result });
}
async getAccounts(refresh) {
return await this.postQuery('getAccounts', { refresh });
}
async getAccountTypes() {
return await this.postQuery('getAccountTypes');
}
async updateAccount(plugin, account, password, options = {}) {
return await this.postQuery('updateAccount', { plugin, account, password, options });
}
async removeAccount(plugin, account) {
return await this.postQuery('removeAccount', { plugin, account });
}
async getUserData(username, password) {
return await this.postQuery('getUserData', { username, password });
}
async getAllUserData() {
return await this.postQuery('getAllUserData');
}
async getServices() {
return await this.postQuery('getServices');
}
async hasService(plugin, func) {
return await this.postQuery('hasService', { plugin, func });
}
async getAllInfo() {
return await this.postQuery('getAllInfo');
}
async getInfoByPlugin(plugin) {
return await this.postQuery('getInfoByPlugin', { plugin });
}
async changePassword(user, oldpw, newpw) {
return await this.postQuery('changePassword', { user, oldpw, newpw });
}
}
exports.PyloadClient = PyloadClient;
//# sourceMappingURL=index.js.map