Initial release 0.1.0
This commit is contained in:
commit
9f97d8407a
52 files changed
+6774
No files matched your search
@@ -0,0 +1,228 @@
|
||||
import { getDatabase } from './database.js';
|
||||
|
||||
export type PreviewPiece = {
|
||||
id: string;
|
||||
title: string;
|
||||
summary: string;
|
||||
status: 'inbox' | 'preparing' | 'ready' | 'archived';
|
||||
durationSeconds: number;
|
||||
format: string;
|
||||
category: string;
|
||||
categoryColor: string;
|
||||
topics: string[];
|
||||
sourceCount: number;
|
||||
};
|
||||
|
||||
export type PreviewUsage = {
|
||||
id: string;
|
||||
title: string;
|
||||
durationSeconds: number;
|
||||
status: 'open' | 'current' | 'done' | 'skipped';
|
||||
intro: string;
|
||||
moderation: string;
|
||||
transition: string;
|
||||
isReserve: boolean;
|
||||
};
|
||||
|
||||
export type PreviewSection = {
|
||||
id: string;
|
||||
name: string;
|
||||
category: string;
|
||||
categoryColor: string;
|
||||
durationSeconds: number;
|
||||
usages: PreviewUsage[];
|
||||
};
|
||||
|
||||
export type PreviewShow = {
|
||||
id: string;
|
||||
title: string;
|
||||
startsAtUtc: string;
|
||||
startsAtBerlin: string;
|
||||
twitchTitle: string;
|
||||
announcement: string;
|
||||
status: string;
|
||||
sections: PreviewSection[];
|
||||
totalDurationSeconds: number;
|
||||
};
|
||||
|
||||
type PieceRow = {
|
||||
id: string;
|
||||
title: string;
|
||||
summary: string;
|
||||
status: PreviewPiece['status'];
|
||||
duration_seconds: number;
|
||||
format: string;
|
||||
category: string | null;
|
||||
category_color: string | null;
|
||||
topics: string | null;
|
||||
source_count: number;
|
||||
};
|
||||
|
||||
export function getPieces(): PreviewPiece[] {
|
||||
const rows = getDatabase()
|
||||
.prepare(
|
||||
`SELECT
|
||||
p.id,
|
||||
p.title,
|
||||
p.summary,
|
||||
p.status,
|
||||
p.duration_seconds,
|
||||
COALESCE(f.name, 'Ohne Format') AS format,
|
||||
(
|
||||
SELECT c.name FROM piece_category_suggestions pcs
|
||||
JOIN section_categories c ON c.id = pcs.category_id
|
||||
WHERE pcs.piece_id = p.id ORDER BY c.sort_order LIMIT 1
|
||||
) AS category,
|
||||
(
|
||||
SELECT c.color FROM piece_category_suggestions pcs
|
||||
JOIN section_categories c ON c.id = pcs.category_id
|
||||
WHERE pcs.piece_id = p.id ORDER BY c.sort_order LIMIT 1
|
||||
) AS category_color,
|
||||
(
|
||||
SELECT group_concat(t.name, '||') FROM piece_topics pt
|
||||
JOIN topics t ON t.id = pt.topic_id WHERE pt.piece_id = p.id
|
||||
) AS topics,
|
||||
(SELECT count(*) FROM piece_sources ps WHERE ps.piece_id = p.id) AS source_count
|
||||
FROM pieces p
|
||||
LEFT JOIN formats f ON f.id = p.format_id
|
||||
WHERE p.status != 'archived'
|
||||
ORDER BY CASE p.status WHEN 'ready' THEN 0 ELSE 1 END, p.title`
|
||||
)
|
||||
.all() as PieceRow[];
|
||||
|
||||
return rows.map((row) => ({
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
summary: row.summary,
|
||||
status: row.status,
|
||||
durationSeconds: row.duration_seconds,
|
||||
format: row.format,
|
||||
category: row.category ?? 'Offen',
|
||||
categoryColor: row.category_color ?? '#8b8f98',
|
||||
topics: row.topics?.split('||') ?? [],
|
||||
sourceCount: row.source_count
|
||||
}));
|
||||
}
|
||||
|
||||
type ShowRow = {
|
||||
id: string;
|
||||
title: string;
|
||||
starts_at_utc: string;
|
||||
twitch_title: string;
|
||||
announcement_text: string;
|
||||
status: string;
|
||||
};
|
||||
|
||||
type SectionRow = {
|
||||
id: string;
|
||||
name: string;
|
||||
category: string | null;
|
||||
category_color: string | null;
|
||||
explicit_duration_seconds: number | null;
|
||||
};
|
||||
|
||||
type UsageRow = {
|
||||
id: string;
|
||||
show_section_id: string;
|
||||
title_snapshot: string;
|
||||
duration_seconds: number;
|
||||
status: PreviewUsage['status'];
|
||||
intro_snapshot: string;
|
||||
moderation_snapshot: string;
|
||||
transition_snapshot: string;
|
||||
is_reserve: number;
|
||||
};
|
||||
|
||||
export function getShow(): PreviewShow {
|
||||
const database = getDatabase();
|
||||
const show = database
|
||||
.prepare(
|
||||
`SELECT id, title, starts_at_utc, twitch_title, announcement_text, status
|
||||
FROM shows ORDER BY starts_at_utc DESC LIMIT 1`
|
||||
)
|
||||
.get() as ShowRow | undefined;
|
||||
|
||||
if (!show) throw new Error('No preview show found. Run npm run db:seed.');
|
||||
|
||||
const sectionRows = database
|
||||
.prepare(
|
||||
`SELECT s.id, s.name, c.name AS category, c.color AS category_color,
|
||||
s.explicit_duration_seconds
|
||||
FROM show_sections s
|
||||
LEFT JOIN section_categories c ON c.id = s.category_id
|
||||
WHERE s.show_id = ? ORDER BY s.position`
|
||||
)
|
||||
.all(show.id) as SectionRow[];
|
||||
const usageRows = database
|
||||
.prepare(
|
||||
`SELECT id, show_section_id, title_snapshot, duration_seconds, status,
|
||||
intro_snapshot, moderation_snapshot, transition_snapshot, is_reserve
|
||||
FROM piece_usages WHERE show_section_id IN (
|
||||
SELECT id FROM show_sections WHERE show_id = ?
|
||||
) ORDER BY position`
|
||||
)
|
||||
.all(show.id) as UsageRow[];
|
||||
|
||||
const sections = sectionRows.map((section) => {
|
||||
const usages = usageRows
|
||||
.filter((usage) => usage.show_section_id === section.id)
|
||||
.map((usage) => ({
|
||||
id: usage.id,
|
||||
title: usage.title_snapshot,
|
||||
durationSeconds: usage.duration_seconds,
|
||||
status: usage.status,
|
||||
intro: usage.intro_snapshot,
|
||||
moderation: usage.moderation_snapshot,
|
||||
transition: usage.transition_snapshot,
|
||||
isReserve: usage.is_reserve === 1
|
||||
}));
|
||||
const plannedUsages = usages.filter((usage) => !usage.isReserve);
|
||||
return {
|
||||
id: section.id,
|
||||
name: section.name,
|
||||
category: section.category ?? 'Offen',
|
||||
categoryColor: section.category_color ?? '#8b8f98',
|
||||
durationSeconds:
|
||||
section.explicit_duration_seconds ??
|
||||
plannedUsages.reduce((total, usage) => total + usage.durationSeconds, 0),
|
||||
usages
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
id: show.id,
|
||||
title: show.title,
|
||||
startsAtUtc: show.starts_at_utc,
|
||||
startsAtBerlin: new Intl.DateTimeFormat('de-DE', {
|
||||
timeZone: 'Europe/Berlin',
|
||||
weekday: 'short',
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}).format(new Date(show.starts_at_utc)),
|
||||
twitchTitle: show.twitch_title,
|
||||
announcement: show.announcement_text,
|
||||
status: show.status,
|
||||
sections,
|
||||
totalDurationSeconds: sections.reduce((total, section) => total + section.durationSeconds, 0)
|
||||
};
|
||||
}
|
||||
|
||||
export function getTaxonomy() {
|
||||
const database = getDatabase();
|
||||
return {
|
||||
categories: database
|
||||
.prepare('SELECT id, name, color FROM section_categories ORDER BY sort_order')
|
||||
.all() as { id: string; name: string; color: string }[],
|
||||
formats: database.prepare('SELECT id, name FROM formats ORDER BY name').all() as {
|
||||
id: string;
|
||||
name: string;
|
||||
}[],
|
||||
topics: database.prepare('SELECT id, name FROM topics ORDER BY name').all() as {
|
||||
id: string;
|
||||
name: string;
|
||||
}[]
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user