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

2
.gitignore vendored
View File

@@ -8,4 +8,4 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/static/files/*
/static/media/*

View File

@@ -9,6 +9,8 @@ Also useful: fonttools (regenerating icon font if necessary)
npm install
```
Copy `.env` to `env.tpl` and insert the correct folder locations
## running dev server
```bash
npm run dev

1
db/.gitignore vendored
View File

@@ -1,2 +1 @@
strimserve.db
stream_json

View File

@@ -1,7 +1,10 @@
import fs from 'fs';
import path from 'path';
import Database from 'better-sqlite3';
import dotenv from 'dotenv';
const jsonFolder = './stream_json/';
dotenv.config({ path: '../.env' });
const jsonFolder = path.resolve(process.env.STREAM_JSON_LOCATION);
const dbName = 'strimserve.db';
const db = new Database(dbName);
@@ -36,10 +39,10 @@ fs.readdir(jsonFolder, (err, files) => {
if (!file.endsWith('.json')) return;
if (file.endsWith('.sideload.json')) return;
const jsonString = fs.readFileSync(jsonFolder + file, 'utf8');
const jsonString = fs.readFileSync(path.join(jsonFolder, file), 'utf8');
let jsonData = JSON.parse(jsonString);
const sideloadPath = jsonFolder + file.slice(0, -5) + ".sideload.json";
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 };

2
env.tpl Normal file
View File

@@ -0,0 +1,2 @@
STREAM_JSON_LOCATION=/data/streams/json
STREAM_MEDIA_LOCATION=/data/streams/media

294
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "vite build && node ./scripts/create_media_symlink.js",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
@@ -14,7 +14,7 @@
"update_db": "cd db && node ./update_db.js",
"generate_iconfont_subset": "cd scripts && bash ./generate_iconfont_subset.sh"
},
"devDependencies": {
"dependencies": {
"@sveltejs/adapter-node": "^1.2.3",
"@sveltejs/kit": "^1.5.0",
"@types/better-sqlite3": "^7.6.4",
@@ -22,8 +22,10 @@
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"better-sqlite3": "^8.3.0",
"dotenv": "^16.3.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.31.0",
"fontkit": "^2.0.2",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
@@ -34,8 +36,5 @@
"typescript": "^5.0.0",
"vite": "^4.2.0"
},
"type": "module",
"dependencies": {
"eslint-plugin-svelte": "^2.31.0"
}
"type": "module"
}

1
public/favicon.png Symbolic link
View File

@@ -0,0 +1 @@
../static/favicon.png

1
public/fonts Symbolic link
View File

@@ -0,0 +1 @@
../static/fonts

View File

@@ -0,0 +1,12 @@
import fs from 'fs';
import 'dotenv/config';
import { symlinkSync } from 'fs';
const target = process.env.STREAM_MEDIA_LOCATION;
const linkName = './build/client/media';
try {
symlinkSync(target, linkName);
console.log(`Symlink created: ${linkName} -> ${target}`);
} catch (err) {
console.error(`Error creating symlink: ${err}`);
}

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');
}

View File

@@ -18,7 +18,7 @@
<StreamPage />
</div>
<div id="player">
<Player display={true} src="/files/tracks/{$currentStream.filename}" />
<Player display={true} src="/media/tracks/{$currentStream.filename}" />
</div>
</div>

View File

@@ -27,7 +27,7 @@
export let paused = true;
export let duration = 0;
export let muted = false;
export let volume = 1;
export let volume = 0.67;
export let preload = 'metadata';
export let iconColor = 'gray';
export let textColor = 'gray';
@@ -56,7 +56,7 @@
onMount(async () => {
const volumeData = localStorage.getItem('volume');
volume = volumeData ? parseFloat(volumeData) : 1;
volume = volumeData ? parseFloat(volumeData) : 0.67;
});
$: updateCurrentSong(currentTime, $currentSongIndex);

View File

@@ -1,3 +1,4 @@
//import adapter from 'svelte-adapter-bun';
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/kit/vite';