mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-11 04:19:26 -07:00
Run prettier across source files
This commit is contained in:
@@ -83,7 +83,9 @@ const PRESENCE_STYLES: Record<DiscordPresenceStylePreset, PresenceStyleDefinitio
|
||||
},
|
||||
};
|
||||
|
||||
function resolvePresenceStyle(preset: DiscordPresenceStylePreset | undefined): PresenceStyleDefinition {
|
||||
function resolvePresenceStyle(
|
||||
preset: DiscordPresenceStylePreset | undefined,
|
||||
): PresenceStyleDefinition {
|
||||
return PRESENCE_STYLES[preset ?? 'default'] ?? PRESENCE_STYLES.default;
|
||||
}
|
||||
|
||||
@@ -130,9 +132,7 @@ export function buildDiscordPresenceActivity(
|
||||
const status = buildStatus(snapshot);
|
||||
const title = sanitizeText(snapshot.mediaTitle, basename(snapshot.mediaPath) || 'Unknown media');
|
||||
const details =
|
||||
snapshot.connected && snapshot.mediaPath
|
||||
? trimField(title)
|
||||
: style.fallbackDetails;
|
||||
snapshot.connected && snapshot.mediaPath ? trimField(title) : style.fallbackDetails;
|
||||
const timeline = `${formatClock(snapshot.currentTimeSec)} / ${formatClock(snapshot.mediaDurationSec)}`;
|
||||
const state =
|
||||
snapshot.connected && snapshot.mediaPath
|
||||
@@ -157,10 +157,7 @@ export function buildDiscordPresenceActivity(
|
||||
if (style.smallImageText.trim().length > 0) {
|
||||
activity.smallImageText = trimField(style.smallImageText.trim());
|
||||
}
|
||||
if (
|
||||
style.buttonLabel.trim().length > 0 &&
|
||||
/^https?:\/\//.test(style.buttonUrl.trim())
|
||||
) {
|
||||
if (style.buttonLabel.trim().length > 0 && /^https?:\/\//.test(style.buttonUrl.trim())) {
|
||||
activity.buttons = [
|
||||
{
|
||||
label: trimField(style.buttonLabel.trim(), 32),
|
||||
|
||||
@@ -380,42 +380,22 @@ export class ImmersionTrackerService {
|
||||
};
|
||||
};
|
||||
|
||||
const eventsRetention = daysToRetentionWindow(
|
||||
retention.eventsDays,
|
||||
7,
|
||||
3650,
|
||||
);
|
||||
const telemetryRetention = daysToRetentionWindow(
|
||||
retention.telemetryDays,
|
||||
30,
|
||||
3650,
|
||||
);
|
||||
const sessionsRetention = daysToRetentionWindow(
|
||||
retention.sessionsDays,
|
||||
30,
|
||||
3650,
|
||||
);
|
||||
const eventsRetention = daysToRetentionWindow(retention.eventsDays, 7, 3650);
|
||||
const telemetryRetention = daysToRetentionWindow(retention.telemetryDays, 30, 3650);
|
||||
const sessionsRetention = daysToRetentionWindow(retention.sessionsDays, 30, 3650);
|
||||
this.eventsRetentionMs = eventsRetention.ms;
|
||||
this.eventsRetentionDays = eventsRetention.days;
|
||||
this.telemetryRetentionMs = telemetryRetention.ms;
|
||||
this.telemetryRetentionDays = telemetryRetention.days;
|
||||
this.sessionsRetentionMs = sessionsRetention.ms;
|
||||
this.sessionsRetentionDays = sessionsRetention.days;
|
||||
this.dailyRollupRetentionMs = daysToRetentionWindow(
|
||||
retention.dailyRollupsDays,
|
||||
365,
|
||||
36500,
|
||||
).ms;
|
||||
this.dailyRollupRetentionMs = daysToRetentionWindow(retention.dailyRollupsDays, 365, 36500).ms;
|
||||
this.monthlyRollupRetentionMs = daysToRetentionWindow(
|
||||
retention.monthlyRollupsDays,
|
||||
5 * 365,
|
||||
36500,
|
||||
).ms;
|
||||
this.vacuumIntervalMs = daysToRetentionWindow(
|
||||
retention.vacuumIntervalDays,
|
||||
7,
|
||||
3650,
|
||||
).ms;
|
||||
this.vacuumIntervalMs = daysToRetentionWindow(retention.vacuumIntervalDays, 7, 3650).ms;
|
||||
this.db = new Database(this.dbPath);
|
||||
applyPragmas(this.db);
|
||||
ensureSchema(this.db);
|
||||
|
||||
@@ -975,79 +975,79 @@ test('getTrendsDashboard month grouping spans every touched calendar month and k
|
||||
);
|
||||
}
|
||||
|
||||
const insertDailyRollup = db.prepare(
|
||||
`
|
||||
const insertDailyRollup = db.prepare(
|
||||
`
|
||||
INSERT INTO imm_daily_rollups (
|
||||
rollup_day, video_id, total_sessions, total_active_min, total_lines_seen,
|
||||
total_tokens_seen, total_cards, CREATED_DATE, LAST_UPDATE_DATE
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
);
|
||||
const insertMonthlyRollup = db.prepare(
|
||||
`
|
||||
);
|
||||
const insertMonthlyRollup = db.prepare(
|
||||
`
|
||||
INSERT INTO imm_monthly_rollups (
|
||||
rollup_month, video_id, total_sessions, total_active_min, total_lines_seen,
|
||||
total_tokens_seen, total_cards, CREATED_DATE, LAST_UPDATE_DATE
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
);
|
||||
insertDailyRollup.run(20500, febVideoId, 1, 30, 4, 100, 2, febStartedAtMs, febStartedAtMs);
|
||||
insertDailyRollup.run(20513, marVideoId, 1, 30, 4, 120, 4, marStartedAtMs, marStartedAtMs);
|
||||
insertMonthlyRollup.run(202602, febVideoId, 1, 30, 4, 100, 2, febStartedAtMs, febStartedAtMs);
|
||||
insertMonthlyRollup.run(202603, marVideoId, 1, 30, 4, 120, 4, marStartedAtMs, marStartedAtMs);
|
||||
);
|
||||
insertDailyRollup.run(20500, febVideoId, 1, 30, 4, 100, 2, febStartedAtMs, febStartedAtMs);
|
||||
insertDailyRollup.run(20513, marVideoId, 1, 30, 4, 120, 4, marStartedAtMs, marStartedAtMs);
|
||||
insertMonthlyRollup.run(202602, febVideoId, 1, 30, 4, 100, 2, febStartedAtMs, febStartedAtMs);
|
||||
insertMonthlyRollup.run(202603, marVideoId, 1, 30, 4, 120, 4, marStartedAtMs, marStartedAtMs);
|
||||
|
||||
db.prepare(
|
||||
`
|
||||
db.prepare(
|
||||
`
|
||||
INSERT INTO imm_words (
|
||||
headword, word, reading, part_of_speech, pos1, pos2, pos3, first_seen, last_seen, frequency
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
).run(
|
||||
'二月',
|
||||
'二月',
|
||||
'にがつ',
|
||||
'noun',
|
||||
'名詞',
|
||||
'',
|
||||
'',
|
||||
(BigInt(febStartedAtMs) / 1000n).toString(),
|
||||
(BigInt(febStartedAtMs) / 1000n).toString(),
|
||||
1,
|
||||
);
|
||||
db.prepare(
|
||||
`
|
||||
).run(
|
||||
'二月',
|
||||
'二月',
|
||||
'にがつ',
|
||||
'noun',
|
||||
'名詞',
|
||||
'',
|
||||
'',
|
||||
(BigInt(febStartedAtMs) / 1000n).toString(),
|
||||
(BigInt(febStartedAtMs) / 1000n).toString(),
|
||||
1,
|
||||
);
|
||||
db.prepare(
|
||||
`
|
||||
INSERT INTO imm_words (
|
||||
headword, word, reading, part_of_speech, pos1, pos2, pos3, first_seen, last_seen, frequency
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
).run(
|
||||
'三月',
|
||||
'三月',
|
||||
'さんがつ',
|
||||
'noun',
|
||||
'名詞',
|
||||
'',
|
||||
'',
|
||||
(BigInt(marStartedAtMs) / 1000n).toString(),
|
||||
(BigInt(marStartedAtMs) / 1000n).toString(),
|
||||
1,
|
||||
);
|
||||
).run(
|
||||
'三月',
|
||||
'三月',
|
||||
'さんがつ',
|
||||
'noun',
|
||||
'名詞',
|
||||
'',
|
||||
'',
|
||||
(BigInt(marStartedAtMs) / 1000n).toString(),
|
||||
(BigInt(marStartedAtMs) / 1000n).toString(),
|
||||
1,
|
||||
);
|
||||
|
||||
const dashboard = getTrendsDashboard(db, '30d', 'month');
|
||||
const dashboard = getTrendsDashboard(db, '30d', 'month');
|
||||
|
||||
assert.equal(dashboard.activity.watchTime.length, 2);
|
||||
assert.deepEqual(
|
||||
dashboard.progress.newWords.map((point) => point.label),
|
||||
dashboard.activity.watchTime.map((point) => point.label),
|
||||
);
|
||||
assert.deepEqual(
|
||||
dashboard.progress.episodes.map((point) => point.label),
|
||||
dashboard.activity.watchTime.map((point) => point.label),
|
||||
);
|
||||
assert.deepEqual(
|
||||
dashboard.progress.lookups.map((point) => point.label),
|
||||
dashboard.activity.watchTime.map((point) => point.label),
|
||||
);
|
||||
assert.equal(dashboard.activity.watchTime.length, 2);
|
||||
assert.deepEqual(
|
||||
dashboard.progress.newWords.map((point) => point.label),
|
||||
dashboard.activity.watchTime.map((point) => point.label),
|
||||
);
|
||||
assert.deepEqual(
|
||||
dashboard.progress.episodes.map((point) => point.label),
|
||||
dashboard.activity.watchTime.map((point) => point.label),
|
||||
);
|
||||
assert.deepEqual(
|
||||
dashboard.progress.lookups.map((point) => point.label),
|
||||
dashboard.activity.watchTime.map((point) => point.label),
|
||||
);
|
||||
} finally {
|
||||
db.close();
|
||||
cleanupDbPath(dbPath);
|
||||
@@ -1230,18 +1230,7 @@ test('getQueryHints counts new words by distinct headword first-seen time', () =
|
||||
headword, word, reading, part_of_speech, pos1, pos2, pos3, first_seen, last_seen, frequency
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
).run(
|
||||
'猫',
|
||||
'猫',
|
||||
'ねこ',
|
||||
'noun',
|
||||
'名詞',
|
||||
'',
|
||||
'',
|
||||
String(twoDaysAgo),
|
||||
String(twoDaysAgo),
|
||||
1,
|
||||
);
|
||||
).run('猫', '猫', 'ねこ', 'noun', '名詞', '', '', String(twoDaysAgo), String(twoDaysAgo), 1);
|
||||
|
||||
const hints = getQueryHints(db);
|
||||
assert.equal(hints.newWordsToday, 1);
|
||||
|
||||
@@ -82,12 +82,9 @@ function hasRetainedPriorSession(
|
||||
LIMIT 1
|
||||
`,
|
||||
)
|
||||
.get(
|
||||
videoId,
|
||||
toDbTimestamp(startedAtMs),
|
||||
toDbTimestamp(startedAtMs),
|
||||
currentSessionId,
|
||||
) as { found: number } | null;
|
||||
.get(videoId, toDbTimestamp(startedAtMs), toDbTimestamp(startedAtMs), currentSessionId) as {
|
||||
found: number;
|
||||
} | null;
|
||||
return Boolean(row);
|
||||
}
|
||||
|
||||
@@ -150,7 +147,7 @@ function resetLifetimeSummaries(db: DatabaseSync, nowMs: number): void {
|
||||
LAST_UPDATE_DATE = ?
|
||||
WHERE global_id = 1
|
||||
`,
|
||||
).run(toDbTimestamp(nowMs), toDbTimestamp(nowMs));
|
||||
).run(toDbTimestamp(nowMs), toDbTimestamp(nowMs));
|
||||
}
|
||||
|
||||
function rebuildLifetimeSummariesInternal(
|
||||
|
||||
@@ -126,9 +126,9 @@ test('pruneRawRetention skips disabled retention windows', () => {
|
||||
const remainingTelemetry = db
|
||||
.prepare('SELECT COUNT(*) AS count FROM imm_session_telemetry')
|
||||
.get() as { count: number };
|
||||
const remainingSessions = db
|
||||
.prepare('SELECT COUNT(*) AS count FROM imm_sessions')
|
||||
.get() as { count: number };
|
||||
const remainingSessions = db.prepare('SELECT COUNT(*) AS count FROM imm_sessions').get() as {
|
||||
count: number;
|
||||
};
|
||||
|
||||
assert.equal(result.deletedSessionEvents, 0);
|
||||
assert.equal(result.deletedTelemetryRows, 0);
|
||||
|
||||
@@ -56,10 +56,7 @@ export function pruneRawRetention(
|
||||
sessionsRetentionDays?: number;
|
||||
},
|
||||
): RawRetentionResult {
|
||||
const resolveCutoff = (
|
||||
retentionMs: number,
|
||||
retentionDays: number | undefined,
|
||||
): string => {
|
||||
const resolveCutoff = (retentionMs: number, retentionDays: number | undefined): string => {
|
||||
if (retentionDays !== undefined) {
|
||||
return subtractDbTimestamp(currentMs, BigInt(retentionDays) * 86_400_000n);
|
||||
}
|
||||
@@ -68,9 +65,11 @@ export function pruneRawRetention(
|
||||
|
||||
const deletedSessionEvents = Number.isFinite(policy.eventsRetentionMs)
|
||||
? (
|
||||
db.prepare(`DELETE FROM imm_session_events WHERE ts_ms < ?`).run(
|
||||
resolveCutoff(policy.eventsRetentionMs, policy.eventsRetentionDays),
|
||||
) as { changes: number }
|
||||
db
|
||||
.prepare(`DELETE FROM imm_session_events WHERE ts_ms < ?`)
|
||||
.run(resolveCutoff(policy.eventsRetentionMs, policy.eventsRetentionDays)) as {
|
||||
changes: number;
|
||||
}
|
||||
).changes
|
||||
: 0;
|
||||
const deletedTelemetryRows = Number.isFinite(policy.telemetryRetentionMs)
|
||||
|
||||
@@ -150,9 +150,11 @@ export function getSessionEvents(
|
||||
ORDER BY ts_ms ASC
|
||||
LIMIT ?
|
||||
`);
|
||||
const rows = stmt.all(sessionId, ...eventTypes, limit) as Array<SessionEventRow & {
|
||||
tsMs: number | string;
|
||||
}>;
|
||||
const rows = stmt.all(sessionId, ...eventTypes, limit) as Array<
|
||||
SessionEventRow & {
|
||||
tsMs: number | string;
|
||||
}
|
||||
>;
|
||||
return rows.map((row) => ({
|
||||
...row,
|
||||
tsMs: fromDbTimestamp(row.tsMs) ?? 0,
|
||||
|
||||
@@ -355,9 +355,7 @@ export function upsertCoverArt(
|
||||
const fetchedAtMs = toDbTimestamp(nowMs());
|
||||
const coverBlob = normalizeCoverBlobBytes(art.coverBlob);
|
||||
const computedCoverBlobHash =
|
||||
coverBlob && coverBlob.length > 0
|
||||
? createHash('sha256').update(coverBlob).digest('hex')
|
||||
: null;
|
||||
coverBlob && coverBlob.length > 0 ? createHash('sha256').update(coverBlob).digest('hex') : null;
|
||||
let coverBlobHash = computedCoverBlobHash ?? sharedCoverBlobHash ?? null;
|
||||
if (!coverBlobHash && (!coverBlob || coverBlob.length === 0)) {
|
||||
coverBlobHash = existing?.coverBlobHash ?? null;
|
||||
|
||||
@@ -39,10 +39,12 @@ export function getSessionSummaries(db: DatabaseSync, limit = 50): SessionSummar
|
||||
ORDER BY s.started_at_ms DESC
|
||||
LIMIT ?
|
||||
`);
|
||||
const rows = prepared.all(limit) as Array<SessionSummaryQueryRow & {
|
||||
startedAtMs: number | string;
|
||||
endedAtMs: number | string | null;
|
||||
}>;
|
||||
const rows = prepared.all(limit) as Array<
|
||||
SessionSummaryQueryRow & {
|
||||
startedAtMs: number | string;
|
||||
endedAtMs: number | string | null;
|
||||
}
|
||||
>;
|
||||
return rows.map((row) => ({
|
||||
...row,
|
||||
startedAtMs: fromDbTimestamp(row.startedAtMs) ?? 0,
|
||||
@@ -69,19 +71,21 @@ export function getSessionTimeline(
|
||||
`;
|
||||
|
||||
if (limit === undefined) {
|
||||
const rows = db.prepare(select).all(sessionId) as Array<SessionTimelineRow & {
|
||||
sampleMs: number | string;
|
||||
}>;
|
||||
const rows = db.prepare(select).all(sessionId) as Array<
|
||||
SessionTimelineRow & {
|
||||
sampleMs: number | string;
|
||||
}
|
||||
>;
|
||||
return rows.map((row) => ({
|
||||
...row,
|
||||
sampleMs: fromDbTimestamp(row.sampleMs) ?? 0,
|
||||
}));
|
||||
}
|
||||
const rows = db
|
||||
.prepare(`${select}\n LIMIT ?`)
|
||||
.all(sessionId, limit) as Array<SessionTimelineRow & {
|
||||
sampleMs: number | string;
|
||||
}>;
|
||||
const rows = db.prepare(`${select}\n LIMIT ?`).all(sessionId, limit) as Array<
|
||||
SessionTimelineRow & {
|
||||
sampleMs: number | string;
|
||||
}
|
||||
>;
|
||||
return rows.map((row) => ({
|
||||
...row,
|
||||
sampleMs: fromDbTimestamp(row.sampleMs) ?? 0,
|
||||
|
||||
@@ -359,10 +359,7 @@ function getNumericCalendarValue(
|
||||
return Number(row?.value ?? 0);
|
||||
}
|
||||
|
||||
export function getLocalEpochDay(
|
||||
db: DatabaseSync,
|
||||
timestampMs: number | bigint | string,
|
||||
): number {
|
||||
export function getLocalEpochDay(db: DatabaseSync, timestampMs: number | bigint | string): number {
|
||||
return getNumericCalendarValue(
|
||||
db,
|
||||
`
|
||||
@@ -375,10 +372,7 @@ export function getLocalEpochDay(
|
||||
);
|
||||
}
|
||||
|
||||
export function getLocalMonthKey(
|
||||
db: DatabaseSync,
|
||||
timestampMs: number | bigint | string,
|
||||
): number {
|
||||
export function getLocalMonthKey(db: DatabaseSync, timestampMs: number | bigint | string): number {
|
||||
return getNumericCalendarValue(
|
||||
db,
|
||||
`
|
||||
@@ -391,10 +385,7 @@ export function getLocalMonthKey(
|
||||
);
|
||||
}
|
||||
|
||||
export function getLocalDayOfWeek(
|
||||
db: DatabaseSync,
|
||||
timestampMs: number | bigint | string,
|
||||
): number {
|
||||
export function getLocalDayOfWeek(db: DatabaseSync, timestampMs: number | bigint | string): number {
|
||||
return getNumericCalendarValue(
|
||||
db,
|
||||
`
|
||||
@@ -407,10 +398,7 @@ export function getLocalDayOfWeek(
|
||||
);
|
||||
}
|
||||
|
||||
export function getLocalHourOfDay(
|
||||
db: DatabaseSync,
|
||||
timestampMs: number | bigint | string,
|
||||
): number {
|
||||
export function getLocalHourOfDay(db: DatabaseSync, timestampMs: number | bigint | string): number {
|
||||
return getNumericCalendarValue(
|
||||
db,
|
||||
`
|
||||
@@ -458,7 +446,8 @@ export function getShiftedLocalDayTimestamp(
|
||||
dayOffset: number,
|
||||
): string {
|
||||
const normalizedDayOffset = Math.trunc(dayOffset);
|
||||
const modifier = normalizedDayOffset >= 0 ? `+${normalizedDayOffset} days` : `${normalizedDayOffset} days`;
|
||||
const modifier =
|
||||
normalizedDayOffset >= 0 ? `+${normalizedDayOffset} days` : `${normalizedDayOffset} days`;
|
||||
const row = db
|
||||
.prepare(
|
||||
`
|
||||
|
||||
@@ -87,7 +87,20 @@ const TREND_DAY_LIMITS: Record<Exclude<TrendRange, 'all'>, number> = {
|
||||
'90d': 90,
|
||||
};
|
||||
|
||||
const MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
const MONTH_NAMES = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
|
||||
const DAY_NAMES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
|
||||
@@ -101,7 +114,11 @@ function getTrendMonthlyLimit(db: DatabaseSync, range: TrendRange): number {
|
||||
}
|
||||
const currentTimestamp = currentDbTimestamp();
|
||||
const todayStartMs = getShiftedLocalDayTimestamp(db, currentTimestamp, 0);
|
||||
const cutoffMs = getShiftedLocalDayTimestamp(db, currentTimestamp, -(TREND_DAY_LIMITS[range] - 1));
|
||||
const cutoffMs = getShiftedLocalDayTimestamp(
|
||||
db,
|
||||
currentTimestamp,
|
||||
-(TREND_DAY_LIMITS[range] - 1),
|
||||
);
|
||||
const currentMonthKey = getLocalMonthKey(db, todayStartMs);
|
||||
const cutoffMonthKey = getLocalMonthKey(db, cutoffMs);
|
||||
const currentYear = Math.floor(currentMonthKey / 100);
|
||||
@@ -630,8 +647,10 @@ export function getTrendsDashboard(
|
||||
|
||||
const animePerDay = {
|
||||
episodes: buildEpisodesPerAnimeFromDailyRollups(dailyRollups, titlesByVideoId),
|
||||
watchTime: buildPerAnimeFromDailyRollups(dailyRollups, titlesByVideoId, (rollup) =>
|
||||
rollup.totalActiveMin,
|
||||
watchTime: buildPerAnimeFromDailyRollups(
|
||||
dailyRollups,
|
||||
titlesByVideoId,
|
||||
(rollup) => rollup.totalActiveMin,
|
||||
),
|
||||
cards: buildPerAnimeFromDailyRollups(
|
||||
dailyRollups,
|
||||
|
||||
@@ -102,7 +102,9 @@ type SubtitleTrackCandidate = {
|
||||
externalFilename: string | null;
|
||||
};
|
||||
|
||||
function normalizeSubtitleTrackCandidate(track: Record<string, unknown>): SubtitleTrackCandidate | null {
|
||||
function normalizeSubtitleTrackCandidate(
|
||||
track: Record<string, unknown>,
|
||||
): SubtitleTrackCandidate | null {
|
||||
const id =
|
||||
typeof track.id === 'number'
|
||||
? track.id
|
||||
@@ -122,8 +124,12 @@ function normalizeSubtitleTrackCandidate(track: Record<string, unknown>): Subtit
|
||||
|
||||
return {
|
||||
id,
|
||||
lang: String(track.lang || '').trim().toLowerCase(),
|
||||
title: String(track.title || '').trim().toLowerCase(),
|
||||
lang: String(track.lang || '')
|
||||
.trim()
|
||||
.toLowerCase(),
|
||||
title: String(track.title || '')
|
||||
.trim()
|
||||
.toLowerCase(),
|
||||
selected: track.selected === true,
|
||||
external: track.external === true,
|
||||
externalFilename,
|
||||
@@ -168,9 +174,7 @@ function pickSecondarySubtitleTrackId(
|
||||
const uniqueTracks = [...dedupedTracks.values()];
|
||||
|
||||
for (const language of normalizedLanguages) {
|
||||
const selectedMatch = uniqueTracks.find(
|
||||
(track) => track.selected && track.lang === language,
|
||||
);
|
||||
const selectedMatch = uniqueTracks.find((track) => track.selected && track.lang === language);
|
||||
if (selectedMatch) {
|
||||
return selectedMatch.id;
|
||||
}
|
||||
|
||||
@@ -102,10 +102,7 @@ async function writeFetchResponse(res: ServerResponse, response: Response): Prom
|
||||
res.end(Buffer.from(body));
|
||||
}
|
||||
|
||||
function startNodeHttpServer(
|
||||
app: Hono,
|
||||
config: StatsServerConfig,
|
||||
): { close: () => void } {
|
||||
function startNodeHttpServer(app: Hono, config: StatsServerConfig): { close: () => void } {
|
||||
const server = http.createServer((req, res) => {
|
||||
void (async () => {
|
||||
try {
|
||||
@@ -1075,11 +1072,9 @@ export function startStatsServer(config: StatsServerConfig): { close: () => void
|
||||
|
||||
const bunRuntime = globalThis as typeof globalThis & {
|
||||
Bun?: {
|
||||
serve?: (options: {
|
||||
fetch: (typeof app)['fetch'];
|
||||
port: number;
|
||||
hostname: string;
|
||||
}) => { stop: () => void };
|
||||
serve?: (options: { fetch: (typeof app)['fetch']; port: number; hostname: string }) => {
|
||||
stop: () => void;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -77,7 +77,11 @@ function normalizeTrackIds(tracks: unknown[]): MpvTrack[] {
|
||||
}
|
||||
|
||||
function getSourceTrackIdentity(track: MpvTrack): string {
|
||||
if (track.external && typeof track['external-filename'] === 'string' && track['external-filename'].length > 0) {
|
||||
if (
|
||||
track.external &&
|
||||
typeof track['external-filename'] === 'string' &&
|
||||
track['external-filename'].length > 0
|
||||
) {
|
||||
return `external:${track['external-filename'].toLowerCase()}`;
|
||||
}
|
||||
if (typeof track.id === 'number') {
|
||||
|
||||
@@ -2029,7 +2029,8 @@ export async function addYomitanNoteViaSearch(
|
||||
: null,
|
||||
duplicateNoteIds: Array.isArray(envelope.duplicateNoteIds)
|
||||
? envelope.duplicateNoteIds.filter(
|
||||
(entry): entry is number => typeof entry === 'number' && Number.isInteger(entry) && entry > 0,
|
||||
(entry): entry is number =>
|
||||
typeof entry === 'number' && Number.isInteger(entry) && entry > 0,
|
||||
)
|
||||
: [],
|
||||
};
|
||||
|
||||
@@ -16,11 +16,12 @@ async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
||||
|
||||
function makeFakeYtDlpScript(dir: string, payload: string): void {
|
||||
const scriptPath = path.join(dir, 'yt-dlp');
|
||||
const script = process.platform === 'win32'
|
||||
? `#!/usr/bin/env bun
|
||||
const script =
|
||||
process.platform === 'win32'
|
||||
? `#!/usr/bin/env bun
|
||||
process.stdout.write(${JSON.stringify(payload)});
|
||||
`
|
||||
: `#!/usr/bin/env sh
|
||||
: `#!/usr/bin/env sh
|
||||
cat <<'EOF' | base64 -d
|
||||
${Buffer.from(payload).toString('base64')}
|
||||
EOF
|
||||
|
||||
@@ -16,11 +16,12 @@ async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
||||
|
||||
function makeFakeYtDlpScript(dir: string, payload: string): void {
|
||||
const scriptPath = path.join(dir, 'yt-dlp');
|
||||
const script = process.platform === 'win32'
|
||||
? `#!/usr/bin/env bun
|
||||
const script =
|
||||
process.platform === 'win32'
|
||||
? `#!/usr/bin/env bun
|
||||
process.stdout.write(${JSON.stringify(payload)});
|
||||
`
|
||||
: `#!/usr/bin/env sh
|
||||
: `#!/usr/bin/env sh
|
||||
cat <<'EOF' | base64 -d
|
||||
${Buffer.from(payload).toString('base64')}
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user