Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -11,4 +11,11 @@ data/*
|
|||||||
*.wav
|
*.wav
|
||||||
*.m4a
|
*.m4a
|
||||||
*.ogg
|
*.ogg
|
||||||
*.flac
|
*.flac
|
||||||
|
|
||||||
|
**/data/*.mp3
|
||||||
|
**/data/*.wav
|
||||||
|
**/data/*.m4a
|
||||||
|
**/data/*.opus
|
||||||
|
**/data/*.ogg
|
||||||
|
**/data/*.flac
|
||||||
@@ -165,6 +165,7 @@ jobs:
|
|||||||
echo "Building $IMAGE_FULL with tags: $TAG_ARGS"
|
echo "Building $IMAGE_FULL with tags: $TAG_ARGS"
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
|
--target production \
|
||||||
-f "$DOCKERFILE" \
|
-f "$DOCKERFILE" \
|
||||||
$TAG_ARGS \
|
$TAG_ARGS \
|
||||||
--cache-from type=registry,ref="$IMAGE_FULL:buildcache" \
|
--cache-from type=registry,ref="$IMAGE_FULL:buildcache" \
|
||||||
|
|||||||
57
Dockerfile
57
Dockerfile
@@ -1,23 +1,52 @@
|
|||||||
# Lightweight production image for the Hitstar Node app
|
# Multi-stage Dockerfile for Hitstar Deno Server
|
||||||
FROM node:22-alpine
|
# Supports both development and production environments
|
||||||
|
|
||||||
|
# Base stage with common dependencies
|
||||||
|
FROM denoland/deno:latest AS base
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies
|
# Copy all source files first for dependency resolution
|
||||||
COPY package*.json ./
|
COPY src/server-deno/ .
|
||||||
# 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 app source (media lives outside via volume)
|
# Cache all dependencies based on deno.json imports
|
||||||
COPY . .
|
RUN deno cache main.ts
|
||||||
|
|
||||||
ENV NODE_ENV=production \
|
# Development stage
|
||||||
|
FROM base AS development
|
||||||
|
|
||||||
|
ENV DENO_ENV=development \
|
||||||
PORT=5173
|
PORT=5173
|
||||||
|
|
||||||
EXPOSE 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"]
|
||||||
|
|||||||
2162
data/hitster_default/years.json
Normal file
2162
data/hitster_default/years.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,24 @@
|
|||||||
services:
|
services:
|
||||||
|
# Production service
|
||||||
hitstar:
|
hitstar:
|
||||||
build: .
|
build:
|
||||||
image: hitstar-webapp:latest
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
target: production
|
||||||
|
image: hitstar-deno:prod
|
||||||
container_name: hitstar
|
container_name: hitstar
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- DENO_ENV=production
|
||||||
- PORT=5173
|
- PORT=5173
|
||||||
ports:
|
ports:
|
||||||
- "5173:5173"
|
- "5173:5173"
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/app/data:rw
|
- ./data:/app/data:ro
|
||||||
restart: unless-stopped
|
- ./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 |
@@ -204,7 +204,9 @@ export class AudioStreamingService {
|
|||||||
* Set common caching headers
|
* Set common caching headers
|
||||||
*/
|
*/
|
||||||
private setCommonHeaders(ctx: Context): void {
|
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');
|
ctx.response.headers.set('Accept-Ranges', 'bytes');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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-Origin', this.config.corsOrigin);
|
||||||
ctx.response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
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-Allow-Headers', 'Content-Type, Range');
|
||||||
|
ctx.response.headers.set('Access-Control-Expose-Headers', 'Content-Range, Content-Length, Accept-Ranges');
|
||||||
|
|
||||||
if (ctx.request.method === 'OPTIONS') {
|
if (ctx.request.method === 'OPTIONS') {
|
||||||
ctx.response.status = 204;
|
ctx.response.status = 204;
|
||||||
|
|||||||
@@ -79,6 +79,13 @@ export function handlePlayTrack(msg) {
|
|||||||
try {
|
try {
|
||||||
$audio.preload = 'auto';
|
$audio.preload = 'auto';
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
|
// Reset audio state before setting new source
|
||||||
|
try {
|
||||||
|
$audio.pause();
|
||||||
|
$audio.currentTime = 0;
|
||||||
|
} catch {}
|
||||||
|
|
||||||
$audio.src = t.url;
|
$audio.src = t.url;
|
||||||
const pf = document.getElementById('progressFill');
|
const pf = document.getElementById('progressFill');
|
||||||
if (pf) pf.style.width = '0%';
|
if (pf) pf.style.width = '0%';
|
||||||
@@ -93,7 +100,7 @@ export function handlePlayTrack(msg) {
|
|||||||
const localStart = now + offsetMs;
|
const localStart = now + offsetMs;
|
||||||
const delay = Math.max(0, localStart - now);
|
const delay = Math.max(0, localStart - now);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$audio.currentTime = 0;
|
// Don't reset currentTime again - it's already 0 from above
|
||||||
$audio.play().catch(() => {});
|
$audio.play().catch(() => {});
|
||||||
const disc = document.getElementById('recordDisc');
|
const disc = document.getElementById('recordDisc');
|
||||||
if (disc) disc.classList.add('spin-record');
|
if (disc) disc.classList.add('spin-record');
|
||||||
|
|||||||
2160
tmp_tracks.json
2160
tmp_tracks.json
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user