From 9eb09c421aff4fbab3eded71826ed4a8b1694384 Mon Sep 17 00:00:00 2001 From: enki Date: Thu, 28 Aug 2025 08:07:13 -0700 Subject: [PATCH] more fuckingfixes --- internal/api/handlers.go | 14 +++++++++++++- internal/web/static/upload.js | 22 +++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/internal/api/handlers.go b/internal/api/handlers.go index adbb115..f213cec 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -1504,8 +1504,17 @@ func (g *Gateway) getMetadata(fileHash string) (*FileMetadata, error) { Chunks: chunks, } + // Check in-memory store for additional data (TorrentInfo, etc.) + if memoryMetadata, exists := metadataStore[fileHash]; exists { + // Merge in-memory metadata with database metadata + metadata.TorrentInfo = memoryMetadata.TorrentInfo + metadata.StreamingInfo = memoryMetadata.StreamingInfo + metadata.HLSPlaylist = memoryMetadata.HLSPlaylist + log.Printf("DEBUG: Found TorrentInfo in memory store for %s", fileHash) + } + // Check if file has completed transcoding and add streaming info - if g.transcodingManager != nil { + if g.transcodingManager != nil && metadata.StreamingInfo == nil { status := g.transcodingManager.GetTranscodingStatus(fileHash) if status == "completed" { // File has been successfully transcoded, mark it as video @@ -2451,6 +2460,7 @@ func (g *Gateway) TorrentHandler(w http.ResponseWriter, r *http.Request) { // Get and validate file hash vars := mux.Vars(r) fileHash := vars["hash"] + log.Printf("DEBUG: TorrentHandler called for hash: %s", fileHash) if err := g.validateFileHash(fileHash); err != nil { g.writeErrorResponse(w, ErrInvalidFileHash, err.Error()) @@ -2473,6 +2483,7 @@ func (g *Gateway) TorrentHandler(w http.ResponseWriter, r *http.Request) { // Get metadata metadata, err := g.getMetadata(fileHash) + log.Printf("DEBUG: TorrentHandler metadata lookup for %s: err=%v, metadata=%v", fileHash, err, metadata != nil) if err != nil { g.writeErrorResponse(w, ErrFileNotFound, fmt.Sprintf("No file found with hash: %s", fileHash)) return @@ -2487,6 +2498,7 @@ func (g *Gateway) TorrentHandler(w http.ResponseWriter, r *http.Request) { // Check if torrent is available if metadata.TorrentInfo == nil { + log.Printf("DEBUG: TorrentHandler - no TorrentInfo for hash %s", fileHash) g.writeError(w, http.StatusNotFound, "Torrent not available", ErrorTypeNotFound, "No torrent data found for this file") return diff --git a/internal/web/static/upload.js b/internal/web/static/upload.js index 5bcf293..ee06e1e 100644 --- a/internal/web/static/upload.js +++ b/internal/web/static/upload.js @@ -276,16 +276,20 @@ class GatewayUI { // Handle completion xhr.addEventListener('load', () => { - if (xhr.status >= 200 && xhr.status < 300) { - try { - const response = JSON.parse(xhr.responseText); - resolve(response); - } catch (error) { - reject(new Error('Invalid response format')); + // Create a Response-like object + const responseObj = { + ok: xhr.status >= 200 && xhr.status < 300, + status: xhr.status, + statusText: xhr.statusText, + json: async () => { + try { + return JSON.parse(xhr.responseText); + } catch (error) { + throw new Error('Invalid response format'); + } } - } else { - reject(new Error(`Upload failed: ${xhr.status} ${xhr.statusText}`)); - } + }; + resolve(responseObj); }); // Handle errors