Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 17 additions & 0 deletions scripts/sync-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ const text = await res.text();
if (!res.ok) throw new Error(`tracker rejected it: ${res.status} ${text.slice(0, 300)}`);
console.error(`tracker ${text}`);

/* A 200 can still name reconcile steps that threw — see SyncResult.failures.
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;
try {
result = JSON.parse(text);
} catch {
console.error('tracker invalid sync response');
process.exit(1);
}
if (result?.failures?.length) {
console.error(`tracker reconcile failures: ${result.failures.join(', ')}`);
process.exit(1);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

function unix(iso: string) {
return Math.floor(new Date(iso).getTime() / 1000);
}
Expand Down
149 changes: 92 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,94 @@ 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 {
/* A checkout with no catalogue yet — there is nothing to carry over. */
}

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`);
}
89 changes: 54 additions & 35 deletions src/components/FilterBar.astro
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
---
import { languageFacets, SOURCES } from '../lib/sources';
import { CAUSE_LABELS } from '../lib/format';
import { BOARD_VIEW_COPY, CAUSE_LABELS, type BoardFamily } from '../lib/format';
import type { BoardState } from '../lib/queries';

interface Props {
family: 'broken' | 'wanted';
family: BoardFamily;
lang?: string;
cause?: string;
nsfw: boolean;
sort: string;
/** Which half of the backlog is on screen. */
state?: 'open' | 'fixed';
/** How many are open, and how many have been fixed, in this family. */
/** Which third of the backlog is on screen. */
state?: BoardState;
/** How many are open, fixed or closed-without-a-fix, in this family. */
openCount: number;
fixedCount: number;
otherCount: number;
}

const {
Expand All @@ -24,9 +26,10 @@ const {
state = 'open',
openCount,
fixedCount,
otherCount,
} = Astro.props;
const langs = languageFacets();
const fixedView = state === 'fixed';
const views = BOARD_VIEW_COPY[family];

// Counted, not typed. This was hardcoded as "108 of 310 sources are marked
// 18+", which was true and would have gone quietly wrong the next time
Expand All @@ -36,44 +39,48 @@ const adult = SOURCES.filter((s) => s.nsfw).length;
// 41 languages is past Hick's-law territory for chips, so language is a select
// while the handful of causes stay as one-tap chips.
/* Two of the three open sorts mean nothing once a report is closed: "Longest
waiting" answers from created_at, which for a fixed report is how long ago it
was filed rather than how long anyone waited, and "Newest" is the same
question the fixed view already answers better. So the fixed view offers the
two orders it can honour, and the labels say which. */
const sorts = fixedView
? [
{ key: 'demand', label: 'Most wanted' },
{ key: 'fixed', label: 'Recently fixed' },
]
: [
{ key: 'demand', label: 'Most wanted' },
{ key: 'stalled', label: 'Longest waiting' },
{ key: 'recent', label: 'Newest' },
];
waiting" answers from created_at, which for a closed report is how long ago
it was filed rather than how long anyone waited, and "Newest" is the same
question the closed views already answer better. So both closed views offer
the two orders they can honour — the shared 'fixed' key labelled by what the
view actually shows. */
const sorts =
state === 'open'
? [
{ key: 'demand', label: 'Most wanted' },
{ key: 'stalled', label: 'Longest waiting' },
{ key: 'recent', label: 'Newest' },
]
: [
{ key: 'demand', label: 'Most wanted' },
{ key: 'fixed', label: state === 'other' ? 'Recently closed' : 'Recently fixed' },
];

// The sort that is actually in force, so exactly one chip reads as pressed —
// board() falls the other view's default back to its own, and a chip that
// disagreed with the list under it is worse than no chip at all.
const activeSort = fixedView
? sort === 'demand'
? 'demand'
: 'fixed'
: sort === 'fixed'
? 'demand'
: sort || 'demand';
const activeSort =
state === 'open'
? sort === 'fixed'
? 'demand'
: sort || 'demand'
: sort === 'demand'
? 'demand'
: 'fixed';

const states = [
{ key: 'open', label: 'Open', count: openCount },
{ key: 'fixed', label: 'Fixed', count: fixedCount },
];
const states = (['open', 'fixed', 'other'] as const).map((key) => ({
key,
label: views[key].chip,
count: key === 'open' ? openCount : key === 'fixed' ? fixedCount : otherCount,
}));
---

<form class="filters" method="get" role="search">
<div class="line primary">
{/* First control on the bar, because it decides what every other one
filters. Counts on the chips for the same reason the 18+ chip carries
one: "Fixed" alone does not say that 468 of these exist. */}
<div class="segmented states" role="group" aria-label="Open or fixed">
<div class="segmented states" role="group" aria-label="Open, fixed or other">
{
states.map((v) => (
<button
Expand Down Expand Up @@ -243,9 +250,21 @@ const states = [
.causes .chip { flex: none; }
.sorts { inline-size: 100%; }
.segmented .chip { flex: 1; text-align: center; }
/* Two chips carrying counts, beside the 18+ chip rather than across the
row: full width would make each half wide enough to look like a button
and cost the row the 18+ chip is on. */
/* Three chips carrying counts, beside the 18+ chip rather than across
their own row: full width would make each third wide enough to look like
a button and cost the row the 18+ chip is on. The three no longer fit
390px alongside it, so the group scrolls sideways instead of wrapping —
same treatment as .causes above, bleed and hidden scrollbar included. */
.states {
flex: 0 1 auto;
min-inline-size: 0;
flex-wrap: nowrap;
overflow-x: auto;
scrollbar-width: none;
margin-inline-start: calc(-1 * var(--space-4));
padding-inline-start: var(--space-4);
}
.states::-webkit-scrollbar { display: none; }
.states .chip { flex: none; }
}
</style>
Loading