add types

This commit is contained in:
2026-03-15 14:50:56 +01:00
parent 347438928a
commit 4d8f7c2b02
12 changed files with 183 additions and 144 deletions
+45
View File
@@ -0,0 +1,45 @@
import { Database } from 'bun:sqlite';
import type { Stream, StreamSummary } from './types.js';
const dbName = './db/strimserve.db';
// Create a new database object and initialize it with the schema
const db = new Database(dbName);
export function getStreams(): StreamSummary[] {
const indexData = db
.prepare(
'SELECT id, stream_date, title, tags, length_seconds ' + 'FROM Stream ORDER BY id DESC'
)
.all() as Record<string, unknown>[];
return indexData.map((stream) => ({
id: stream.id as string,
stream_date: Date.parse(stream.stream_date as string),
title: stream.title as string | null,
tags: JSON.parse(stream.tags as string) as string[],
length_seconds: stream.length_seconds as number
}));
}
export function getStreamInfo(streamId: string): Stream | null {
const streamData = db
.prepare(
'SELECT id, stream_date, filename, ' +
'format, title, description, tags, ' +
'length_seconds, tracks FROM Stream ' +
'WHERE id = ?'
)
.get(streamId) as Record<string, unknown> | null;
if (!streamData) return null;
return {
id: streamData.id as string,
stream_date: Date.parse(streamData.stream_date as string),
filename: streamData.filename as string,
format: streamData.format as string,
title: streamData.title as string | null,
description: streamData.description as string | null,
tags: JSON.parse(streamData.tags as string) as string[],
length_seconds: streamData.length_seconds as number,
tracks: JSON.parse(streamData.tracks as string)
};
}