better handling all around for files and symlinks

This commit is contained in:
2023-10-17 23:09:36 +02:00
parent 5bee1b6382
commit d8ca28f2ff
14 changed files with 90 additions and 260 deletions

View File

@@ -1,17 +1,19 @@
import fs from 'fs';
import path from 'path';
import { error } from "@sveltejs/kit";
import { getStreamInfo } from "$lib/database.js";
import { dev } from "$app/environment";
import { STREAM_JSON_LOCATION } from '$env/static/private';
let getOriginalJson, writeSideloadJson;
export let actions;
// utilities for manipulating original stream JSONs
if (dev) {
const jsonFolder = './db/stream_json/';
const jsonFolder = path.resolve(STREAM_JSON_LOCATION);
getOriginalJson = function (streamId) {
const filePath = jsonFolder + streamId + ".sideload.json";
const filePath = path.join(jsonFolder, streamId + ".sideload.json");
if (fs.existsSync(filePath)) {
const jsonString = fs.readFileSync(filePath, 'utf8');
return jsonString;
@@ -21,7 +23,7 @@ if (dev) {
}
writeSideloadJson = function (streamId, newJson) {
const filePath = jsonFolder + streamId + ".sideload.json";
const filePath = path.join(jsonFolder, streamId + ".sideload.json");
fs.writeFileSync(filePath, JSON.stringify(newJson), 'utf8');
}