Refactor code structure for improved readability and maintainability
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 288 KiB |
File diff suppressed because it is too large
Load Diff
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user