Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions scripts/sync-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,25 @@ console.error(`tracker ${text}`);
The response body says what happened either way; this turns it into a red
run on the schedule instead of nicer scrollback nobody reads. A body that
does not parse at all is a red run too: a truncated 200 is not a confirmed
sync. */
let result: { failures?: string[] } | null = null;
sync. JSON.parse also accepts {}, [] and bare primitives, none of which
carry a failure list, so the shape is checked before it is trusted —
otherwise each of them reads as a successful run. */
let result: { failures: string[] };
try {
result = JSON.parse(text);
const parsed: unknown = JSON.parse(text);
if (
!parsed ||
typeof parsed !== 'object' ||
!Array.isArray((parsed as { failures?: unknown }).failures)
) {
throw new Error('invalid sync response shape');
}
result = parsed as { failures: string[] };
} catch {
console.error('tracker invalid sync response');
process.exit(1);
}
if (result?.failures?.length) {
if (result.failures.length) {
console.error(`tracker reconcile failures: ${result.failures.join(', ')}`);
process.exit(1);
}
Expand Down
152 changes: 95 additions & 57 deletions scripts/sync-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
* the app itself shows users, which makes it the only value a reporter can
* realistically be expected to match.
*
* Sources the index has dropped are kept as tombstones rather than deleted.
* Reports hold a bare source_id, so deleting a row strips every report about
* that source of its name, 404s its prerendered page, and freezes its nsfw
* flag outside reconcileNsfw's reach. mergeCatalogue stamps the day on the row
* instead; a source the index lists again comes back live with fresh fields.
*
* bun run sync:sources
*/

import type { SourceRow } from '../src/lib/sources';

const INDEX_URL =
'https://raw.githubusercontent.com/yuzono/anime-repo/repo/index.min.json';
const OUT = new URL('../src/data/sources.json', import.meta.url);
Expand All @@ -26,67 +34,97 @@ type IndexEntry = {
sources: { name: string; lang: string; id: string; baseUrl: string }[];
};

export type SourceRow = {
id: string;
name: string;
lang: string;
baseUrl: string;
extPkg: string;
extName: string;
extVersion: string;
extVersionCode: number;
nsfw: boolean;
};

const res = await fetch(INDEX_URL, { headers: { 'user-agent': 'yuzono-tracker/sync' } });
if (!res.ok) throw new Error(`index fetch failed: ${res.status} ${res.statusText}`);
export function flatten(index: IndexEntry[]): { rows: SourceRow[]; duplicates: number } {
const rows = new Map<string, SourceRow>();
let duplicates = 0;

const index = (await res.json()) as IndexEntry[];
for (const ext of index) {
// Strip the app prefix the index uses for display ("Aniyomi: AnimeOnsen").
const extName = ext.name.replace(/^\s*(Aniyomi|Anikku|Tachiyomi)\s*:\s*/i, '');

const rows = new Map<string, SourceRow>();
let duplicates = 0;
for (const src of ext.sources ?? []) {
if (rows.has(src.id)) {
duplicates++;
continue;
}
rows.set(src.id, {
id: src.id,
name: src.name,
lang: src.lang || ext.lang,
baseUrl: src.baseUrl,
extPkg: ext.pkg,
extName,
extVersion: ext.version,
extVersionCode: ext.code,
nsfw: ext.nsfw === 1,
});
}
}

for (const ext of index) {
// Strip the app prefix the index uses for display ("Aniyomi: AnimeOnsen").
const extName = ext.name.replace(/^\s*(Aniyomi|Anikku|Tachiyomi)\s*:\s*/i, '');
return { rows: [...rows.values()], duplicates };
}

for (const src of ext.sources ?? []) {
if (rows.has(src.id)) {
duplicates++;
continue;
}
rows.set(src.id, {
id: src.id,
name: src.name,
lang: src.lang || ext.lang,
baseUrl: src.baseUrl,
extPkg: ext.pkg,
extName,
extVersion: ext.version,
extVersionCode: ext.code,
nsfw: ext.nsfw === 1,
});
/**
* Upstream wins every field, so a returning id is reborn with the fresh name
* and version and loses `removed`. An id upstream has dropped carries over as
* a tombstone stamped with the day it was noticed gone — and the `??` keeps an
* existing stamp, which is what stops this re-stamping on every five-minute
* run and leaves the commit diff empty once nothing moved.
*/
export function mergeCatalogue(
previous: SourceRow[],
upstream: SourceRow[],
today: string,
): SourceRow[] {
const live = new Map(upstream.map((r) => [r.id, r]));
const merged = new Map<string, SourceRow>();
for (const row of upstream) merged.set(row.id, { ...row });
for (const row of previous) {
if (!live.has(row.id)) merged.set(row.id, { ...row, removed: row.removed ?? today });
}
return [...merged.values()].sort(
(a, b) => a.name.localeCompare(b.name) || a.lang.localeCompare(b.lang),
);
}

const sorted = [...rows.values()].sort(
(a, b) => a.name.localeCompare(b.name) || a.lang.localeCompare(b.lang),
);

await Bun.write(OUT, JSON.stringify(sorted, null, 2) + '\n');

const byLang = sorted.reduce<Record<string, number>>((acc, s) => {
acc[s.lang] = (acc[s.lang] ?? 0) + 1;
return acc;
}, {});
const topLangs = Object.entries(byLang)
.sort((a, b) => b[1] - a[1])
.slice(0, 8)
.map(([l, n]) => `${l}:${n}`)
.join(' ');

console.log(`extensions ${index.length}`);
console.log(`sources ${sorted.length}${duplicates ? ` (${duplicates} duplicate ids skipped)` : ''}`);
console.log(`nsfw ${sorted.filter((s) => s.nsfw).length}`);
console.log(`languages ${Object.keys(byLang).length} ${topLangs}`);
console.log(`wrote src/data/sources.json`);
if (import.meta.main) {
const res = await fetch(INDEX_URL, { headers: { 'user-agent': 'yuzono-tracker/sync' } });
if (!res.ok) throw new Error(`index fetch failed: ${res.status} ${res.statusText}`);

const index = (await res.json()) as IndexEntry[];
const { rows, duplicates } = flatten(index);

let previous: SourceRow[] = [];
try {
previous = (await Bun.file(OUT).json()) as SourceRow[];
} catch (err) {
/* Only a missing file means "first run". A catalogue that exists but
cannot be read or parsed must stop the sync: falling back to [] here
would write an upstream-only file and silently drop every tombstone. */
if ((err as { code?: string })?.code !== 'ENOENT') throw err;
}

const sorted = mergeCatalogue(previous, rows, new Date().toISOString().slice(0, 10));

await Bun.write(OUT, JSON.stringify(sorted, null, 2) + '\n');
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const byLang = sorted.reduce<Record<string, number>>((acc, s) => {
acc[s.lang] = (acc[s.lang] ?? 0) + 1;
return acc;
}, {});
const topLangs = Object.entries(byLang)
.sort((a, b) => b[1] - a[1])
.slice(0, 8)
.map(([l, n]) => `${l}:${n}`)
.join(' ');

const liveIds = new Set(rows.map((r) => r.id));
const gone = previous.filter((r) => !r.removed && !liveIds.has(r.id));

console.log(`extensions ${index.length}`);
console.log(`sources ${sorted.length}${duplicates ? ` (${duplicates} duplicate ids skipped)` : ''}`);
console.log(`removed ${gone.length}${gone.length ? ` (${gone.map((s) => s.name).join(', ')})` : ''}`);
console.log(`nsfw ${sorted.filter((s) => s.nsfw).length}`);
console.log(`languages ${Object.keys(byLang).length} ${topLangs}`);
console.log(`wrote src/data/sources.json`);
}
9 changes: 7 additions & 2 deletions src/components/ReportRow.astro
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,16 @@ const asked = r.kind === 'feature' ? KIND_LABELS.feature : null;
{source && <span class="data">v{source.extVersion}</span>}
{
/* The closing date has already been said above, so the filing date
would be a second date on the row with nothing to distinguish it. */
would be a second date on the row with nothing to distinguish it.
A closed row whose status_changed_at was never set gets the age
labelled: bare, "Fixed" followed by a number reads as the closing
date. */
stalled ? (
<span class="stalled">{stalled}</span>
) : closed ? null : (
) : closed ? null : live ? (
<span>{relativeAge(r.createdAt)} ago</span>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
) : (
<span>Filed {relativeAge(r.createdAt)} ago</span>
)
}
{adult && <span class="adult">18+</span>}
Expand Down
46 changes: 32 additions & 14 deletions src/components/SourceStatus.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import { OPEN_STATUSES } from '../lib/db/schema';
interface Props {
sourceId: string;
sort?: 'demand' | 'recent';
/**
* The day the source left the catalogue, when it did. Suppresses both
* report CTAs: /new rejects a removed source, so the page must not invite
* a submission that can only end in an error.
*/
removed?: string;
}
const { sourceId } = Astro.props;
const { sourceId, removed } = Astro.props as Props;
const qs = Astro.url.searchParams.get('sort');
const sort = (Astro.props as Props).sort ?? (qs === 'recent' ? 'recent' : 'demand');
const basePath = Astro.url.pathname;
Expand All @@ -31,16 +37,26 @@ const closed = all.filter((r) => !(OPEN_STATUSES as readonly string[]).includes(

{
open.length === 0 ? (
<div class="ok">
<p class="ok-title">No open reports</p>
<p class="ok-sub">
Nobody has reported this source as broken. If it's failing for you, say so. You'll
be the first.
</p>
<a class="btn btn-primary" href={`/new?source=${sourceId}`}>
Report a problem
</a>
</div>
removed ? (
<div class="ok">
<p class="ok-sub">
{closed.length === 0
? 'No problems were reported before it was removed.'
: 'No open problems remain.'}
</p>
</div>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
) : (
<div class="ok">
<p class="ok-title">No open reports</p>
<p class="ok-sub">
Nobody has reported this source as broken. If it's failing for you, say so. You'll
be the first.
</p>
<a class="btn btn-primary" href={`/new?source=${sourceId}`}>
Report a problem
</a>
</div>
)
) : (
<section>
<div class="sort-row">
Expand All @@ -55,9 +71,11 @@ const closed = all.filter((r) => !(OPEN_STATUSES as readonly string[]).includes(
<ReportRow report={r} mine={backed.has(r.id)} />
))}
</ol>
<a class="btn add" href={`/new?source=${sourceId}`}>
Something else is broken
</a>
{!removed && (
<a class="btn add" href={`/new?source=${sourceId}`}>
Something else is broken
</a>
)}
</section>
)
}
Expand Down
12 changes: 12 additions & 0 deletions src/data/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,18 @@
"extVersionCode": 7,
"nsfw": false
},
{
"id": "5343978110335507456",
"name": "NoobSubs",
"lang": "en",
"baseUrl": "https://noobftp1.noobsubs.com",
"extPkg": "eu.kanade.tachiyomi.animeextension.en.noobsubs",
"extName": "NoobSubs",
"extVersion": "14.1",
"extVersionCode": 1,
"nsfw": false,
"removed": "2026-08-24"
},
{
"id": "5310001068353260432",
"name": "Nyaa (Torrent)",
Expand Down
26 changes: 26 additions & 0 deletions src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ export function relativeAge(createdAt: number, now = Date.now() / 1000): string
return `${Math.floor(d / 365)}y`;
}

/**
* A fixed day, said once: "24 August 2026".
*
* The relative formatters above are wrong for anything baked into a
* prerendered page. /source/<slug>/ rebuilds only on deploy, so a "removed two
* days ago" rendered at build time would freeze there and lie a little more
* every day after. Assembled from formatToParts rather than formatted whole,
* because plain 'en' orders month-first ("August 24, 2026") and this reads as
* a day. timeZone is pinned to UTC because an ISO-only date parses to midnight
* UTC — left to the machine's zone, a build in the Americas would print the
* previous day.
*/
export function absoluteDate(iso: string): string {
const parts = new Map(
new Intl.DateTimeFormat('en', {
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'UTC',
})
.formatToParts(new Date(iso))
.map((p) => [p.type, p.value] as const),
);
return `${parts.get('day')} ${parts.get('month')} ${parts.get('year')}`;
}

export const STAGE_LABELS = {
browse: 'Browse',
episodes: 'Episodes',
Expand Down
10 changes: 7 additions & 3 deletions src/lib/github-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { announceFixed } from './webhook';
import { notifyWatchers } from './notify';
import { logAction } from './staff';
import { readConfig, type Config } from './settings';
import { SOURCES } from './sources';
import { ALL_SOURCES } from './sources';
import {
classifyIssue,
promoteTitle,
Expand Down Expand Up @@ -378,8 +378,12 @@ export async function reconcileRequestNames(actor: Actor): Promise<number> {
* survives every later pass.
*/
export async function reconcileNsfw(actor: Actor): Promise<number> {
const adult = SOURCES.filter((s) => s.nsfw).map((s) => s.id);
const tame = SOURCES.filter((s) => !s.nsfw).map((s) => s.id);
// ALL_SOURCES, not SOURCES: a delisted id sits in neither list otherwise,
// and its reports' nsfw flag freezes permanently — with no moderator control
// on /report for catalogue-backed rows to fix it by hand. A tombstone keeps
// the last known flag governing.
const adult = ALL_SOURCES.filter((s) => s.nsfw).map((s) => s.id);
const tame = ALL_SOURCES.filter((s) => !s.nsfw).map((s) => s.id);
const d = db();

/* The id lists travel as one json_each parameter each, via inIds. D1 caps
Expand Down
Loading