svelte5 migration, formatting cleanup

This commit is contained in:
2025-02-11 13:13:17 +01:00
parent 44875efa7e
commit b5a740c302
32 changed files with 5782 additions and 1374 deletions

View File

@@ -11,15 +11,15 @@ const db = new Database(dbName);
// Map JSON attribute names to database column names
// Not needed today, but makes schema changes easier
const lookup = {
id: 'id',
date: 'stream_date',
filename: 'filename',
format: 'format',
title: 'title',
tags: 'tags',
description: 'description',
length_seconds: 'length_seconds',
tracks: 'tracks'
id: 'id',
date: 'stream_date',
filename: 'filename',
format: 'format',
title: 'title',
tags: 'tags',
description: 'description',
length_seconds: 'length_seconds',
tracks: 'tracks'
};
// Retrieve existing IDs from Stream
@@ -32,40 +32,39 @@ const shouldOverwrite = process.argv.includes('--overwrite');
// Process JSON files and insert data into Stream
fs.readdir(jsonFolder, (err, files) => {
if (err) throw err;
console.log(`Found ${files.length} JSON file(s) in ${jsonFolder}.`);
if (err) throw err;
console.log(`Found ${files.length} JSON file(s) in ${jsonFolder}.`);
files.forEach(file => {
if (!file.endsWith('.json')) return;
if (file.endsWith('.sideload.json')) return;
files.forEach((file) => {
if (!file.endsWith('.json')) return;
if (file.endsWith('.sideload.json')) return;
const jsonString = fs.readFileSync(path.join(jsonFolder, file), 'utf8');
let jsonData = JSON.parse(jsonString);
const jsonString = fs.readFileSync(path.join(jsonFolder, file), 'utf8');
let jsonData = JSON.parse(jsonString);
const sideloadPath = path.join(jsonFolder, file.slice(0, -5) + ".sideload.json");
if (fs.existsSync(sideloadPath, 'utf8')) {
const sideloadData = JSON.parse(fs.readFileSync(sideloadPath));
jsonData = { ...jsonData, ...sideloadData };
}
// Skip if ID already exists in Stream
if (idSet.has(jsonData.id)) {
if (!shouldOverwrite) {
console.log(`Skipped data for ID ${jsonData.id} (already exists).`);
return;
}
console.log(`Overwriting data for ID ${jsonData.id}.`);
}
const sideloadPath = path.join(jsonFolder, file.slice(0, -5) + '.sideload.json');
if (fs.existsSync(sideloadPath, 'utf8')) {
const sideloadData = JSON.parse(fs.readFileSync(sideloadPath));
jsonData = { ...jsonData, ...sideloadData };
}
// Skip if ID already exists in Stream
if (idSet.has(jsonData.id)) {
if (!shouldOverwrite) {
console.log(`Skipped data for ID ${jsonData.id} (already exists).`);
return;
}
console.log(`Overwriting data for ID ${jsonData.id}.`);
}
// Prepare attributes for insertion
const values = Object.keys(jsonData).map(
// Serialize value if array
key => Array.isArray(jsonData[key]) ? JSON.stringify(jsonData[key]) : jsonData[key]
);
const columns = Object.keys(jsonData).map(key => lookup[key]);
// Prepare attributes for insertion
const values = Object.keys(jsonData).map(
// Serialize value if array
(key) => (Array.isArray(jsonData[key]) ? JSON.stringify(jsonData[key]) : jsonData[key])
);
const columns = Object.keys(jsonData).map((key) => lookup[key]);
const sql = `INSERT OR REPLACE INTO Stream (${columns.join(', ')}) VALUES (${columns.map(() => '?').join(', ')})`;
db.prepare(sql).run(...values);
console.log(`Inserted data for ID ${jsonData.id}.`);
});
const sql = `INSERT OR REPLACE INTO Stream (${columns.join(', ')}) VALUES (${columns.map(() => '?').join(', ')})`;
db.prepare(sql).run(...values);
console.log(`Inserted data for ID ${jsonData.id}.`);
});
});