more fuckingfixes
This commit is contained in:
parent
653c291f1d
commit
9eb09c421a
@ -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
|
||||
|
@ -276,16 +276,20 @@ class GatewayUI {
|
||||
|
||||
// Handle completion
|
||||
xhr.addEventListener('load', () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
// Create a Response-like object
|
||||
const responseObj = {
|
||||
ok: xhr.status >= 200 && xhr.status < 300,
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
json: async () => {
|
||||
try {
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
resolve(response);
|
||||
return JSON.parse(xhr.responseText);
|
||||
} catch (error) {
|
||||
reject(new Error('Invalid response format'));
|
||||
throw new Error('Invalid response format');
|
||||
}
|
||||
} else {
|
||||
reject(new Error(`Upload failed: ${xhr.status} ${xhr.statusText}`));
|
||||
}
|
||||
};
|
||||
resolve(responseObj);
|
||||
});
|
||||
|
||||
// Handle errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user