reorganizing file structures;
This commit is contained in:
3
src/utils/aria2Options.js
Normal file
3
src/utils/aria2Options.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const aria2Options = ["ca-certificate", "certificate", "dht-file-path", "dht-file-path6", "dir", "input-file", "load-cookies", "log", "metalink-file", "netrc-path", "on-bt-download-complete", "on-download-complete", "on-download-error", "on-download-start", "on-download-stop", "on-download-pause", "out", "private-key", "rpc-certificate", "rpc-private-key", "save-cookies", "save-session", "server-stat-if", "server-stat-of", "torrent-file", "all-proxy", "all-proxy-passwd", "all-proxy-user", "allow-overwrite", "allow-piece-length-change", "always-resume", "async-dns", "auto-file-renaming", "bt-enable-hook-after-hash-check", "bt-enable-lpd", "bt-exclude-tracker", "bt-external-ip", "bt-force-encryption", "bt-hash-check-seed", "bt-load-saved-metadata", "bt-max-peers", "bt-metadata-only", "bt-min-crypto-level", "bt-prioritize-piece", "bt-remove-unselected-file", "bt-request-peer-speed-limit", "bt-require-crypto", "bt-save-metadata", "bt-seed-unverified", "bt-stop-timeout", "bt-tracker", "bt-tracker-connect-timeout", "bt-tracker-interval", "bt-tracker-timeout", "check-integrity", "checksum", "conditional-get", "connect-timeout", "content-disposition-default-utf8", "continue", "dir", "dry-run", "enable-http-keep-alive", "enable-http-pipelining", "enable-mmap", "enable-peer-exchange", "file-allocation", "follow-metalink", "follow-torrent", "force-save", "ftp-passwd", "ftp-pasv", "ftp-proxy", "ftp-proxy-passwd", "ftp-proxy-user", "ftp-reuse-connection", "ftp-type", "ftp-user", "gid", "hash-check-only", "header", "http-accept-gzip", "http-auth-challenge", "http-no-cache", "http-passwd", "http-proxy", "http-proxy-passwd", "http-proxy-user", "http-user", "https-proxy", "https-proxy-passwd", "https-proxy-user", "index-out", "lowest-speed-limit", "max-connection-per-server", "max-download-limit", "max-file-not-found", "max-mmap-limit", "max-resume-failure-tries", "max-tries", "max-upload-limit", "metalink-base-uri", "metalink-enable-unique-protocol", "metalink-language", "metalink-location", "metalink-os", "metalink-preferred-protocol", "metalink-version", "min-split-size", "no-file-allocation-limit", "no-netrc", "no-proxy", "out", "parameterized-uri", "pause", "pause-metadata", "piece-length", "proxy-method", "realtime-chunk-checksum", "referer", "remote-time", "remove-control-file", "retry-wait", "reuse-uri", "rpc-save-upload-metadata", "seed-ratio", "seed-time", "select-file", "split", "ssh-host-key-md", "stream-piece-selector", "timeout", "uri-selector", "use-head", "user-agent", "dry-run", "metalink-base-uri", "parameterized-uri", "pause", "piece-length", "rpc-save-upload-metadata", "bt-max-peers", "bt-request-peer-speed-limit", "bt-remove-unselected-file", "force-save", "max-download-limit", "max-upload-limit", "bt-max-open-files", "download-result", "keep-unfinished-download-result", "log", "log-level", "max-concurrent-downloads", "max-download-result", "max-overall-download-limit", "max-overall-upload-limit", "optimize-concurrent-downloads", "save-cookies", "save-session", "server-stat-of"];
|
||||
|
||||
export default aria2Options
|
||||
184
src/utils/helper.js
Normal file
184
src/utils/helper.js
Normal file
@@ -0,0 +1,184 @@
|
||||
import {
|
||||
generateUrl
|
||||
} from '@nextcloud/router'
|
||||
import Toastify from 'toastify-js'
|
||||
import "toastify-js/src/toastify.css"
|
||||
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
|
||||
import nctable from '../lib/ncTable';
|
||||
import Http from '../lib/http'
|
||||
|
||||
const helper = {
|
||||
vue: {},
|
||||
addVue(name, object) {
|
||||
helper.vue[name] = object;
|
||||
},
|
||||
getVue(name) {
|
||||
return helper.vue[name];
|
||||
},
|
||||
generateUrl: generateUrl,
|
||||
loop(callback, delay, ...args) {
|
||||
callback(...args);
|
||||
clearTimeout(helper.timeoutID);
|
||||
this.polling(callback, delay, ...args);
|
||||
},
|
||||
enabledPolling: 0,
|
||||
trim(string, char) {
|
||||
return string.split(char).filter(Boolean).join(char)
|
||||
},
|
||||
isHtml(string) {
|
||||
const htmlRegex = new RegExp('^<([a-z]+)[^>]+>(.*?)</\\1>', 'i');
|
||||
return htmlRegex.test(string);
|
||||
},
|
||||
ucfirst(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
},
|
||||
polling(callback, delay, ...args) {
|
||||
self = this;
|
||||
helper.timeoutID = setTimeout(function () {
|
||||
if (self.enabledPolling) {
|
||||
callback(...args);
|
||||
self.polling(callback, delay, ...args);
|
||||
}
|
||||
}, delay);
|
||||
},
|
||||
isURL(url) {
|
||||
let regex = '^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@|\\d{1,3}(?:\.\\d{1,3}){3}|(?:(?:[a-z\\d\\u{00a1}-\\u{ffff}'
|
||||
+ ']+-?)*[a-z\\d\\u{00a1}-\\u{ffff}]+)(?:\.(?:[a-z\\d\\u{00a1}-\\u{ffff}]+-?)*[a-z\\d\\u{00a1}-\\u{ffff}]+)*(?:\.'
|
||||
+ '[a-z\\u{00a1}-\\u{ffff}]{2,6}))(?::\\d+)?(?:[^\\s]*)?$';
|
||||
const pattern = new RegExp(regex, 'iu');
|
||||
return pattern.test(url);
|
||||
},
|
||||
isMagnetURI(url) {
|
||||
const magnetURI = /^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}(&dn=.+&tr=.+)?$/i;
|
||||
|
||||
return magnetURI.test(url.trim());
|
||||
},
|
||||
message: function (message, duration = 3000) {
|
||||
Toastify({
|
||||
text: message,
|
||||
duration: duration,
|
||||
newWindow: true,
|
||||
close: true,
|
||||
gravity: "top", // `top` or `bottom`
|
||||
position: "center", // `left`, `center` or `right`
|
||||
backgroundColor: "linear-gradient(to right, rgb(26, 28, 27), rgb(126, 138, 105))",
|
||||
stopOnFocus: true, // Prevents dismissing of toast on hover
|
||||
onClick: function () { } // Callback after click
|
||||
}).showToast();
|
||||
},
|
||||
aria2Toggle: function (data) {
|
||||
if (!data.status) {
|
||||
return;
|
||||
}
|
||||
if (!data.status && data.error) {
|
||||
return;
|
||||
}
|
||||
let element = document.querySelector("#start-aria2 button");
|
||||
let aria2 = element.getAttribute("data-aria2");
|
||||
if (aria2 === 'on') {
|
||||
element.setAttribute("data-aria2", "off");
|
||||
element.textContent = t("ncdownloader", "Start Aria2");
|
||||
} else {
|
||||
element.setAttribute("data-aria2", "on");
|
||||
element.textContent = t("ncdownloader", "Stop Aria2");
|
||||
}
|
||||
},
|
||||
getPathLast: function (path) {
|
||||
return path.substring(path.lastIndexOf('/') + 1)
|
||||
},
|
||||
updateCounter(data) {
|
||||
for (let key in data) {
|
||||
const counter = document.getElementById(key + "-downloads-counter")
|
||||
counter.innerHTML = '<div class="number">' + data[key] + '</div>';
|
||||
}
|
||||
},
|
||||
refresh(path) {
|
||||
path = path || "/apps/ncdownloader/status/active";
|
||||
let url = helper.generateUrl(path);
|
||||
Http.getInstance(url).setHandler(function (data) {
|
||||
if (data && data.row) {
|
||||
nctable.getInstance(data.title, data.row).create();
|
||||
} else {
|
||||
nctable.getInstance().noData();
|
||||
}
|
||||
if (data.counter)
|
||||
helper.updateCounter(data.counter);
|
||||
}).send();
|
||||
},
|
||||
html2DOM: function (htmlString) {
|
||||
const parser = new window.DOMParser();
|
||||
let doc = parser.parseFromString(htmlString, "text/html")
|
||||
return doc.querySelector("div");
|
||||
},
|
||||
makePair: function (data, prefix = "aria2-settings") {
|
||||
for (let key in data) {
|
||||
let index;
|
||||
if ((index = key.indexOf(prefix + "-key-")) !== -1) {
|
||||
let valueKey = prefix + "-value-" + key.substring(key.lastIndexOf('-') + 1);
|
||||
if (!data[valueKey]) continue;
|
||||
let newkey = data[key];
|
||||
data[newkey] = data[valueKey];
|
||||
delete data[key];
|
||||
delete data[valueKey];
|
||||
}
|
||||
}
|
||||
},
|
||||
getData(selector) {
|
||||
const element = typeof selector === "object" ? selector : document.getElementById(selector)
|
||||
const data = {}
|
||||
data['path'] = element.getAttribute('path') || '';
|
||||
//if the targeted element is not of input or select type, search for such elements below it
|
||||
if (!['SELECT', 'INPUT'].includes(element.nodeName.toUpperCase())) {
|
||||
const nodeList = element.querySelectorAll('input,select')
|
||||
|
||||
for (let i = 0; i < nodeList.length; i++) {
|
||||
const element = nodeList[i]
|
||||
if (element.hasAttribute('type') && element.getAttribute('type') === 'button') {
|
||||
continue
|
||||
}
|
||||
const key = element.getAttribute('id')
|
||||
data[key] = element.value
|
||||
for (let prop in element.dataset) {
|
||||
data[prop] = element.dataset[prop];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let prop in element.dataset) {
|
||||
data[prop] = element.dataset[prop];
|
||||
}
|
||||
const key = element.getAttribute('id')
|
||||
data[key] = element.value
|
||||
}
|
||||
return data;
|
||||
},
|
||||
showElement(prop) {
|
||||
let vm = helper.getVue('mainApp');
|
||||
vm.$data.display[prop] = true;
|
||||
//hide all other elements;
|
||||
for (let key in vm.$data.display) {
|
||||
if (key !== prop) {
|
||||
vm.$data.display[key] = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
hideElement(prop) {
|
||||
let vm = helper.getVue('mainApp');
|
||||
vm.$data.display[prop] = false;
|
||||
},
|
||||
showDownload() {
|
||||
helper.showElement('download');
|
||||
nctable.getInstance().clear();
|
||||
helper.enabledPolling = 0;
|
||||
},
|
||||
hideDownload() {
|
||||
helper.hideElement('download');
|
||||
},
|
||||
topleft(id) {
|
||||
let container = typeof id === 'object' ? id : document.getElementById(id);
|
||||
container.style.top = 0;
|
||||
container.style.left = 0;
|
||||
container.style.width = "100%";
|
||||
}
|
||||
}
|
||||
|
||||
export default helper
|
||||
Reference in New Issue
Block a user