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