Refactor code structure for improved readability and maintainability

This commit is contained in:
2025-10-19 22:08:17 +02:00
parent bec0a3b72f
commit 445f522fa8
11 changed files with 2242 additions and 2182 deletions

View File

@@ -11,4 +11,11 @@ data/*
*.wav
*.m4a
*.ogg
*.flac
*.flac
**/data/*.mp3
**/data/*.wav
**/data/*.m4a
**/data/*.opus
**/data/*.ogg
**/data/*.flac

View File

@@ -165,6 +165,7 @@ jobs:
echo "Building $IMAGE_FULL with tags: $TAG_ARGS"
docker buildx build \
--platform linux/amd64 \
--target production \
-f "$DOCKERFILE" \
$TAG_ARGS \
--cache-from type=registry,ref="$IMAGE_FULL:buildcache" \

View File

@@ -1,23 +1,52 @@
# Lightweight production image for the Hitstar Node app
FROM node:22-alpine
# Multi-stage Dockerfile for Hitstar Deno Server
# Supports both development and production environments
# Base stage with common dependencies
FROM denoland/deno:latest AS base
WORKDIR /app
# Install dependencies
COPY package*.json ./
# Use npm ci when a lockfile is present, otherwise fallback to npm install without throwing an error
RUN if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then \
npm ci --omit=dev; \
else \
npm install --omit=dev; \
fi
# Copy all source files first for dependency resolution
COPY src/server-deno/ .
# Copy app source (media lives outside via volume)
COPY . .
# Cache all dependencies based on deno.json imports
RUN deno cache main.ts
ENV NODE_ENV=production \
# Development stage
FROM base AS development
ENV DENO_ENV=development \
PORT=5173
EXPOSE 5173
CMD ["node", "src/server/index.js", "--host", "0.0.0.0"]
# Copy all source files
COPY src/server-deno/ .
# Run with watch mode and all necessary permissions
CMD ["deno", "run", \
"--allow-net", \
"--allow-read", \
"--allow-env", \
"--allow-write", \
"--watch", \
"main.ts"]
# Production stage
FROM base AS production
ENV DENO_ENV=production \
PORT=5173
EXPOSE 5173
# Copy only necessary source files for production
COPY src/server-deno/ .
# Run optimized production server
CMD ["deno", "run", \
"--allow-net", \
"--allow-read=/app/data,/app/public", \
"--allow-env", \
"--allow-write=/app/data", \
"main.ts"]

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,24 @@
services:
# Production service
hitstar:
build: .
image: hitstar-webapp:latest
build:
context: .
dockerfile: Dockerfile
target: production
image: hitstar-deno:prod
container_name: hitstar
environment:
- NODE_ENV=production
- DENO_ENV=production
- PORT=5173
ports:
- "5173:5173"
volumes:
- ./data:/app/data:rw
restart: unless-stopped
- ./data:/app/data:ro
- ./src/server-deno/public:/app/public:ro
restart: unless-stopped
networks:
- hitstar-network
networks:
hitstar-network:
driver: bridge

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 KiB

View File

@@ -204,7 +204,9 @@ export class AudioStreamingService {
* Set common caching headers
*/
private setCommonHeaders(ctx: Context): void {
ctx.response.headers.set('Cache-Control', 'no-store');
// Allow caching of audio content to prevent redundant range requests
// The token system already provides security
ctx.response.headers.set('Cache-Control', 'public, max-age=3600');
ctx.response.headers.set('Accept-Ranges', 'bytes');
}
}

View File

@@ -51,6 +51,7 @@ export class HttpServer {
ctx.response.headers.set('Access-Control-Allow-Origin', this.config.corsOrigin);
ctx.response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
ctx.response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Range');
ctx.response.headers.set('Access-Control-Expose-Headers', 'Content-Range, Content-Length, Accept-Ranges');
if (ctx.request.method === 'OPTIONS') {
ctx.response.status = 204;

View File

@@ -79,6 +79,13 @@ export function handlePlayTrack(msg) {
try {
$audio.preload = 'auto';
} catch {}
// Reset audio state before setting new source
try {
$audio.pause();
$audio.currentTime = 0;
} catch {}
$audio.src = t.url;
const pf = document.getElementById('progressFill');
if (pf) pf.style.width = '0%';
@@ -93,7 +100,7 @@ export function handlePlayTrack(msg) {
const localStart = now + offsetMs;
const delay = Math.max(0, localStart - now);
setTimeout(() => {
$audio.currentTime = 0;
// Don't reset currentTime again - it's already 0 from above
$audio.play().catch(() => {});
const disc = document.getElementById('recordDisc');
if (disc) disc.classList.add('spin-record');

File diff suppressed because it is too large Load Diff