mirror of
https://github.com/tuna/mirror-web.git
synced 2025-12-25 20:32:46 +00:00
reformat, change tab to space
This commit is contained in:
parent
28da3dced1
commit
9dd20e063b
|
|
@ -8,9 +8,9 @@ root = true
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|
||||||
[*.{html,md,js}]
|
[*.{html,md,js,vue,es6,json}]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
indent_style = tab
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
# Matches the exact files either package.json or .travis.yml
|
# Matches the exact files either package.json or .travis.yml
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ empty.mount("#upgrade-mask");
|
||||||
const isoModalEl = document.getElementById("isoModal");
|
const isoModalEl = document.getElementById("isoModal");
|
||||||
|
|
||||||
createApp(IsoModal, {
|
createApp(IsoModal, {
|
||||||
onReady: async function () {
|
onReady: async function () {
|
||||||
if (window.location.hash.match(/#iso-download(\?.*)?/)) {
|
if (window.location.hash.match(/#iso-download(\?.*)?/)) {
|
||||||
new BootStrapModal(isoModalEl).show();
|
new BootStrapModal(isoModalEl).show();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}).mount(isoModalEl);
|
}).mount(isoModalEl);
|
||||||
|
|
||||||
createApp(MainMirrorList).mount("#mirror-list");
|
createApp(MainMirrorList).mount("#mirror-list");
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ import "../styles/global.scss";
|
||||||
import { suffix as siteSuffix } from "virtual:jekyll-config";
|
import { suffix as siteSuffix } from "virtual:jekyll-config";
|
||||||
|
|
||||||
if (siteSuffix) {
|
if (siteSuffix) {
|
||||||
if (
|
if (
|
||||||
!document.location.hostname.endsWith(siteSuffix) &&
|
!document.location.hostname.endsWith(siteSuffix) &&
|
||||||
!document.location.hostname.endsWith(siteSuffix + ".")
|
!document.location.hostname.endsWith(siteSuffix + ".")
|
||||||
) {
|
) {
|
||||||
document.title = document.title.replace(/(清华)|(tsinghua)|(tuna)/gi, "");
|
document.title = document.title.replace(/(清华)|(tsinghua)|(tuna)/gi, "");
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
document.body.classList.add("nonthu");
|
document.body.classList.add("nonthu");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import {
|
import {
|
||||||
hide_mirrorz as HideMirrorZ,
|
hide_mirrorz as HideMirrorZ,
|
||||||
hostname as SiteHostname,
|
hostname as SiteHostname,
|
||||||
mirrorz_help_link as MirrorzHelpLink,
|
mirrorz_help_link as MirrorzHelpLink,
|
||||||
} from "virtual:jekyll-config";
|
} from "virtual:jekyll-config";
|
||||||
import { options as globalOptions } from "virtual:jekyll-data";
|
import { options as globalOptions } from "virtual:jekyll-data";
|
||||||
import hljs from "../lib/hljs";
|
import hljs from "../lib/hljs";
|
||||||
|
|
@ -12,87 +12,87 @@ import "./default";
|
||||||
import "../styles/help.scss";
|
import "../styles/help.scss";
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
Array.from(document.querySelectorAll("#help-content table")).map((el) => {
|
Array.from(document.querySelectorAll("#help-content table")).map((el) => {
|
||||||
el.classList.add("table", "table-bordered", "table-striped");
|
el.classList.add("table", "table-bordered", "table-striped");
|
||||||
});
|
});
|
||||||
|
|
||||||
const update_target = (ev) => {
|
const update_target = (ev) => {
|
||||||
const sel = ev.target;
|
const sel = ev.target;
|
||||||
const target_selectors = sel.attributes["data-target"].value.split(",");
|
const target_selectors = sel.attributes["data-target"].value.split(",");
|
||||||
for (const target_selector of target_selectors) {
|
for (const target_selector of target_selectors) {
|
||||||
const target = document.querySelector(target_selector);
|
const target = document.querySelector(target_selector);
|
||||||
const template_selector = target.attributes["data-template"].value;
|
const template_selector = target.attributes["data-template"].value;
|
||||||
const select_selectors =
|
const select_selectors =
|
||||||
target.attributes["data-select"].value.split(",");
|
target.attributes["data-select"].value.split(",");
|
||||||
let url = "/" + mirrorId;
|
let url = "/" + mirrorId;
|
||||||
if (mirrorId.endsWith(".git")) {
|
if (mirrorId.endsWith(".git")) {
|
||||||
url = "/git/" + mirrorId;
|
url = "/git/" + mirrorId;
|
||||||
}
|
}
|
||||||
const template_data = {
|
const template_data = {
|
||||||
mirror: SiteHostname + url,
|
mirror: SiteHostname + url,
|
||||||
};
|
};
|
||||||
for (const select_selector of select_selectors) {
|
for (const select_selector of select_selectors) {
|
||||||
const opt_attrs = document
|
const opt_attrs = document
|
||||||
.querySelector(select_selector)
|
.querySelector(select_selector)
|
||||||
.querySelector("option:checked").attributes;
|
.querySelector("option:checked").attributes;
|
||||||
for (const attr of opt_attrs) {
|
for (const attr of opt_attrs) {
|
||||||
if (attr.name.startsWith("data-")) {
|
if (attr.name.startsWith("data-")) {
|
||||||
template_data[attr.name.slice(5)] = attr.value;
|
template_data[attr.name.slice(5)] = attr.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// special hack for case-insensitive
|
// special hack for case-insensitive
|
||||||
if ("sudoe" in template_data) {
|
if ("sudoe" in template_data) {
|
||||||
template_data.sudoE = template_data.sudoe;
|
template_data.sudoE = template_data.sudoe;
|
||||||
}
|
}
|
||||||
const template = document
|
const template = document
|
||||||
.querySelector(template_selector)
|
.querySelector(template_selector)
|
||||||
.textContent.trim();
|
.textContent.trim();
|
||||||
const content = Mark.up(template, template_data);
|
const content = Mark.up(template, template_data);
|
||||||
target.innerHTML = content;
|
target.innerHTML = content;
|
||||||
hljs.highlightElement(target);
|
hljs.highlightElement(target);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.from(document.querySelectorAll("select.content-select")).map((el) => {
|
Array.from(document.querySelectorAll("select.content-select")).map((el) => {
|
||||||
el.addEventListener("change", update_target);
|
el.addEventListener("change", update_target);
|
||||||
el.dispatchEvent(new Event("change"));
|
el.dispatchEvent(new Event("change"));
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("help-select").addEventListener("change", (ev) => {
|
document.getElementById("help-select").addEventListener("change", (ev) => {
|
||||||
let help_url =
|
let help_url =
|
||||||
ev.target.querySelector("option:checked").attributes["data-help-url"]
|
ev.target.querySelector("option:checked").attributes["data-help-url"]
|
||||||
.value;
|
.value;
|
||||||
window.location = `${window.location.protocol}//${window.location.host}${help_url}`;
|
window.location = `${window.location.protocol}//${window.location.host}${help_url}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
fetch(TUNASYNC_JSON_PATH)
|
fetch(TUNASYNC_JSON_PATH)
|
||||||
.then((resp) => resp.json())
|
.then((resp) => resp.json())
|
||||||
.then((statusData) => {
|
.then((statusData) => {
|
||||||
// remove help items for disabled/removed mirrors
|
// remove help items for disabled/removed mirrors
|
||||||
let availableMirrorIds = new Set(statusData.map((x) => x.name));
|
let availableMirrorIds = new Set(statusData.map((x) => x.name));
|
||||||
globalOptions.unlisted_mirrors.forEach((elem) => {
|
globalOptions.unlisted_mirrors.forEach((elem) => {
|
||||||
availableMirrorIds.add(elem.name);
|
availableMirrorIds.add(elem.name);
|
||||||
});
|
});
|
||||||
if (!availableMirrorIds.has(mirrorId)) {
|
if (!availableMirrorIds.has(mirrorId)) {
|
||||||
if (HideMirrorZ) {
|
if (HideMirrorZ) {
|
||||||
location.href = "/404-help-hidden.html"; // this will break 404 issue submission
|
location.href = "/404-help-hidden.html"; // this will break 404 issue submission
|
||||||
} else {
|
} else {
|
||||||
location.href = MirrorzHelpLink + mirrorId; // TODO: convert this to mirrorz cname
|
location.href = MirrorzHelpLink + mirrorId; // TODO: convert this to mirrorz cname
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.from(
|
Array.from(
|
||||||
document.querySelectorAll('option[id^="toc-"],li[id^="toc-"]'),
|
document.querySelectorAll('option[id^="toc-"],li[id^="toc-"]'),
|
||||||
).forEach((elem) => {
|
).forEach((elem) => {
|
||||||
if (
|
if (
|
||||||
elem.id.startsWith("toc-") &&
|
elem.id.startsWith("toc-") &&
|
||||||
!availableMirrorIds.has(elem.id.slice(4))
|
!availableMirrorIds.has(elem.id.slice(4))
|
||||||
) {
|
) {
|
||||||
elem.remove();
|
elem.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// vim: ts=2 sts=2 sw=2 noexpandtab
|
// vim: ts=2 sts=2 sw=2 noexpandtab
|
||||||
|
|
|
||||||
|
|
@ -5,109 +5,109 @@ import { mirrorId } from "../lib/mirrorid";
|
||||||
import Mustache from "mustache";
|
import Mustache from "mustache";
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", function () {
|
window.addEventListener("DOMContentLoaded", function () {
|
||||||
function generateFormConfig(form) {
|
function generateFormConfig(form) {
|
||||||
const formData = Object.fromEntries(new FormData(form).entries());
|
const formData = Object.fromEntries(new FormData(form).entries());
|
||||||
Array.from(
|
Array.from(
|
||||||
// FormData ignores unchecked checkboxes, workaround
|
// FormData ignores unchecked checkboxes, workaround
|
||||||
form.querySelectorAll("input[type=checkbox]:not(:checked)"),
|
form.querySelectorAll("input[type=checkbox]:not(:checked)"),
|
||||||
).forEach((elm) => {
|
).forEach((elm) => {
|
||||||
formData[elm.name] = "";
|
formData[elm.name] = "";
|
||||||
});
|
});
|
||||||
let conf = {};
|
let conf = {};
|
||||||
for (const x in formData) {
|
for (const x in formData) {
|
||||||
conf[x] = formData[x];
|
conf[x] = formData[x];
|
||||||
const varConf = GLOBAL_CONFIG.input[x];
|
const varConf = GLOBAL_CONFIG.input[x];
|
||||||
if (!varConf) continue;
|
if (!varConf) continue;
|
||||||
let optConf = null;
|
let optConf = null;
|
||||||
if ("option" in varConf) optConf = varConf.option[formData[x]];
|
if ("option" in varConf) optConf = varConf.option[formData[x]];
|
||||||
else if ("true" in varConf || "false" in varConf) {
|
else if ("true" in varConf || "false" in varConf) {
|
||||||
optConf = formData[x] === "on" ? varConf.true : varConf.false;
|
optConf = formData[x] === "on" ? varConf.true : varConf.false;
|
||||||
}
|
}
|
||||||
if (typeof optConf === "object") Object.assign(conf, optConf);
|
if (typeof optConf === "object") Object.assign(conf, optConf);
|
||||||
if (typeof optConf === "string") conf[x] = optConf;
|
if (typeof optConf === "string") conf[x] = optConf;
|
||||||
}
|
}
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderCode(tmpl) {
|
function renderCode(tmpl) {
|
||||||
// generate mustache config
|
// generate mustache config
|
||||||
let conf = {
|
let conf = {
|
||||||
path: (mirrorId.endsWith(".git") ? "/git/" : "/") + mirrorId,
|
path: (mirrorId.endsWith(".git") ? "/git/" : "/") + mirrorId,
|
||||||
};
|
};
|
||||||
Array.from(document.querySelectorAll("form.z-global")).forEach((elm) => {
|
Array.from(document.querySelectorAll("form.z-global")).forEach((elm) => {
|
||||||
Object.assign(conf, generateFormConfig(elm));
|
Object.assign(conf, generateFormConfig(elm));
|
||||||
});
|
});
|
||||||
conf.scheme = conf._scheme ? "https" : "http";
|
conf.scheme = conf._scheme ? "https" : "http";
|
||||||
conf.host = conf.host.replace(/^https?:\/\//, "");
|
conf.host = conf.host.replace(/^https?:\/\//, "");
|
||||||
conf.sudo = conf._sudo ? "sudo " : "";
|
conf.sudo = conf._sudo ? "sudo " : "";
|
||||||
if (conf.filter && GLOBAL_CONFIG.filter.scheme) {
|
if (conf.filter && GLOBAL_CONFIG.filter.scheme) {
|
||||||
conf.scheme = GLOBAL_CONFIG.filter.scheme;
|
conf.scheme = GLOBAL_CONFIG.filter.scheme;
|
||||||
}
|
}
|
||||||
// find div.z-wrap
|
// find div.z-wrap
|
||||||
const div = tmpl.previousElementSibling;
|
const div = tmpl.previousElementSibling;
|
||||||
// find form.z-form
|
// find form.z-form
|
||||||
const form = div.querySelector("form.z-form");
|
const form = div.querySelector("form.z-form");
|
||||||
// find form.z-code
|
// find form.z-code
|
||||||
var code = div.querySelector("pre.z-code");
|
var code = div.querySelector("pre.z-code");
|
||||||
if (code === null) {
|
if (code === null) {
|
||||||
code = document.createElement("pre");
|
code = document.createElement("pre");
|
||||||
code.classList.add("z-code");
|
code.classList.add("z-code");
|
||||||
div.appendChild(code);
|
div.appendChild(code);
|
||||||
}
|
}
|
||||||
if (form) Object.assign(conf, generateFormConfig(form));
|
if (form) Object.assign(conf, generateFormConfig(form));
|
||||||
conf.endpoint = conf.scheme + "://" + conf.host + conf.path;
|
conf.endpoint = conf.scheme + "://" + conf.host + conf.path;
|
||||||
|
|
||||||
// render with mustache
|
// render with mustache
|
||||||
let rendered = Mustache.render(
|
let rendered = Mustache.render(
|
||||||
tmpl.textContent.trim(),
|
tmpl.textContent.trim(),
|
||||||
conf,
|
conf,
|
||||||
{},
|
{},
|
||||||
{ escape: (x) => x },
|
{ escape: (x) => x },
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
const lang = tmpl.attributes.getNamedItem("z-lang");
|
const lang = tmpl.attributes.getNamedItem("z-lang");
|
||||||
if (lang && hljs.getLanguage(lang.value)) {
|
if (lang && hljs.getLanguage(lang.value)) {
|
||||||
rendered = hljs.highlight(rendered, { language: lang.value }).value;
|
rendered = hljs.highlight(rendered, { language: lang.value }).value;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
code.innerHTML = rendered;
|
code.innerHTML = rendered;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderForm(event) {
|
function renderForm(event) {
|
||||||
if (!event || event.currentTarget.classList.contains("z-global")) {
|
if (!event || event.currentTarget.classList.contains("z-global")) {
|
||||||
Array.from(document.querySelectorAll(".z-help pre.z-tmpl")).forEach(
|
Array.from(document.querySelectorAll(".z-help pre.z-tmpl")).forEach(
|
||||||
renderCode,
|
renderCode,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
renderCode(event.currentTarget.parentElement.nextElementSibling);
|
renderCode(event.currentTarget.parentElement.nextElementSibling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load project config
|
// Load project config
|
||||||
const GLOBAL_CONFIG = JSON.parse(
|
const GLOBAL_CONFIG = JSON.parse(
|
||||||
atob(document.getElementById("z-config").textContent),
|
atob(document.getElementById("z-config").textContent),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hide HTTPS selector if filtered
|
// Hide HTTPS selector if filtered
|
||||||
if (GLOBAL_CONFIG.filter && GLOBAL_CONFIG.filter.scheme) {
|
if (GLOBAL_CONFIG.filter && GLOBAL_CONFIG.filter.scheme) {
|
||||||
document.querySelector(
|
document.querySelector(
|
||||||
'input[name="_scheme"]',
|
'input[name="_scheme"]',
|
||||||
).parentElement.style.display = "none";
|
).parentElement.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render code
|
// Render code
|
||||||
renderForm(null);
|
renderForm(null);
|
||||||
|
|
||||||
const ignoreEventHandler = (event) => event.preventDefault();
|
const ignoreEventHandler = (event) => event.preventDefault();
|
||||||
|
|
||||||
for (const form of document.querySelectorAll("form.z-form")) {
|
for (const form of document.querySelectorAll("form.z-form")) {
|
||||||
form.addEventListener("submit", ignoreEventHandler);
|
form.addEventListener("submit", ignoreEventHandler);
|
||||||
if (form.classList.contains("z-global")) {
|
if (form.classList.contains("z-global")) {
|
||||||
form.addEventListener("change", () => renderForm(null));
|
form.addEventListener("change", () => renderForm(null));
|
||||||
} else {
|
} else {
|
||||||
form.addEventListener("change", renderForm);
|
form.addEventListener("change", renderForm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ bugLink.href = bugURL.href;
|
||||||
const mrLink = document.getElementById("new_issue_mr");
|
const mrLink = document.getElementById("new_issue_mr");
|
||||||
const mrURL = new URL(mrLink.href);
|
const mrURL = new URL(mrLink.href);
|
||||||
mrURL.searchParams.append(
|
mrURL.searchParams.append(
|
||||||
"title",
|
"title",
|
||||||
tag + "Mirror Request for new mirror " + location.pathname.split("/")[1],
|
tag + "Mirror Request for new mirror " + location.pathname.split("/")[1],
|
||||||
);
|
);
|
||||||
mrLink.href = mrURL.href;
|
mrLink.href = mrURL.href;
|
||||||
|
|
|
||||||
|
|
@ -6,120 +6,120 @@ import { format as TimeAgoFormat } from "timeago.js";
|
||||||
const label_map = globalOptions.label_map;
|
const label_map = globalOptions.label_map;
|
||||||
|
|
||||||
export const useMirrorList = (additional = []) => {
|
export const useMirrorList = (additional = []) => {
|
||||||
const mirrorList = ref([]);
|
const mirrorList = ref([]);
|
||||||
let refreshTimer = null;
|
let refreshTimer = null;
|
||||||
|
|
||||||
const refreshMirrorList = async () => {
|
const refreshMirrorList = async () => {
|
||||||
if (document.hidden === true) {
|
if (document.hidden === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await fetch(TUNASYNC_JSON_PATH);
|
const res = await fetch(TUNASYNC_JSON_PATH);
|
||||||
const status_data = await res.json();
|
const status_data = await res.json();
|
||||||
const processed = status_data
|
const processed = status_data
|
||||||
.concat(additional)
|
.concat(additional)
|
||||||
.map((d) => processMirrorItem(d));
|
.map((d) => processMirrorItem(d));
|
||||||
mirrorList.value = sortAndUniqMirrors(processLinkItem(processed));
|
mirrorList.value = sortAndUniqMirrors(processLinkItem(processed));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
refreshTimer = setTimeout(refreshMirrorList, 10000);
|
refreshTimer = setTimeout(refreshMirrorList, 10000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
nextTick().then(() => refreshMirrorList());
|
nextTick().then(() => refreshMirrorList());
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
window.addEventListener("visibilitychange", () => {
|
window.addEventListener("visibilitychange", () => {
|
||||||
if (refreshTimer) {
|
if (refreshTimer) {
|
||||||
clearTimeout(refreshTimer);
|
clearTimeout(refreshTimer);
|
||||||
refreshTimer = null;
|
refreshTimer = null;
|
||||||
}
|
}
|
||||||
if (document.visibilityState === "visible") {
|
if (document.visibilityState === "visible") {
|
||||||
refreshMirrorList().then();
|
refreshMirrorList().then();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return mirrorList;
|
return mirrorList;
|
||||||
};
|
};
|
||||||
|
|
||||||
const processLinkItem = (mirrors) => {
|
const processLinkItem = (mirrors) => {
|
||||||
var processed = [];
|
var processed = [];
|
||||||
for (let d of mirrors) {
|
for (let d of mirrors) {
|
||||||
if (d.link_to === undefined) {
|
if (d.link_to === undefined) {
|
||||||
processed.push(d);
|
processed.push(d);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (const target of mirrors) {
|
for (const target of mirrors) {
|
||||||
if (d.link_to === target.name) {
|
if (d.link_to === target.name) {
|
||||||
d.status = target.status;
|
d.status = target.status;
|
||||||
d.label = target.label;
|
d.label = target.label;
|
||||||
d.upstream = target.upstream;
|
d.upstream = target.upstream;
|
||||||
d.show_status = target.show_status;
|
d.show_status = target.show_status;
|
||||||
d.last_update = target.last_update;
|
d.last_update = target.last_update;
|
||||||
d.last_update_ago = target.last_update_ago;
|
d.last_update_ago = target.last_update_ago;
|
||||||
d.last_ended = target.last_ended;
|
d.last_ended = target.last_ended;
|
||||||
d.last_ended_ago = target.last_ended_ago;
|
d.last_ended_ago = target.last_ended_ago;
|
||||||
d.last_schedule = target.last_schedule;
|
d.last_schedule = target.last_schedule;
|
||||||
d.last_schedule_ago = target.last_schedule_ago;
|
d.last_schedule_ago = target.last_schedule_ago;
|
||||||
processed.push(d);
|
processed.push(d);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return processed;
|
return processed;
|
||||||
};
|
};
|
||||||
|
|
||||||
const stringifyTime = (ts) => {
|
const stringifyTime = (ts) => {
|
||||||
const date = new Date(ts * 1000);
|
const date = new Date(ts * 1000);
|
||||||
let str = "";
|
let str = "";
|
||||||
let ago = "";
|
let ago = "";
|
||||||
if (date.getFullYear() > 2000) {
|
if (date.getFullYear() > 2000) {
|
||||||
str =
|
str =
|
||||||
`${("000" + date.getFullYear()).slice(-4)}-${("0" + (date.getMonth() + 1)).slice(-2)}-${("0" + date.getDate()).slice(-2)}` +
|
`${("000" + date.getFullYear()).slice(-4)}-${("0" + (date.getMonth() + 1)).slice(-2)}-${("0" + date.getDate()).slice(-2)}` +
|
||||||
` ${("0" + date.getHours()).slice(-2)}:${("0" + date.getMinutes()).slice(-2)}`;
|
` ${("0" + date.getHours()).slice(-2)}:${("0" + date.getMinutes()).slice(-2)}`;
|
||||||
ago = TimeAgoFormat(date);
|
ago = TimeAgoFormat(date);
|
||||||
} else {
|
} else {
|
||||||
str = "0000-00-00 00:00";
|
str = "0000-00-00 00:00";
|
||||||
ago = "Never";
|
ago = "Never";
|
||||||
}
|
}
|
||||||
return [str, ago];
|
return [str, ago];
|
||||||
};
|
};
|
||||||
|
|
||||||
const processMirrorItem = (d) => {
|
const processMirrorItem = (d) => {
|
||||||
if (d.is_master === undefined) {
|
if (d.is_master === undefined) {
|
||||||
d.is_master = true;
|
d.is_master = true;
|
||||||
}
|
}
|
||||||
if (d.link_to !== undefined) {
|
if (d.link_to !== undefined) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
d.label = label_map[d.status];
|
d.label = label_map[d.status];
|
||||||
d.show_status = d.status != "success";
|
d.show_status = d.status != "success";
|
||||||
// Strip the second component of last_update
|
// Strip the second component of last_update
|
||||||
[d.last_update, d.last_update_ago] = stringifyTime(d.last_update_ts);
|
[d.last_update, d.last_update_ago] = stringifyTime(d.last_update_ts);
|
||||||
[d.last_ended, d.last_ended_ago] = stringifyTime(d.last_ended_ts);
|
[d.last_ended, d.last_ended_ago] = stringifyTime(d.last_ended_ts);
|
||||||
[d.last_started, d.last_started_ago] = stringifyTime(d.last_started_ts);
|
[d.last_started, d.last_started_ago] = stringifyTime(d.last_started_ts);
|
||||||
[d.next_schedule, d.next_schedule_ago] = stringifyTime(d.next_schedule_ts);
|
[d.next_schedule, d.next_schedule_ago] = stringifyTime(d.next_schedule_ts);
|
||||||
return d;
|
return d;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sortAndUniqMirrors = (mirs) => {
|
const sortAndUniqMirrors = (mirs) => {
|
||||||
mirs.sort((a, b) => {
|
mirs.sort((a, b) => {
|
||||||
return a.name < b.name ? -1 : 1;
|
return a.name < b.name ? -1 : 1;
|
||||||
});
|
});
|
||||||
return mirs.reduce((acc, cur) => {
|
return mirs.reduce((acc, cur) => {
|
||||||
if (acc.length > 1 && acc[acc.length - 1].name == cur.name) {
|
if (acc.length > 1 && acc[acc.length - 1].name == cur.name) {
|
||||||
if (acc[acc.length - 1].last_update_ts && cur.last_update_ts) {
|
if (acc[acc.length - 1].last_update_ts && cur.last_update_ts) {
|
||||||
if (acc[acc.length - 1].last_update_ts < cur.last_update_ts) {
|
if (acc[acc.length - 1].last_update_ts < cur.last_update_ts) {
|
||||||
acc[acc.length - 1] = cur;
|
acc[acc.length - 1] = cur;
|
||||||
}
|
}
|
||||||
} else if (cur.last_update_ts) {
|
} else if (cur.last_update_ts) {
|
||||||
acc[acc.length - 1] = cur;
|
acc[acc.length - 1] = cur;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
acc.push(cur);
|
acc.push(cur);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export const mirrorId = JSON.parse(
|
export const mirrorId = JSON.parse(
|
||||||
Array.from(document.getElementsByTagName("script")).filter(
|
Array.from(document.getElementsByTagName("script")).filter(
|
||||||
(script) => script.type === "text/x-tuna-help-mirrorid",
|
(script) => script.type === "text/x-tuna-help-mirrorid",
|
||||||
)[0]?.textContent || '""',
|
)[0]?.textContent || '""',
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue