better handling all around for files and symlinks
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -8,4 +8,4 @@ node_modules
|
||||
!.env.example
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
/static/files/*
|
||||
/static/media/*
|
||||
|
||||
@@ -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
1
db/.gitignore
vendored
@@ -1,2 +1 @@
|
||||
strimserve.db
|
||||
stream_json
|
||||
|
||||
@@ -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
2
env.tpl
Normal file
@@ -0,0 +1,2 @@
|
||||
STREAM_JSON_LOCATION=/data/streams/json
|
||||
STREAM_MEDIA_LOCATION=/data/streams/media
|
||||
294
package-lock.json
generated
294
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@@ -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
1
public/favicon.png
Symbolic link
@@ -0,0 +1 @@
|
||||
../static/favicon.png
|
||||
1
public/fonts
Symbolic link
1
public/fonts
Symbolic link
@@ -0,0 +1 @@
|
||||
../static/fonts
|
||||
12
scripts/create_media_symlink.js
Normal file
12
scripts/create_media_symlink.js
Normal 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}`);
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//import adapter from 'svelte-adapter-bun';
|
||||
import adapter from '@sveltejs/adapter-node';
|
||||
import { vitePreprocess } from '@sveltejs/kit/vite';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user