more fuckingfixes
This commit is contained in:
parent
ab8279f814
commit
aa5190c27b
@ -1459,6 +1459,68 @@ func (g *Gateway) LoadExistingFilesToMetadataStore() error {
|
||||
TorrentInfo: metadata.TorrentInfo,
|
||||
}
|
||||
|
||||
// Regenerate TorrentInfo for torrent storage type files if missing
|
||||
if file.StorageType == "torrent" && file.InfoHash != "" && fileMetadata.TorrentInfo == nil {
|
||||
log.Printf("DEBUG: Regenerating TorrentInfo for file %s (InfoHash: %s)", file.Hash, file.InfoHash)
|
||||
|
||||
// Get chunk hashes
|
||||
chunkHashes, err := g.storage.GetChunkHashes(file.Hash)
|
||||
if err != nil {
|
||||
log.Printf("Warning: Failed to get chunk hashes for %s: %v", file.Hash, err)
|
||||
} else {
|
||||
// Create torrent pieces from chunk hashes
|
||||
pieces := make([]torrent.PieceInfo, len(chunkHashes))
|
||||
for i, chunkHash := range chunkHashes {
|
||||
// Convert hex string to bytes for torrent hash
|
||||
hashBytes := make([]byte, 20)
|
||||
copy(hashBytes, []byte(chunkHash)[:20])
|
||||
|
||||
pieces[i] = torrent.PieceInfo{
|
||||
Index: i,
|
||||
Hash: [20]byte(hashBytes),
|
||||
SHA256: chunkHash,
|
||||
Length: int(g.config.GetChunkSize()),
|
||||
}
|
||||
}
|
||||
|
||||
// Generate WebSeed URL
|
||||
webSeedURL := fmt.Sprintf("%s/api/download/%s", g.getBaseURL(), file.Hash)
|
||||
|
||||
fileInfo := torrent.FileInfo{
|
||||
Name: file.OriginalName,
|
||||
Size: file.Size,
|
||||
Pieces: pieces,
|
||||
WebSeedURL: webSeedURL,
|
||||
}
|
||||
|
||||
// Use existing trackers from config
|
||||
trackers := g.config.Torrent.Trackers
|
||||
if len(trackers) == 0 {
|
||||
trackers = []string{
|
||||
"udp://tracker.opentrackr.org:1337",
|
||||
"udp://tracker.openbittorrent.com:6969",
|
||||
}
|
||||
}
|
||||
|
||||
// Get gateway URL
|
||||
gatewayURL := g.getBaseURL()
|
||||
|
||||
// Build DHT nodes list
|
||||
var dhtNodes [][]interface{}
|
||||
if g.config.IsServiceEnabled("dht") {
|
||||
dhtNodes = append(dhtNodes, []interface{}{g.GetPublicURL(), g.GetDHTPort()})
|
||||
}
|
||||
|
||||
torrentInfo, err := torrent.CreateTorrent(fileInfo, trackers, gatewayURL, dhtNodes)
|
||||
if err != nil {
|
||||
log.Printf("Warning: Failed to regenerate torrent for %s: %v", file.Hash, err)
|
||||
} else {
|
||||
fileMetadata.TorrentInfo = torrentInfo
|
||||
log.Printf("DEBUG: Successfully regenerated TorrentInfo for %s", file.Hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store in metadataStore
|
||||
metadataStore[file.Hash] = fileMetadata
|
||||
log.Printf("DEBUG: Loaded file %s into metadataStore", file.Hash)
|
||||
|
Loading…
x
Reference in New Issue
Block a user