исправлено автоскачивание проекта vMix на кнопку во вкладке игра
This commit is contained in:
21
app.py
21
app.py
@@ -549,9 +549,26 @@ def select_match(
|
|||||||
"success": True,
|
"success": True,
|
||||||
"session_token": session_token,
|
"session_token": session_token,
|
||||||
"session_url": f"/admin/session/{session_token}",
|
"session_url": f"/admin/session/{session_token}",
|
||||||
"download_url": f"/admin/session/{session_token}/download-vmix",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/admin/session/{session_token}/download-vmix-page", response_class=HTMLResponse)
|
||||||
|
def download_vmix_project_page(request: Request, session_token: str):
|
||||||
|
session_row = get_match_session_by_token(session_token)
|
||||||
|
if not session_row:
|
||||||
|
return RedirectResponse(url="/admin/matches", status_code=303)
|
||||||
|
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
name="download_vmix.html",
|
||||||
|
request=request,
|
||||||
|
context={
|
||||||
|
"session": session_row,
|
||||||
|
"session_token": session_token,
|
||||||
|
"download_url": f"/admin/session/{session_token}/download-vmix",
|
||||||
|
"back_url": f"/admin/session/{session_token}?tab=game",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/admin/session/{session_token}/download-vmix")
|
@app.get("/admin/session/{session_token}/download-vmix")
|
||||||
def download_vmix_project(session_token: str):
|
def download_vmix_project(session_token: str):
|
||||||
|
|||||||
142
templates/download_vmix.html
Normal file
142
templates/download_vmix.html
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0" />
|
||||||
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
|
<meta http-equiv="Expires" content="0" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Загрузка проекта vMix</title>
|
||||||
|
<link rel="stylesheet" href="/static/styles.css?v=20260421_1" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="matrixLoader" class="matrix-loader active" aria-hidden="false">
|
||||||
|
<canvas id="matrixCanvas" class="matrix-canvas"></canvas>
|
||||||
|
<div class="matrix-content">
|
||||||
|
<div class="matrix-title" id="matrixTitle">Загрузка vMix</div>
|
||||||
|
<div class="matrix-status" id="matrixStatusText">Подготовка проекта к скачиванию...</div>
|
||||||
|
<div style="margin-top: 18px;">
|
||||||
|
<a href="{{ back_url }}" class="btn btn-secondary">Назад к игре</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
const statusText = document.getElementById("matrixStatusText");
|
||||||
|
const titleEl = document.getElementById("matrixTitle");
|
||||||
|
const loader = document.getElementById("matrixLoader");
|
||||||
|
const canvas = document.getElementById("matrixCanvas");
|
||||||
|
const ctx = canvas ? canvas.getContext("2d") : null;
|
||||||
|
|
||||||
|
let matrixAnimationId = null;
|
||||||
|
let drops = [];
|
||||||
|
let fontSize = 16;
|
||||||
|
let columns = 0;
|
||||||
|
let lastTime = 0;
|
||||||
|
const fps = 18;
|
||||||
|
const interval = 1000 / fps;
|
||||||
|
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ@$%#*+=<>";
|
||||||
|
|
||||||
|
function resizeCanvas() {
|
||||||
|
if (!canvas || !ctx) return;
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
columns = Math.floor(canvas.width / fontSize);
|
||||||
|
drops = Array(columns).fill(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawMatrix(time = 0) {
|
||||||
|
if (!canvas || !ctx) return;
|
||||||
|
if (time - lastTime < interval) {
|
||||||
|
matrixAnimationId = requestAnimationFrame(drawMatrix);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastTime = time;
|
||||||
|
ctx.fillStyle = "rgba(0, 0, 0, 0.08)";
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
ctx.fillStyle = "#00ff66";
|
||||||
|
ctx.font = `${fontSize}px monospace`;
|
||||||
|
for (let i = 0; i < drops.length; i++) {
|
||||||
|
const text = chars[Math.floor(Math.random() * chars.length)];
|
||||||
|
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
|
||||||
|
if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) {
|
||||||
|
drops[i] = 0;
|
||||||
|
}
|
||||||
|
drops[i]++;
|
||||||
|
}
|
||||||
|
matrixAnimationId = requestAnimationFrame(drawMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setState(state, title, message) {
|
||||||
|
if (loader) {
|
||||||
|
loader.classList.remove("is-error", "is-success");
|
||||||
|
if (state) loader.classList.add(state);
|
||||||
|
}
|
||||||
|
if (titleEl) titleEl.textContent = title || "";
|
||||||
|
if (statusText) statusText.textContent = message || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startDownload() {
|
||||||
|
try {
|
||||||
|
setState("", "Загрузка vMix", "Формирование проекта...");
|
||||||
|
|
||||||
|
const response = await fetch("{{ download_url }}", {
|
||||||
|
method: "GET",
|
||||||
|
credentials: "same-origin"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
let errText = "Не удалось скачать vMix проект";
|
||||||
|
try {
|
||||||
|
const errJson = await response.json();
|
||||||
|
errText = errJson.error || errText;
|
||||||
|
} catch (_) {}
|
||||||
|
throw new Error(errText);
|
||||||
|
}
|
||||||
|
|
||||||
|
setState("", "Загрузка vMix", "Скачивание проекта...");
|
||||||
|
|
||||||
|
const blob = await response.blob();
|
||||||
|
let filename = "project.vmix";
|
||||||
|
const disposition = response.headers.get("Content-Disposition");
|
||||||
|
|
||||||
|
if (disposition) {
|
||||||
|
let match = disposition.match(/filename\*=UTF-8''([^;]+)/i);
|
||||||
|
if (match && match[1]) {
|
||||||
|
filename = decodeURIComponent(match[1]);
|
||||||
|
} else {
|
||||||
|
match = disposition.match(/filename="([^"]+)"/i);
|
||||||
|
if (match && match[1]) {
|
||||||
|
filename = match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const blobUrl = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = blobUrl;
|
||||||
|
a.download = filename;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
|
||||||
|
setState("is-success", "Готово", "Проект vMix успешно скачан. Возвращаемся во вкладку «Игра»...");
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
window.URL.revokeObjectURL(blobUrl);
|
||||||
|
window.location.href = "{{ back_url }}";
|
||||||
|
}, 1200);
|
||||||
|
} catch (error) {
|
||||||
|
setState("is-error", "Ошибка загрузки", error.message || "Не удалось скачать проект vMix");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("resize", resizeCanvas);
|
||||||
|
resizeCanvas();
|
||||||
|
drawMatrix();
|
||||||
|
startDownload();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -46,6 +46,26 @@
|
|||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vmix-download-btn {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vmix-icon {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: linear-gradient(135deg, #ff5f6d 0%, #7b61ff 100%);
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 800;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
letter-spacing: 0.02em;
|
||||||
|
box-shadow: 0 0 10px rgba(123, 97, 255, 0.28);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
@@ -105,6 +125,15 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="/admin/session/{{ session[3] }}/download-vmix-page"
|
||||||
|
class="icon-btn header-icon vmix-download-btn"
|
||||||
|
title="Скачать проект vMix"
|
||||||
|
aria-label="Скачать проект vMix"
|
||||||
|
>
|
||||||
|
<span class="vmix-icon" aria-hidden="true">V</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
method="post"
|
method="post"
|
||||||
action="/admin/session/{{ session[3] }}/close"
|
action="/admin/session/{{ session[3] }}/close"
|
||||||
|
|||||||
@@ -602,70 +602,6 @@
|
|||||||
throw new Error(data.error || data.vmix_error || "Не удалось выбрать матч");
|
throw new Error(data.error || data.vmix_error || "Не удалось выбрать матч");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.download_url) {
|
|
||||||
setLoaderState("",
|
|
||||||
"Подготовка матча",
|
|
||||||
"Формирование проекта vMix..."
|
|
||||||
);
|
|
||||||
|
|
||||||
const downloadResponse = await fetch(data.download_url, {
|
|
||||||
method: "GET",
|
|
||||||
credentials: "same-origin"
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!downloadResponse.ok) {
|
|
||||||
let errText = "Не удалось скачать vMix проект";
|
|
||||||
try {
|
|
||||||
const errJson = await downloadResponse.json();
|
|
||||||
errText = errJson.error || errText;
|
|
||||||
} catch (_) {}
|
|
||||||
throw new Error(errText);
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoaderState("",
|
|
||||||
"Подготовка матча",
|
|
||||||
"Скачивание проекта vMix..."
|
|
||||||
);
|
|
||||||
|
|
||||||
const blob = await downloadResponse.blob();
|
|
||||||
|
|
||||||
let filename = "project.vmix";
|
|
||||||
const disposition = downloadResponse.headers.get("Content-Disposition");
|
|
||||||
|
|
||||||
if (disposition) {
|
|
||||||
let match = disposition.match(/filename\*=UTF-8''([^;]+)/i);
|
|
||||||
if (match && match[1]) {
|
|
||||||
filename = decodeURIComponent(match[1]);
|
|
||||||
} else {
|
|
||||||
match = disposition.match(/filename="([^"]+)"/i);
|
|
||||||
if (match && match[1]) {
|
|
||||||
filename = match[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const blobUrl = window.URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement("a");
|
|
||||||
a.href = blobUrl;
|
|
||||||
a.download = filename;
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
a.remove();
|
|
||||||
|
|
||||||
setLoaderState(
|
|
||||||
"is-success",
|
|
||||||
"Загрузка завершена",
|
|
||||||
"Проект vMix успешно подготовлен.\nПереход во вкладку «Игра»..."
|
|
||||||
);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
window.URL.revokeObjectURL(blobUrl);
|
|
||||||
window.location.href = data.session_url + "?tab=game";
|
|
||||||
}, 1200);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoaderState(
|
setLoaderState(
|
||||||
"is-success",
|
"is-success",
|
||||||
"Загрузка завершена",
|
"Загрузка завершена",
|
||||||
|
|||||||
Reference in New Issue
Block a user