Release 0.5.9
This commit is contained in:
1 parent
2851c7d936
commit
c3033479b5
32 files changed
+1598
-50
No files matched your search
+233
-3
@@ -60,6 +60,16 @@ export type PieceUsage = {
|
||||
presentationProvider: string;
|
||||
presentationProviderId: string;
|
||||
ownNotes: string;
|
||||
sources: { id: string; label: string; url: string; timecodeSeconds: number | null }[];
|
||||
tools: {
|
||||
id: string;
|
||||
originalToolId: string | null;
|
||||
name: string;
|
||||
startUrl: string;
|
||||
workUrl: string;
|
||||
note: string;
|
||||
}[];
|
||||
topics: string[];
|
||||
};
|
||||
|
||||
export type SentPieceUsage = {
|
||||
@@ -147,6 +157,7 @@ export type PieceUsageUpdate = {
|
||||
presentationSiteName: string;
|
||||
ownNotes: string;
|
||||
durationSeconds: number;
|
||||
tools?: { id: string; workUrl: string; note: string }[];
|
||||
};
|
||||
|
||||
export type MovePieceUsageInput = {
|
||||
@@ -372,7 +383,7 @@ function normalizePositions(
|
||||
ids.forEach((id, position) => update.run(position, id));
|
||||
}
|
||||
|
||||
function usageFromRow(row: UsageRow): PieceUsage {
|
||||
function usageFromRow(database: Database.Database, row: UsageRow): PieceUsage {
|
||||
return {
|
||||
id: row.id,
|
||||
originalPieceId: row.original_piece_id,
|
||||
@@ -396,10 +407,189 @@ function usageFromRow(row: UsageRow): PieceUsage {
|
||||
presentationSiteName: row.presentation_site_name_snapshot,
|
||||
presentationProvider: row.presentation_provider_snapshot,
|
||||
presentationProviderId: row.presentation_provider_id_snapshot,
|
||||
ownNotes: row.own_notes
|
||||
ownNotes: row.own_notes,
|
||||
sources: (
|
||||
database
|
||||
.prepare(
|
||||
`SELECT id, label, url, timecode_seconds FROM usage_source_snapshots
|
||||
WHERE usage_id = ? ORDER BY position`
|
||||
)
|
||||
.all(row.id) as {
|
||||
id: string;
|
||||
label: string;
|
||||
url: string;
|
||||
timecode_seconds: number | null;
|
||||
}[]
|
||||
).map((source) => ({
|
||||
id: source.id,
|
||||
label: source.label,
|
||||
url: source.url,
|
||||
timecodeSeconds: source.timecode_seconds
|
||||
})),
|
||||
tools: (
|
||||
database
|
||||
.prepare(
|
||||
`SELECT id, original_tool_id, name, start_url, work_url, note
|
||||
FROM usage_tool_snapshots WHERE usage_id = ? ORDER BY position`
|
||||
)
|
||||
.all(row.id) as {
|
||||
id: string;
|
||||
original_tool_id: string | null;
|
||||
name: string;
|
||||
start_url: string;
|
||||
work_url: string;
|
||||
note: string;
|
||||
}[]
|
||||
).map((tool) => ({
|
||||
id: tool.id,
|
||||
originalToolId: tool.original_tool_id,
|
||||
name: tool.name,
|
||||
startUrl: tool.start_url,
|
||||
workUrl: tool.work_url,
|
||||
note: tool.note
|
||||
})),
|
||||
topics: (
|
||||
database
|
||||
.prepare('SELECT name FROM usage_topic_snapshots WHERE usage_id = ? ORDER BY position')
|
||||
.all(row.id) as { name: string }[]
|
||||
).map((topic) => topic.name)
|
||||
};
|
||||
}
|
||||
|
||||
function snapshotPieceRelations(database: Database.Database, usageId: string, pieceId: string) {
|
||||
database.prepare('DELETE FROM usage_source_snapshots WHERE usage_id = ?').run(usageId);
|
||||
database.prepare('DELETE FROM usage_tool_snapshots WHERE usage_id = ?').run(usageId);
|
||||
database.prepare('DELETE FROM usage_topic_snapshots WHERE usage_id = ?').run(usageId);
|
||||
const sources = database
|
||||
.prepare(
|
||||
`SELECT label, url, timecode_seconds, position FROM piece_sources
|
||||
WHERE piece_id = ? ORDER BY position`
|
||||
)
|
||||
.all(pieceId) as {
|
||||
label: string;
|
||||
url: string;
|
||||
timecode_seconds: number | null;
|
||||
position: number;
|
||||
}[];
|
||||
const addSource = database.prepare(
|
||||
`INSERT INTO usage_source_snapshots (id, usage_id, label, url, timecode_seconds, position)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const source of sources) {
|
||||
addSource.run(
|
||||
randomUUID(),
|
||||
usageId,
|
||||
source.label,
|
||||
source.url,
|
||||
source.timecode_seconds,
|
||||
source.position
|
||||
);
|
||||
}
|
||||
const tools = database
|
||||
.prepare(
|
||||
`SELECT pt.tool_id, t.name, t.start_url, pt.work_url, pt.note, pt.position
|
||||
FROM piece_tools pt JOIN tools t ON t.id = pt.tool_id
|
||||
WHERE pt.piece_id = ? ORDER BY pt.position`
|
||||
)
|
||||
.all(pieceId) as {
|
||||
tool_id: string;
|
||||
name: string;
|
||||
start_url: string;
|
||||
work_url: string;
|
||||
note: string;
|
||||
position: number;
|
||||
}[];
|
||||
const addTool = database.prepare(
|
||||
`INSERT INTO usage_tool_snapshots
|
||||
(id, usage_id, original_tool_id, name, start_url, work_url, note, position)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const tool of tools) {
|
||||
addTool.run(
|
||||
randomUUID(),
|
||||
usageId,
|
||||
tool.tool_id,
|
||||
tool.name,
|
||||
tool.start_url,
|
||||
tool.work_url,
|
||||
tool.note,
|
||||
tool.position
|
||||
);
|
||||
}
|
||||
const topics = database
|
||||
.prepare(
|
||||
`SELECT t.name FROM piece_topics pt JOIN topics t ON t.id = pt.topic_id
|
||||
WHERE pt.piece_id = ? ORDER BY t.name, t.id`
|
||||
)
|
||||
.all(pieceId) as { name: string }[];
|
||||
const addTopic = database.prepare(
|
||||
'INSERT INTO usage_topic_snapshots (usage_id, name, position) VALUES (?, ?, ?)'
|
||||
);
|
||||
topics.forEach((topic, position) => addTopic.run(usageId, topic.name, position));
|
||||
}
|
||||
|
||||
function copyUsageRelations(database: Database.Database, sourceUsageId: string, usageId: string) {
|
||||
const sources = database
|
||||
.prepare(
|
||||
`SELECT label, url, timecode_seconds, position FROM usage_source_snapshots
|
||||
WHERE usage_id = ? ORDER BY position`
|
||||
)
|
||||
.all(sourceUsageId) as {
|
||||
label: string;
|
||||
url: string;
|
||||
timecode_seconds: number | null;
|
||||
position: number;
|
||||
}[];
|
||||
const addSource = database.prepare(
|
||||
`INSERT INTO usage_source_snapshots (id, usage_id, label, url, timecode_seconds, position)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const source of sources)
|
||||
addSource.run(
|
||||
randomUUID(),
|
||||
usageId,
|
||||
source.label,
|
||||
source.url,
|
||||
source.timecode_seconds,
|
||||
source.position
|
||||
);
|
||||
const tools = database
|
||||
.prepare(
|
||||
`SELECT original_tool_id, name, start_url, work_url, note, position
|
||||
FROM usage_tool_snapshots WHERE usage_id = ? ORDER BY position`
|
||||
)
|
||||
.all(sourceUsageId) as {
|
||||
original_tool_id: string | null;
|
||||
name: string;
|
||||
start_url: string;
|
||||
work_url: string;
|
||||
note: string;
|
||||
position: number;
|
||||
}[];
|
||||
const addTool = database.prepare(
|
||||
`INSERT INTO usage_tool_snapshots
|
||||
(id, usage_id, original_tool_id, name, start_url, work_url, note, position)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const tool of tools)
|
||||
addTool.run(
|
||||
randomUUID(),
|
||||
usageId,
|
||||
tool.original_tool_id,
|
||||
tool.name,
|
||||
tool.start_url,
|
||||
tool.work_url,
|
||||
tool.note,
|
||||
tool.position
|
||||
);
|
||||
database
|
||||
.prepare(
|
||||
`INSERT INTO usage_topic_snapshots (usage_id, name, position)
|
||||
SELECT ?, name, position FROM usage_topic_snapshots WHERE usage_id = ?`
|
||||
)
|
||||
.run(usageId, sourceUsageId);
|
||||
}
|
||||
|
||||
export function listShows(): ShowListItem[] {
|
||||
return (
|
||||
getDatabase()
|
||||
@@ -497,7 +687,7 @@ export function getShow(id: string): Show | null {
|
||||
const usagesBySection = new Map<string, PieceUsage[]>();
|
||||
for (const row of usageRows) {
|
||||
const usages = usagesBySection.get(row.show_section_id) ?? [];
|
||||
usages.push(usageFromRow(row));
|
||||
usages.push(usageFromRow(database, row));
|
||||
usagesBySection.set(row.show_section_id, usages);
|
||||
}
|
||||
const sections = sectionRows
|
||||
@@ -889,6 +1079,7 @@ export function addPieceUsage(
|
||||
piece.presentation_provider_id,
|
||||
input.sectionId === null ? 1 : 0
|
||||
);
|
||||
snapshotPieceRelations(database, id, input.pieceId);
|
||||
ids.splice(position, 0, id);
|
||||
normalizePositions(database, 'piece_usages', ids);
|
||||
return { ...result, id };
|
||||
@@ -1018,6 +1209,7 @@ export function duplicatePieceUsage(
|
||||
source.own_notes,
|
||||
source.is_reserve
|
||||
);
|
||||
copyUsageRelations(database, usageId, id);
|
||||
ids.splice(sourcePosition + 1, 0, id);
|
||||
normalizePositions(database, 'piece_usages', ids);
|
||||
return { ...result, id };
|
||||
@@ -1102,6 +1294,15 @@ export function refreshPieceUsageFromOriginal(
|
||||
source.presentation_provider_id,
|
||||
usageId
|
||||
);
|
||||
snapshotPieceRelations(
|
||||
database,
|
||||
usageId,
|
||||
(
|
||||
database
|
||||
.prepare('SELECT original_piece_id FROM piece_usages WHERE id = ?')
|
||||
.get(usageId) as { original_piece_id: string }
|
||||
).original_piece_id
|
||||
);
|
||||
return result;
|
||||
})();
|
||||
}
|
||||
@@ -1170,6 +1371,35 @@ export function updatePieceUsage(
|
||||
duration,
|
||||
usageId
|
||||
);
|
||||
if (input.tools) {
|
||||
const existing = database
|
||||
.prepare('SELECT id FROM usage_tool_snapshots WHERE usage_id = ?')
|
||||
.all(usageId) as { id: string }[];
|
||||
const existingIds = new Set(existing.map((tool) => tool.id));
|
||||
if (
|
||||
input.tools.length !== existing.length ||
|
||||
input.tools.some((tool) => !existingIds.has(tool.id))
|
||||
) {
|
||||
throw new Error('INVALID_TOOLS');
|
||||
}
|
||||
const updateTool = database.prepare(
|
||||
'UPDATE usage_tool_snapshots SET work_url = ?, note = ? WHERE id = ? AND usage_id = ?'
|
||||
);
|
||||
for (const tool of input.tools) {
|
||||
const workUrl = cleanText(tool.workUrl, 2_000, 'tools');
|
||||
if (workUrl) {
|
||||
try {
|
||||
const url = new URL(workUrl);
|
||||
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) {
|
||||
throw new Error();
|
||||
}
|
||||
} catch {
|
||||
throw new Error('INVALID_TOOLS');
|
||||
}
|
||||
}
|
||||
updateTool.run(workUrl, cleanText(tool.note, 2_000, 'tools'), tool.id, usageId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user