You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.1 KiB
JavaScript
101 lines
3.1 KiB
JavaScript
const assetVersion = new URL(import.meta.url).searchParams.get('v');
|
|
|
|
function versionedModuleUrl(path) {
|
|
const url = new URL(path, import.meta.url);
|
|
url.search = '';
|
|
if (assetVersion) url.searchParams.set('v', assetVersion);
|
|
return url.href;
|
|
}
|
|
|
|
const [
|
|
presentation,
|
|
{ mountOperationsDirectory },
|
|
{ mountOperationsHealth },
|
|
{ mountOperationsRecovery },
|
|
taskObserver,
|
|
] = await Promise.all([
|
|
import(versionedModuleUrl('./admin-operation-presentation.js')),
|
|
import(versionedModuleUrl('./admin-operations-directory.js')),
|
|
import(versionedModuleUrl('./admin-operations-health.js')),
|
|
import(versionedModuleUrl('./admin-operations-recovery.js')),
|
|
import(versionedModuleUrl('./task-observer.js')),
|
|
]);
|
|
|
|
const root = document.querySelector('[data-admin-operations]');
|
|
|
|
if (root) {
|
|
const requestRuntime = window.VenixAdminRequestRuntime.create({
|
|
taskReceiptValidator: taskObserver.taskUrl,
|
|
});
|
|
const transport = Object.freeze({
|
|
read(path, options = {}) {
|
|
return requestRuntime.read(path, {
|
|
signal: options.signal,
|
|
timeoutMs: options.timeoutMs || 15000,
|
|
headers: options.headers || {},
|
|
method: String(options.method || 'GET').toUpperCase(),
|
|
});
|
|
},
|
|
mutate(path, options = {}) {
|
|
return requestRuntime.mutate(path, {
|
|
signal: options.signal,
|
|
timeoutMs: options.timeoutMs || 15000,
|
|
headers: options.headers || {},
|
|
method: String(options.method || 'POST').toUpperCase(),
|
|
body: options.body,
|
|
response: 'json',
|
|
});
|
|
},
|
|
async acceptedTask(path, options = {}) {
|
|
const payload = await requestRuntime.mutate(path, {
|
|
signal: options.signal,
|
|
timeoutMs: options.timeoutMs || 15000,
|
|
headers: options.headers || {},
|
|
method: String(options.method || 'POST').toUpperCase(),
|
|
body: options.body,
|
|
response: 'task',
|
|
});
|
|
if (!taskObserver.taskUrl(payload)) {
|
|
throw new Error('服务未返回严格的任务回执;为避免重复执行,请勿再次提交并联系管理员。');
|
|
}
|
|
return payload;
|
|
},
|
|
});
|
|
const confirmDanger = options => window.VenixAdminDangerDialog.confirm(options);
|
|
|
|
let directory;
|
|
const recovery = mountOperationsRecovery({
|
|
root,
|
|
transport,
|
|
presentation,
|
|
taskObserver,
|
|
confirmDanger,
|
|
refreshDirectory: () => directory.refresh(),
|
|
notifyDirectory: (message, error = false) => directory.notify(message, error),
|
|
});
|
|
directory = mountOperationsDirectory({
|
|
root,
|
|
transport,
|
|
presentation,
|
|
onOpenDetail: (id, opener) => { void recovery.open(id, opener); },
|
|
});
|
|
const health = mountOperationsHealth({ transport, presentation });
|
|
|
|
window.addEventListener('popstate', () => {
|
|
recovery.close();
|
|
void directory.restore();
|
|
});
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (!document.hidden) return;
|
|
directory.abort('hidden');
|
|
health.abort('hidden');
|
|
recovery.abort('hidden');
|
|
});
|
|
window.addEventListener('pagehide', () => {
|
|
directory.abort('pagehide');
|
|
health.abort('pagehide');
|
|
recovery.abort('pagehide');
|
|
recovery.persistScroll();
|
|
});
|
|
}
|