From 6e8e7a04807c01b02ec4e2243e0b0442557efd3a Mon Sep 17 00:00:00 2001 From: benoit74 Date: Thu, 31 Oct 2024 10:43:55 +0000 Subject: [PATCH 1/3] Prettier constants.js and Mixins.js --- .../frontend-ui/src/components/Mixins.js | 274 ++++++---- dispatcher/frontend-ui/src/constants.js | 515 +++++++++++------- 2 files changed, 483 insertions(+), 306 deletions(-) diff --git a/dispatcher/frontend-ui/src/components/Mixins.js b/dispatcher/frontend-ui/src/components/Mixins.js index 6cd693fbc..df4302bbd 100644 --- a/dispatcher/frontend-ui/src/components/Mixins.js +++ b/dispatcher/frontend-ui/src/components/Mixins.js @@ -1,82 +1,137 @@ +import jwt from "jsonwebtoken"; -import jwt from 'jsonwebtoken'; - -import Constants from '../constants.js' +import Constants from "../constants.js"; export default { data() { return { selectedLimit: this.getLimitPreference(), // user-defined nb of tasks to retrieve/display limits: Constants.LIMIT_CHOICES, - }; + }; }, computed: { - publicPath() { return process.env.BASE_URL; }, // for static files linking - categories() { return Constants.categories; }, // list of categories for filter/edit - warehouse_paths() { return Constants.warehouse_paths; }, // list of paths for edit - periodicities() { return Constants.periodicities; }, // list of paths for edit - languages() { return this.$store.getters.languages; }, // list of lang for filter/edit - tags() { return this.$store.getters.tags; }, // list of tags for filter/edit - offliners() { return this.$store.getters.offliners; }, // list of offliners for edit - platforms() { return this.$store.getters.platforms; }, // list of platforms for edit + publicPath() { + return process.env.BASE_URL; + }, // for static files linking + categories() { + return Constants.categories; + }, // list of categories for filter/edit + warehouse_paths() { + return Constants.warehouse_paths; + }, // list of paths for edit + periodicities() { + return Constants.periodicities; + }, // list of paths for edit + languages() { + return this.$store.getters.languages; + }, // list of lang for filter/edit + tags() { + return this.$store.getters.tags; + }, // list of tags for filter/edit + offliners() { + return this.$store.getters.offliners; + }, // list of offliners for edit + platforms() { + return this.$store.getters.platforms; + }, // list of platforms for edit isLoggedIn() { try { - return Boolean(this.$store.getters.username !== null && !this.token_expired); - } catch { return false; } + return Boolean( + this.$store.getters.username !== null && !this.token_expired + ); + } catch { + return false; + } }, token_expired() { let expiry = this.$store.getters.token_expiry; - return (!expiry) ? true : Constants.now() > expiry; - }, - canRequestTasks() { return this.$root.has_perm("tasks", "request"); }, - canUnRequestTasks() { return this.$root.has_perm("tasks", "unrequest"); }, - canCancelTasks() { return this.$root.has_perm("tasks", "cancel"); }, - canCreateSchedules() { return this.$root.has_perm("schedules", "create"); }, - canUpdateSchedules() { return this.$root.has_perm("schedules", "update"); }, - canDeleteSchedules() { return this.$root.has_perm("schedules", "delete"); }, - canReadUsers() { return this.$root.has_perm("users", "read"); }, - canSSHKeyUsers() { return this.$root.has_perm("users", "ssh_keys"); }, - canCreateUsers() { return this.$root.has_perm("users", "create"); }, - canUpdateUsers() { return this.$root.has_perm("users", "update"); }, - canDeleteUsers() { return this.$root.has_perm("users", "delete"); }, - canChangePasswordUsers() { return this.$root.has_perm("users", "change_password"); }, - + return !expiry ? true : Constants.now() > expiry; + }, + canRequestTasks() { + return this.$root.has_perm("tasks", "request"); + }, + canUnRequestTasks() { + return this.$root.has_perm("tasks", "unrequest"); + }, + canCancelTasks() { + return this.$root.has_perm("tasks", "cancel"); + }, + canCreateSchedules() { + return this.$root.has_perm("schedules", "create"); + }, + canUpdateSchedules() { + return this.$root.has_perm("schedules", "update"); + }, + canDeleteSchedules() { + return this.$root.has_perm("schedules", "delete"); + }, + canReadUsers() { + return this.$root.has_perm("users", "read"); + }, + canSSHKeyUsers() { + return this.$root.has_perm("users", "ssh_keys"); + }, + canCreateUsers() { + return this.$root.has_perm("users", "create"); + }, + canUpdateUsers() { + return this.$root.has_perm("users", "update"); + }, + canDeleteUsers() { + return this.$root.has_perm("users", "delete"); + }, + canChangePasswordUsers() { + return this.$root.has_perm("users", "change_password"); + }, }, methods: { cancel_task(task_id, on_success) { let parent = this; - parent.queryAPI('post', '/tasks/' + task_id + '/cancel') + parent + .queryAPI("post", "/tasks/" + task_id + "/cancel") .then(function () { - let msg = "Requested Task " + Constants.short_id(task_id) + " has been marked for cancelation."; + let msg = + "Requested Task " + + Constants.short_id(task_id) + + " has been marked for cancelation."; parent.alertSuccess("Canceling!", msg); }) .catch(function (error) { parent.alertError(Constants.standardHTTPError(error.response)); }) .then(function () { - if (on_success) - on_success(); + if (on_success) on_success(); }); }, - scrollToTop() { window.scrollTo(0,0); }, - format_dt(dt) { return Constants.format_dt(dt); }, - from_now(dt) { return Constants.from_now(dt); }, - toggleLoader(text) { // shortcut to store's loader status changer - let payload = text ? {status: true, text: text} : {status: false}; - this.$store.dispatch('setLoading', payload); + scrollToTop() { + window.scrollTo(0, 0); + }, + format_dt(dt) { + return Constants.format_dt(dt); }, - getLimitPreference() { // retrieve nb of items to display from cookie - return this.$cookie.get('pref-limit') || Constants.DEFAULT_LIMIT; + from_now(dt) { + return Constants.from_now(dt); }, - saveLimitPreference(value) { // save nb of items to display in a cookie - this.$cookie.set('pref-limit', value, {expires: Constants.COOKIE_LIFETIME_EXPIRY}); + toggleLoader(text) { + // shortcut to store's loader status changer + let payload = text ? { status: true, text: text } : { status: false }; + this.$store.dispatch("setLoading", payload); + }, + getLimitPreference() { + // retrieve nb of items to display from cookie + return this.$cookie.get("pref-limit") || Constants.DEFAULT_LIMIT; + }, + saveLimitPreference(value) { + // save nb of items to display in a cookie + this.$cookie.set("pref-limit", value, { + expires: Constants.COOKIE_LIFETIME_EXPIRY, + }); }, redirectTo(name, params) { - let route_entry = {name: name}; - if (params) - route_entry.params = params; + let route_entry = { name: name }; + if (params) route_entry.params = params; this.$router.push(route_entry); }, @@ -84,23 +139,24 @@ export default { let options = { title: "Please Confirm", size: "sm", - buttonSize: 'sm', - okVariant: 'danger', - okTitle: 'YES', - cancelTitle: 'NO', - centered: true + buttonSize: "sm", + okVariant: "danger", + okTitle: "YES", + cancelTitle: "NO", + centered: true, }; - this.$bvModal.msgBoxConfirm("Do you want to " + action + "?", options) - .then(value => { + this.$bvModal + .msgBoxConfirm("Do you want to " + action + "?", options) + .then((value) => { if (value === true && onConfirm) { onConfirm(); } - if (value === false && onRefuse){ + if (value === false && onRefuse) { onRefuse(); } }) - .catch(err => { - if (onError){ + .catch((err) => { + if (onError) { onError(err); } }); @@ -108,23 +164,36 @@ export default { alert(level, title, text, duration) { let message = "" + title + ""; - if (text) - message += "
" + text; - this.$root.$emit('feedback-message', level, message, duration); - }, - alertInfo(title, text, duration) { this.alert('info', title, text, duration); }, - alertSuccess(title, text, duration) { this.alert('success', title, text, duration); }, - alertWarning(title, text, duration) { this.alert('warning', title, text, duration); }, - alertDanger(title, text, duration) { this.alert('danger', title, text, duration); }, - alertAccessRefused(perm_name) { this.alertWarning("Access Refused", "You don't have " + perm_name + " permission."); }, - alertError(text) { this.alertDanger("Error", text, Constants.ALERT_PERMANENT_DURATION); }, + if (text) message += "
" + text; + this.$root.$emit("feedback-message", level, message, duration); + }, + alertInfo(title, text, duration) { + this.alert("info", title, text, duration); + }, + alertSuccess(title, text, duration) { + this.alert("success", title, text, duration); + }, + alertWarning(title, text, duration) { + this.alert("warning", title, text, duration); + }, + alertDanger(title, text, duration) { + this.alert("danger", title, text, duration); + }, + alertAccessRefused(perm_name) { + this.alertWarning( + "Access Refused", + "You don't have " + perm_name + " permission." + ); + }, + alertError(text) { + this.alertDanger("Error", text, Constants.ALERT_PERMANENT_DURATION); + }, statusClass(status) { - if (status == 'succeeded') - return 'schedule-suceedeed'; + if (status == "succeeded") return "schedule-suceedeed"; if (["failed", "canceled", "cancel_requested"].indexOf(status)) - return 'schedule-failed'; - return 'schedule-running'; + return "schedule-failed"; + return "schedule-running"; }, handleTokenResponse(response) { console.debug("handleTokenResponse", response); @@ -135,16 +204,23 @@ export default { access_token: access_token, payload: jwt.decode(access_token), refresh_token: refresh_token, - } + }; // save token to store - this.$store.dispatch('saveAuthenticationToken', token_data); + this.$store.dispatch("saveAuthenticationToken", token_data); // save to cookie - let cookie_data = {"access_token": access_token, "refresh_token": refresh_token}; - this.$cookie.set(Constants.TOKEN_COOKIE_NAME, - JSON.stringify(cookie_data), - {expires: Constants.TOKEN_COOKIE_EXPIRY, - secure: Constants.isProduction()}); + let cookie_data = { + access_token: access_token, + refresh_token: refresh_token, + }; + this.$cookie.set( + Constants.TOKEN_COOKIE_NAME, + JSON.stringify(cookie_data), + { + expires: Constants.TOKEN_COOKIE_EXPIRY, + secure: Constants.isProduction(), + } + ); }, async renew_token_from_refresh(refresh_token, on_success, on_error) { console.debug("renew_token_from_refresh", refresh_token); @@ -152,11 +228,15 @@ export default { refresh_token = this.$store.getters.refresh_token; let req_headers = this.$root.axios.defaults.headers; - req_headers['refresh-token'] = refresh_token; + req_headers["refresh-token"] = refresh_token; let response; try { - response = await this.$root.axios.post('/auth/token', {}, {headers: req_headers}); + response = await this.$root.axios.post( + "/auth/token", + {}, + { headers: req_headers } + ); console.debug("/auth/token success"); console.debug(response); } catch (error) { @@ -180,18 +260,16 @@ export default { }, loadTokenFromCookie(force_refresh) { // already authenticated - if (this.isLoggedIn && !force_refresh) - return true; + if (this.isLoggedIn && !force_refresh) return true; let cookie_value = this.$cookie.get(Constants.TOKEN_COOKIE_NAME); // no cookie - if (!cookie_value) - return false; + if (!cookie_value) return false; let token_data; try { - token_data = JSON.parse(cookie_value); - token_data.payload = jwt.decode(token_data.access_token); + token_data = JSON.parse(cookie_value); + token_data.payload = jwt.decode(token_data.access_token); } catch { // incorrect cookie payload this.$cookie.delete(Constants.TOKEN_COOKIE_NAME); @@ -204,14 +282,14 @@ export default { let expiry = Constants.fromSeconds(token_data.payload.exp); let parent = this; - if ((Constants.now() > expiry) || force_refresh) { + if (Constants.now() > expiry || force_refresh) { console.debug("cookie token expired or refresh requested"); let renewed = false; this.renew_token_from_refresh( token_data.refresh_token, function () { console.debug("could renew the token, great!"); - renewed = true + renewed = true; }, function () { console.debug("couldnt refresh token, removing cookie"); @@ -222,7 +300,7 @@ export default { return renewed; } else { console.log("cookie token not expired, using it."); - this.$store.dispatch('saveAuthenticationToken', token_data); + this.$store.dispatch("saveAuthenticationToken", token_data); return true; } }, @@ -232,9 +310,9 @@ export default { if (error && error.response && error.response.status === 401) { // attempt to automatically renew token if (!this.loadTokenFromCookie(true)) { - this.removeToken() + this.removeToken(); } - this.redirectTo('home') + this.redirectTo("home"); } // set user-facing error message in UI let msg = Constants.standardHTTPError(error.response); @@ -245,7 +323,7 @@ export default { } }, removeToken(manual) { - this.$store.dispatch('clearAuthentication'); + this.$store.dispatch("clearAuthentication"); this.$cookie.delete(Constants.TOKEN_COOKIE_NAME); let msg = ""; if (!manual) { @@ -255,13 +333,13 @@ export default { }, queryAPI(method, path, data, config) { console.debug("queryAPI", method, path); - if (data === undefined) - data = {}; - if (config === undefined) - config = {}; + if (data === undefined) data = {}; + if (config === undefined) config = {}; if (this.token_expired && this.$store.getters.access_token) { - console.debug("we have an expired token, attempting to refresh before request."); + console.debug( + "we have an expired token, attempting to refresh before request." + ); let parent = this; return new Promise(function (resolve) { @@ -281,5 +359,5 @@ export default { return this.$root.axios[method](path, data, config); } }, - } -} + }, +}; diff --git a/dispatcher/frontend-ui/src/constants.js b/dispatcher/frontend-ui/src/constants.js index d36e70c6f..b42c98d53 100644 --- a/dispatcher/frontend-ui/src/constants.js +++ b/dispatcher/frontend-ui/src/constants.js @@ -1,76 +1,71 @@ -import filesize from 'filesize' -import querystring from 'querystring' +import filesize from "filesize"; +import querystring from "querystring"; const { DateTime, Duration, Interval } = require("luxon"); function isFirefoxOnIOS() { let ua = navigator.userAgent.toLowerCase(); - return (ua.indexOf("mobile") >= 0 && ua.indexOf("mozilla") >= 0 && ua.indexOf("applewebkit") >= 0) + return ( + ua.indexOf("mobile") >= 0 && + ua.indexOf("mozilla") >= 0 && + ua.indexOf("applewebkit") >= 0 + ); } -function format_dt(value) { // display a datetime in a standard format - if (!value) - return ''; +function format_dt(value) { + // display a datetime in a standard format + if (!value) return ""; let dt = DateTime.fromISO(value); - if (dt.invalid) - return value; - return dt.toFormat('fff'); + if (dt.invalid) return value; + return dt.toFormat("fff"); } function to_timestamp(value) { - if (!value) - return 0; + if (!value) return 0; let dt = DateTime.fromISO(value); - if (dt.invalid) - return 0; + if (dt.invalid) return 0; return dt.toMillis(); } function get_units(interval) { - let units = [] + let units = []; let all_units = ["months", "days", "hours", "minutes"]; - all_units.forEach(function (unit){ - if (interval.length(unit) >= 1) - units.push(unit); + all_units.forEach(function (unit) { + if (interval.length(unit) >= 1) units.push(unit); }); - if (units.length == 0) - units.push("seconds") + if (units.length == 0) units.push("seconds"); return units; } function to_duration_obj(milliseconds) { - var items = {years: 0, + var items = { + years: 0, months: 0, days: 0, hours: 0, minutes: 0, seconds: 0, - milliseconds: milliseconds}; + milliseconds: milliseconds, + }; function to_obj() { let o = {}; - Object.entries(items).forEach(item => { + Object.entries(items).forEach((item) => { let [key, value] = item; - if (value >= 1 && key != "milliseconds") - o[key] = value; - }) + if (value >= 1 && key != "milliseconds") o[key] = value; + }); return o; } function shift(lower, upper, num) { items[upper] = items[lower] / num; items[lower] = items[lower] % num; - return (items[upper] < 1); + return items[upper] < 1; } - if (shift("milliseconds", "seconds", 1000)) - return to_obj(); - if (shift("seconds", "minutes", 60)) - return to_obj(); - if (shift("minutes", "hours", 60)) - return to_obj(); - if (shift("hours", "days", 24)) - return to_obj(); - if (shift("days", "months", 30)) - return to_obj(); + if (shift("milliseconds", "seconds", 1000)) return to_obj(); + if (shift("seconds", "minutes", 60)) return to_obj(); + if (shift("minutes", "hours", 60)) return to_obj(); + if (shift("hours", "days", 24)) return to_obj(); + if (shift("days", "months", 30)) return to_obj(); shift("months", "years", 12); return to_obj(); } @@ -80,22 +75,25 @@ function format_duration(duration_value) { return dur.toHuman({ maximumSignificantDigits: 1 }); } -function format_duration_between(start, end) { // display a duration between two datetimes - var int = Interval.fromDateTimes(DateTime.fromISO(start), DateTime.fromISO(end)); +function format_duration_between(start, end) { + // display a duration between two datetimes + var int = Interval.fromDateTimes( + DateTime.fromISO(start), + DateTime.fromISO(end) + ); let diff = Duration.fromObject(int.toDuration(get_units(int)).toObject()); return diff.toHuman({ maximumSignificantDigits: 1 }); } function from_now(value) { - if (!value) - return ''; + if (!value) return ""; let start = DateTime.fromISO(value); - if (start.invalid) - return value; + if (start.invalid) return value; return start.toRelative(); } -function params_serializer(params) { // turn javascript params object into querystring +function params_serializer(params) { + // turn javascript params object into querystring return querystring.stringify(params); } @@ -108,16 +106,19 @@ function image_human(config) { } function image_url(config) { - let prefix = (config.image.name.indexOf("ghcr.io") != -1) ? "https://" : "https://hub.docker.com/r/"; + let prefix = + config.image.name.indexOf("ghcr.io") != -1 + ? "https://" + : "https://hub.docker.com/r/"; return prefix + config.image.name; } function logs_url(task) { - return upload_url(task.upload.logs.upload_uri, task.container.log) + return upload_url(task.upload.logs.upload_uri, task.container.log); } function artifacts_url(task) { - return upload_url(task.upload.artifacts.upload_uri, task.container.artifacts) + return upload_url(task.upload.artifacts.upload_uri, task.container.artifacts); } function upload_url(uri, filename) { @@ -130,8 +131,7 @@ function upload_url(uri, filename) { if (scheme == "s3") { let log_url = url.protocol + "//" + url.host + url.pathname; let bucketName = url.searchParams.get("bucketName"); - if (bucketName) - log_url += bucketName + "/"; + if (bucketName) log_url += bucketName + "/"; return log_url + filename; } @@ -139,53 +139,65 @@ function upload_url(uri, filename) { } function build_command_without(config, secret_fields) { - if (secret_fields == null) - return ""; + if (secret_fields == null) return ""; return config.str_command; } function build_docker_command(name, config, secret_fields) { let mounts = ["-v", "/my-path:" + config.mount_point + ":rw"]; - let mem_params = ["--memory-swappiness", "0", "--memory", config.resources.memory]; + let mem_params = [ + "--memory-swappiness", + "0", + "--memory", + config.resources.memory, + ]; let capadd_params = []; let capdrop_params = []; if (config.resources.cap_add) { config.resources.cap_add.forEach(function (cap) { - capadd_params.push("--cap-add") + capadd_params.push("--cap-add"); capadd_params.push(cap); }); } if (config.resources.cap_drop) { config.resources.cap_drop.forEach(function (cap) { - capdrop_params.push("--cap-drop") + capdrop_params.push("--cap-drop"); capdrop_params.push(cap); }); } let shm_params = []; - if (config.resources.shm) - shm_params = ["--shm-size", config.resources.shm]; + if (config.resources.shm) shm_params = ["--shm-size", config.resources.shm]; let cpu_params = ["--cpu-shares", config.resources.cpu * DEFAULT_CPU_SHARE]; - let docker_base = ["docker", "run"].concat(mounts).concat(["--name", config.task_name + "_" + name, "--detach"]) - .concat(cpu_params).concat(mem_params).concat(shm_params) - .concat(capadd_params).concat(capdrop_params); + let docker_base = ["docker", "run"] + .concat(mounts) + .concat(["--name", config.task_name + "_" + name, "--detach"]) + .concat(cpu_params) + .concat(mem_params) + .concat(shm_params) + .concat(capadd_params) + .concat(capdrop_params); let scraper_command = build_command_without(config, secret_fields); - let args = docker_base.concat([image_human(config)]).concat([scraper_command]); + let args = docker_base + .concat([image_human(config)]) + .concat([scraper_command]); return args.join(" "); } -function trim_command(command, columns=79) { // trim a string to espaced version (at most columns) +function trim_command(command, columns = 79) { + // trim a string to espaced version (at most columns) let parts; - if (typeof(command) == "object" && Object.isArray(command)) { - parts = command.map(function(part) { return part.replace(/^--/, ""); }); + if (typeof command == "object" && Object.isArray(command)) { + parts = command.map(function (part) { + return part.replace(/^--/, ""); + }); command = parts.join(" "); } else { parts = command.split(" --"); } // don't bother if command is not that long - if (command.length <= columns) - return command; + if (command.length <= columns) return command; let sep = "\\\n"; // first line is considered already filled with PS1 (35 chars) @@ -221,19 +233,19 @@ function trim_command(command, columns=79) { // trim a string to espaced versio lines[0] = first_line.substr(2); // remove extra space at end let last_line = lines[lines.length - 1]; - lines[lines.length - 1] = last_line.substr(0, last_line.length -1); + lines[lines.length - 1] = last_line.substr(0, last_line.length - 1); let new_command = lines.join(sep); return new_command; } -function short_id(id) { // short id of tasks (last chars) +function short_id(id) { + // short id of tasks (last chars) return id.substr(0, 5); } function filesize2(value) { - if (!value) - return ''; + if (!value) return ""; return filesize(value); } @@ -241,33 +253,47 @@ function duplicate(dict) { return JSON.parse(JSON.stringify(dict)); } - function schedule_durations_dict(duration) { function single_duration(value, worker, on) { - return {single: true, - value: value, - worker: worker, - on: on}; + return { single: true, value: value, worker: worker, on: on }; } function multiple_durations(min_value, max_value, workers) { - let min_workers = Object.values(Object.filter(workers, function (item) { return item.value == min_value; })); - let max_workers = Object.values(Object.filter(workers, function (item) { return item.value == max_value; })); - return {single: false, - min_value: min_value * 1000, - max_value: max_value * 1000, - min_workers: min_workers, - max_workers: max_workers}; + let min_workers = Object.values( + Object.filter(workers, function (item) { + return item.value == min_value; + }) + ); + let max_workers = Object.values( + Object.filter(workers, function (item) { + return item.value == max_value; + }) + ); + return { + single: false, + min_value: min_value * 1000, + max_value: max_value * 1000, + min_workers: min_workers, + max_workers: max_workers, + }; } if (!duration.available) { - return single_duration(duration.default.value, "default", duration.default.on); + return single_duration( + duration.default.value, + "default", + duration.default.on + ); } - let min_worker = Object.min(duration.workers, 'value'); - let max_worker = Object.max(duration.workers, 'value'); + let min_worker = Object.min(duration.workers, "value"); + let max_worker = Object.max(duration.workers, "value"); if (min_worker == max_worker) { - return single_duration(duration.workers[min_worker].value, min_worker, duration.workers[min_worker].on); + return single_duration( + duration.workers[min_worker].value, + min_worker, + duration.workers[min_worker].on + ); } let min_value = duration.workers[min_worker].value; let max_value = duration.workers[max_worker].value; @@ -275,42 +301,48 @@ function schedule_durations_dict(duration) { } function secret_fields_for(offliner_flags_definition) { - if (offliner_flags_definition === null) - return []; + if (offliner_flags_definition === null) return []; return offliner_flags_definition - .filter(function (item) { return "secret" in item && item.secret === true; }) - .map(function (item) { return item.data_key}); + .filter(function (item) { + return "secret" in item && item.secret === true; + }) + .map(function (item) { + return item.data_key; + }); } function get_timezone_details() { - let dt = DateTime.local() - let diff = Duration.fromObject({minutes: Math.abs(dt.o)}) + let dt = DateTime.local(); + let diff = Duration.fromObject({ minutes: Math.abs(dt.o) }); let offsetstr = ""; let amount = ""; if (diff.minutes % 60 == 0) { - amount = `${diff.as("hour")} hour` - if (diff.minutes > 60) - amount += 's' - } else - amount = `${diff.toHuman({ unitDisplay: "long" })}` - - if (dt.o > 0) - offsetstr = `${amount} ahead of UTC` - else if (dt.o < 0) - offsetstr = `${amount} behind UTC` - else - offsetstr = 'in par with UTC' - return {tz: dt.zoneName, offset: dt.o, offsetstr: offsetstr} + amount = `${diff.as("hour")} hour`; + if (diff.minutes > 60) amount += "s"; + } else amount = `${diff.toHuman({ unitDisplay: "long" })}`; + + if (dt.o > 0) offsetstr = `${amount} ahead of UTC`; + else if (dt.o < 0) offsetstr = `${amount} behind UTC`; + else offsetstr = "in par with UTC"; + return { tz: dt.zoneName, offset: dt.o, offsetstr: offsetstr }; } -function getDelay(milliseconds) { // retrieve a promise making a pause in milliseconds - return new Promise(resolve => setTimeout(resolve, milliseconds)); +function getDelay(milliseconds) { + // retrieve a promise making a pause in milliseconds + return new Promise((resolve) => setTimeout(resolve, milliseconds)); } var DEFAULT_CPU_SHARE = 1024; -var ZIMFARM_WEBAPI = window.environ.ZIMFARM_WEBAPI || "https://api.farm.openzim.org/v1"; -var cancelable_statuses = ["reserved", "started", "scraper_started", "scraper_completed", "scraper_killed"]; +var ZIMFARM_WEBAPI = + window.environ.ZIMFARM_WEBAPI || "https://api.farm.openzim.org/v1"; +var cancelable_statuses = [ + "reserved", + "started", + "scraper_started", + "scraper_completed", + "scraper_killed", +]; var running_statuses = cancelable_statuses.concat(["cancel_requested"]); export default { @@ -318,10 +350,14 @@ export default { return ZIMFARM_WEBAPI.indexOf("https://") == 0; }, zimfarm_webapi: ZIMFARM_WEBAPI, - kiwix_download_url: window.environ.ZIMFARM_KIWIX_DOWNLOAD_URL || "https://download.kiwix.org/zim", - TASKS_LOAD_SCHEDULES_CHUNK_SIZE: parseInt(window.environ.ZIMFARM_TASKS_LOAD_SCHEDULES_CHUNK_SIZE, 10) || 5, - TASKS_LOAD_SCHEDULES_DELAY: parseInt(window.environ.ZIMFARM_TASKS_LOAD_SCHEDULES_DELAY, 10) || 100, - DEFAULT_CPU_SHARE: DEFAULT_CPU_SHARE, // used to generate docker cpu-shares + kiwix_download_url: + window.environ.ZIMFARM_KIWIX_DOWNLOAD_URL || + "https://download.kiwix.org/zim", + TASKS_LOAD_SCHEDULES_CHUNK_SIZE: + parseInt(window.environ.ZIMFARM_TASKS_LOAD_SCHEDULES_CHUNK_SIZE, 10) || 5, + TASKS_LOAD_SCHEDULES_DELAY: + parseInt(window.environ.ZIMFARM_TASKS_LOAD_SCHEDULES_DELAY, 10) || 100, + DEFAULT_CPU_SHARE: DEFAULT_CPU_SHARE, // used to generate docker cpu-shares DEFAULT_FIRE_PRIORITY: 5, DEFAULT_LIMIT: 20, LIMIT_CHOICES: [10, 20, 50, 100, 200], @@ -330,103 +366,162 @@ export default { ALERT_LONG_DURATION: 10, ALERT_PERMANENT_DURATION: true, ROLES: ["editor", "manager", "admin", "worker", "processor"], - TOKEN_COOKIE_EXPIRY: '180D', // 6 months - COOKIE_LIFETIME_EXPIRY: '10Y', // 10 years + TOKEN_COOKIE_EXPIRY: "180D", // 6 months + COOKIE_LIFETIME_EXPIRY: "10Y", // 10 years TOKEN_COOKIE_NAME: "auth", cancelable_statuses: cancelable_statuses, running_statuses: running_statuses, contact_email: "contact@kiwix.org", - categories: ["devdocs", "freecodecamp", "gutenberg", "ifixit", "other", "phet", "psiram", "stack_exchange", - "ted", "openedx", "vikidia", "wikibooks", "wikihow", "wikinews", - "wikipedia", "wikiquote", "wikisource", "wikispecies", "wikiversity", - "wikivoyage", "wiktionary"], // list of categories for fileering - warehouse_paths: ["/devdocs", "/freecodecamp", "/gutenberg", "/ifixit", "/other", "/phet", "/psiram", "/stack_exchange", - "/ted", "/mooc", "/videos", "/vikidia", "/wikibooks", "/wikihow", - "/wikinews", "/wikipedia", "/wikiquote", "/wikisource", - "/wikiversity", "/wikivoyage", "/wiktionary", "/zimit", - "/.hidden/dev", "/.hidden/private", "/.hidden/endless", - "/.hidden/bard", "/.hidden/bsf", "/.hidden/datacup", "/.hidden/custom_apps"], - offliners: ["mwoffliner", "youtube", "phet", "gutenberg", "sotoki", "nautilus", "ted", "openedx", "zimit", "kolibri", "wikihow", "ifixit", "freecodecamp", "devdocs"], + categories: [ + "devdocs", + "freecodecamp", + "gutenberg", + "ifixit", + "other", + "phet", + "psiram", + "stack_exchange", + "ted", + "openedx", + "vikidia", + "wikibooks", + "wikihow", + "wikinews", + "wikipedia", + "wikiquote", + "wikisource", + "wikispecies", + "wikiversity", + "wikivoyage", + "wiktionary", + ], // list of categories for fileering + warehouse_paths: [ + "/devdocs", + "/freecodecamp", + "/gutenberg", + "/ifixit", + "/other", + "/phet", + "/psiram", + "/stack_exchange", + "/ted", + "/mooc", + "/videos", + "/vikidia", + "/wikibooks", + "/wikihow", + "/wikinews", + "/wikipedia", + "/wikiquote", + "/wikisource", + "/wikiversity", + "/wikivoyage", + "/wiktionary", + "/zimit", + "/.hidden/dev", + "/.hidden/private", + "/.hidden/endless", + "/.hidden/bard", + "/.hidden/bsf", + "/.hidden/datacup", + "/.hidden/custom_apps", + ], + offliners: [ + "mwoffliner", + "youtube", + "phet", + "gutenberg", + "sotoki", + "nautilus", + "ted", + "openedx", + "zimit", + "kolibri", + "wikihow", + "ifixit", + "freecodecamp", + "devdocs", + ], periodicities: ["manually", "monthly", "quarterly", "biannualy", "annually"], - memory_values: [536870912, // 512MiB - 1073741824, // 1GiB - 2147483648, // 2GiB - 3221225472, // 3GiB - 4294967296, // 4GiB - 5368709120, // 5GiB - 6442450944, // 6GiB - 7516192768, // 7GiB - 8589934592, // 8GiB - 9663676416, // 9GiB - 10737418240, // 10GiB - 11811160064, // 11GiB - 12884901888, // 12GiB - 13958643712, // 13GiB - 15032385536, // 14GiB - 16106127360, // 15GiB - 17179869184, // 16GiB - 18253611008, // 17GiB - 19327352832, // 18GiB - 20401094656, // 19GiB - 21474836480, // 20GiB - 22548578304, // 21GiB - 23622320128, // 22GiB - 24696061952, // 23GiB - 25769803776, // 24GiB - 26843545600, // 25GiB - 27917287424, // 26GiB - 28991029248, // 27GiB - 30064771072, // 28GiB - 31138512896, // 29GiB - 32212254720, // 30GiB - 33285996544, // 31GiB - 34359738368, // 32GiB - 51539607552, // 48GiB - 53687091200, // 50GB - 60129542144, // 56GB - 68719476736, // 64GiB - 77309411328, // 72GiB - 85899345920, // 80GiB - 94489280512, // 88GiB - 103079215104, // 96GiB - 107374182400, // 100GiB - 111669149696, // 104GiB - 120259084288, // 112GiB - 128849018880, // 120GiB - 137438953472, // 128GiB - ], - disk_values: [536870912, // 512MiB - 1073741824, // 1GiB - 2147483648, // 2GiB - 3221225472, // 3GiB - 4294967296, // 4GiB - 5368709120, // 5GiB - 10737418240, // 10GiB - 16106127360, // 15GiB - 21474836480, // 20GiB - 32212254720, // 30GiB - 42949672960, // 40GiB - 53687091200, // 50GiB - 80530636800, // 75GiB - 107374182400, // 100GiB - 134217728000, // 125GiB - 161061273600, // 150GiB - 187904819200, // 175GiB - 214748364800, // 200GiB - 241591910400, // 225GiB - 268435456000, // 250GiB - 295279001600, // 275GiB - 322122547200, // 300GiB - 375809638400, // 350GiB - 429496729600, // 400GiB - 483183820800, // 450GiB - 536870912000, // 500GiB - ], + memory_values: [ + 536870912, // 512MiB + 1073741824, // 1GiB + 2147483648, // 2GiB + 3221225472, // 3GiB + 4294967296, // 4GiB + 5368709120, // 5GiB + 6442450944, // 6GiB + 7516192768, // 7GiB + 8589934592, // 8GiB + 9663676416, // 9GiB + 10737418240, // 10GiB + 11811160064, // 11GiB + 12884901888, // 12GiB + 13958643712, // 13GiB + 15032385536, // 14GiB + 16106127360, // 15GiB + 17179869184, // 16GiB + 18253611008, // 17GiB + 19327352832, // 18GiB + 20401094656, // 19GiB + 21474836480, // 20GiB + 22548578304, // 21GiB + 23622320128, // 22GiB + 24696061952, // 23GiB + 25769803776, // 24GiB + 26843545600, // 25GiB + 27917287424, // 26GiB + 28991029248, // 27GiB + 30064771072, // 28GiB + 31138512896, // 29GiB + 32212254720, // 30GiB + 33285996544, // 31GiB + 34359738368, // 32GiB + 51539607552, // 48GiB + 53687091200, // 50GB + 60129542144, // 56GB + 68719476736, // 64GiB + 77309411328, // 72GiB + 85899345920, // 80GiB + 94489280512, // 88GiB + 103079215104, // 96GiB + 107374182400, // 100GiB + 111669149696, // 104GiB + 120259084288, // 112GiB + 128849018880, // 120GiB + 137438953472, // 128GiB + ], + disk_values: [ + 536870912, // 512MiB + 1073741824, // 1GiB + 2147483648, // 2GiB + 3221225472, // 3GiB + 4294967296, // 4GiB + 5368709120, // 5GiB + 10737418240, // 10GiB + 16106127360, // 15GiB + 21474836480, // 20GiB + 32212254720, // 30GiB + 42949672960, // 40GiB + 53687091200, // 50GiB + 80530636800, // 75GiB + 107374182400, // 100GiB + 134217728000, // 125GiB + 161061273600, // 150GiB + 187904819200, // 175GiB + 214748364800, // 200GiB + 241591910400, // 225GiB + 268435456000, // 250GiB + 295279001600, // 275GiB + 322122547200, // 300GiB + 375809638400, // 350GiB + 429496729600, // 400GiB + 483183820800, // 450GiB + 536870912000, // 500GiB + ], yes_no(value, value_yes, value_no) { - if (!value_yes) - value_yes = "yes"; - if (!value_no) - value_no = "no"; + if (!value_yes) value_yes = "yes"; + if (!value_no) value_no = "no"; return value ? value_yes : value_no; }, standardHTTPError(response) { @@ -505,16 +600,20 @@ export default { 599: "Network Connect Timeout Error", }; - if (response === undefined) { // no response - //usually due to browser blocking failed OPTION preflight request - return "Cross-Origin Request Blocked: preflight request failed." + if (response === undefined) { + // no response + //usually due to browser blocking failed OPTION preflight request + return "Cross-Origin Request Blocked: preflight request failed."; } - let status_text = response.statusText ? response.statusText : statuses[response.status]; + let status_text = response.statusText + ? response.statusText + : statuses[response.status]; if (response.status == 400) { if (response.data && response.data.error) status_text += "
" + JSON.stringify(response.data.error); if (response.data && response.data.error_description) - status_text += "
" + JSON.stringify(response.data.error_description); + status_text += + "
" + JSON.stringify(response.data.error_description); if (response.data && response.data.message) status_text += "
" + JSON.stringify(response.data.message); } @@ -523,7 +622,7 @@ export default { format_dt: format_dt, format_duration: format_duration, format_duration_between: format_duration_between, - params_serializer:params_serializer, + params_serializer: params_serializer, now: now, image_human: image_human, image_url: image_url, From 27530a8577c1b0337923d3b13b1da3e675346ab7 Mon Sep 17 00:00:00 2001 From: benoit74 Date: Thu, 31 Oct 2024 10:45:07 +0000 Subject: [PATCH 2/3] Remove unused offliners constant --- dispatcher/frontend-ui/src/constants.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/dispatcher/frontend-ui/src/constants.js b/dispatcher/frontend-ui/src/constants.js index b42c98d53..f9470ca29 100644 --- a/dispatcher/frontend-ui/src/constants.js +++ b/dispatcher/frontend-ui/src/constants.js @@ -426,22 +426,6 @@ export default { "/.hidden/datacup", "/.hidden/custom_apps", ], - offliners: [ - "mwoffliner", - "youtube", - "phet", - "gutenberg", - "sotoki", - "nautilus", - "ted", - "openedx", - "zimit", - "kolibri", - "wikihow", - "ifixit", - "freecodecamp", - "devdocs", - ], periodicities: ["manually", "monthly", "quarterly", "biannualy", "annually"], memory_values: [ 536870912, // 512MiB From 7204e39467a5cb40dc66606a17e596d4dc4f6be7 Mon Sep 17 00:00:00 2001 From: benoit74 Date: Thu, 31 Oct 2024 10:50:58 +0000 Subject: [PATCH 3/3] Finish mindtouch deployment --- dispatcher/backend/src/common/enum.py | 1 + dispatcher/frontend-ui/src/components/Mixins.js | 4 ++-- dispatcher/frontend-ui/src/constants.js | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dispatcher/backend/src/common/enum.py b/dispatcher/backend/src/common/enum.py index 4213646a3..85d2c7722 100644 --- a/dispatcher/backend/src/common/enum.py +++ b/dispatcher/backend/src/common/enum.py @@ -195,6 +195,7 @@ def all(cls) -> set: cls.ifixit, cls.freecodecamp, cls.devdocs, + cls.mindtouch, } diff --git a/dispatcher/frontend-ui/src/components/Mixins.js b/dispatcher/frontend-ui/src/components/Mixins.js index df4302bbd..27d273b5d 100644 --- a/dispatcher/frontend-ui/src/components/Mixins.js +++ b/dispatcher/frontend-ui/src/components/Mixins.js @@ -14,10 +14,10 @@ export default { return process.env.BASE_URL; }, // for static files linking categories() { - return Constants.categories; + return Constants.categories.sort(); }, // list of categories for filter/edit warehouse_paths() { - return Constants.warehouse_paths; + return Constants.warehouse_paths.sort(); }, // list of paths for edit periodicities() { return Constants.periodicities; diff --git a/dispatcher/frontend-ui/src/constants.js b/dispatcher/frontend-ui/src/constants.js index f9470ca29..e9c5af2ed 100644 --- a/dispatcher/frontend-ui/src/constants.js +++ b/dispatcher/frontend-ui/src/constants.js @@ -394,8 +394,11 @@ export default { "wikiversity", "wikivoyage", "wiktionary", + "mindtouch", ], // list of categories for fileering warehouse_paths: [ + "/mindtouch", + "/libretexts", "/devdocs", "/freecodecamp", "/gutenberg",