initial commit
This commit is contained in:
59
src/routes/streams/[stream_id]/+page.server.ts
Normal file
59
src/routes/streams/[stream_id]/+page.server.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import fs from 'fs';
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { getStreamInfo } from "$lib/database.js";
|
||||
import { dev } from "$app/environment";
|
||||
|
||||
let getOriginalJson, writeSideloadJson;
|
||||
export let actions;
|
||||
|
||||
// utilities for manipulating original stream JSONs
|
||||
if (dev) {
|
||||
const jsonFolder = './db/stream_json/';
|
||||
|
||||
getOriginalJson = function (streamId) {
|
||||
const filePath = jsonFolder + streamId + ".sideload.json";
|
||||
if (fs.existsSync(filePath)) {
|
||||
const jsonString = fs.readFileSync(filePath, 'utf8');
|
||||
return jsonString;
|
||||
} else {
|
||||
return JSON.stringify({ 'title': '', 'description': '', 'tags': [] });
|
||||
}
|
||||
}
|
||||
|
||||
writeSideloadJson = function (streamId, newJson) {
|
||||
const filePath = jsonFolder + streamId + ".sideload.json";
|
||||
fs.writeFileSync(filePath, JSON.stringify(newJson), 'utf8');
|
||||
}
|
||||
|
||||
actions = {
|
||||
default: async ({ params, request }) => {
|
||||
const data = await request.formData();
|
||||
// let newJson = JSON.parse(getOriginalJson(params.stream_id));
|
||||
let newJson = {};
|
||||
newJson['title'] = data.get('title');
|
||||
newJson['description'] = data.get('description');
|
||||
newJson['tags'] = data.getAll('tags');
|
||||
writeSideloadJson(params.stream_id, newJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function load({ params }) {
|
||||
const result = getStreamInfo(params.stream_id);
|
||||
if (result === null) {
|
||||
throw error(404);
|
||||
}
|
||||
|
||||
if (dev) {
|
||||
// pass raw JSON for metadata editor
|
||||
let original = JSON.parse(getOriginalJson(params.stream_id));
|
||||
return {
|
||||
stream: result,
|
||||
original: original
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
stream: result
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user