feat: record anonymous download type events
This commit is contained in:
1 parent
783e620214
commit
6e9f0ac648
2 files changed
+19
-1
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
args:
|
args:
|
||||||
VERSION: v2026.08.26-r6
|
VERSION: v2026.08.27-r7
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8083:8080"
|
- "127.0.0.1:8083:8080"
|
||||||
|
|||||||
+18
@@ -5,6 +5,16 @@ const results = document.querySelector('#results');
|
|||||||
const modeNote = document.querySelector('#mode-note');
|
const modeNote = document.querySelector('#mode-note');
|
||||||
const localDownloads = document.querySelector('#local-downloads');
|
const localDownloads = document.querySelector('#local-downloads');
|
||||||
const lyricCache = new Map();
|
const lyricCache = new Map();
|
||||||
|
let publicMode = false;
|
||||||
|
|
||||||
|
const downloadEvents = {
|
||||||
|
lrc: 'original-lrc',
|
||||||
|
txt: 'original-txt',
|
||||||
|
transLRC: 'translation-lrc',
|
||||||
|
transTXT: 'translation-txt',
|
||||||
|
romaLRC: 'sound-lrc',
|
||||||
|
romaTXT: 'sound-txt'
|
||||||
|
};
|
||||||
|
|
||||||
function text(value) { return document.createTextNode(value ?? ''); }
|
function text(value) { return document.createTextNode(value ?? ''); }
|
||||||
function hasText(value) { return typeof value === 'string' && value.trim().length > 0; }
|
function hasText(value) { return typeof value === 'string' && value.trim().length > 0; }
|
||||||
@@ -26,6 +36,7 @@ async function loadInfo() {
|
|||||||
if (info.mode === 'local') {
|
if (info.mode === 'local') {
|
||||||
modeNote.textContent = '本机模式:查询从这台电脑直接发出,不经过 lrc.flechazo.xin。';
|
modeNote.textContent = '本机模式:查询从这台电脑直接发出,不经过 lrc.flechazo.xin。';
|
||||||
} else {
|
} else {
|
||||||
|
publicMode = true;
|
||||||
modeNote.textContent = '网页模式:查询由本站后端转发,但不会写入数据库或日志正文。下载文件在浏览器中生成。';
|
modeNote.textContent = '网页模式:查询由本站后端转发,但不会写入数据库或日志正文。下载文件在浏览器中生成。';
|
||||||
localDownloads.hidden = false;
|
localDownloads.hidden = false;
|
||||||
}
|
}
|
||||||
@@ -46,6 +57,12 @@ function download(name, body, type = 'text/plain;charset=utf-8') {
|
|||||||
setTimeout(() => URL.revokeObjectURL(url), 1500);
|
setTimeout(() => URL.revokeObjectURL(url), 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function recordDownload(kind) {
|
||||||
|
const event = downloadEvents[kind];
|
||||||
|
if (!publicMode || !event) return;
|
||||||
|
fetch(`/api/events/download/${event}`, {method: 'POST', keepalive: true}).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
function parseLRC(lrc) {
|
function parseLRC(lrc) {
|
||||||
const lines = [];
|
const lines = [];
|
||||||
for (const raw of (lrc || '').split(/\r?\n/)) {
|
for (const raw of (lrc || '').split(/\r?\n/)) {
|
||||||
@@ -129,6 +146,7 @@ function saveLyrics(song, data, kind) {
|
|||||||
const selected = variants[kind];
|
const selected = variants[kind];
|
||||||
if (!selected || !hasText(selected[1])) throw new Error('这首歌没有对应歌词');
|
if (!selected || !hasText(selected[1])) throw new Error('这首歌没有对应歌词');
|
||||||
download(selected[0], selected[1]);
|
download(selected[0], selected[1]);
|
||||||
|
recordDownload(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
function populatePreview(select, output, data) {
|
function populatePreview(select, output, data) {
|
||||||
|
|||||||
Reference in new issue
Block a user