Add option for http mount
This commit is contained in:
69
internal/http/response.go
Normal file
69
internal/http/response.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/davextra"
|
||||
)
|
||||
|
||||
// createMultiTorrentResponse creates a WebDAV response for a list of torrents
|
||||
func createMultiTorrentResponse(basePath string, torrents []torrent.Torrent) (string, error) {
|
||||
htmlDoc := "<ul>"
|
||||
|
||||
seen := make(map[string]bool)
|
||||
|
||||
for _, item := range torrents {
|
||||
if item.Progress != 100 {
|
||||
continue
|
||||
}
|
||||
if _, exists := seen[item.Name]; exists {
|
||||
continue
|
||||
}
|
||||
seen[item.Name] = true
|
||||
|
||||
path := filepath.Join(basePath, item.Name)
|
||||
htmlDoc += fmt.Sprintf("<li><a href=\"%s/\">%s</a></li>", path, item.Name)
|
||||
}
|
||||
|
||||
return htmlDoc, nil
|
||||
}
|
||||
|
||||
func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent) (string, error) {
|
||||
htmlDoc := "<ul>"
|
||||
|
||||
nameAndLink := make(map[string]bool)
|
||||
finalName := make(map[string]bool)
|
||||
|
||||
currentPath := filepath.Join(basePath)
|
||||
|
||||
for _, torrent := range torrents {
|
||||
for _, file := range torrent.SelectedFiles {
|
||||
if file.Link == "" {
|
||||
log.Println("File has no link, skipping", file.Path)
|
||||
continue
|
||||
}
|
||||
|
||||
filename := filepath.Base(file.Path)
|
||||
key := filename + file.Link
|
||||
|
||||
if nameAndLink[key] {
|
||||
continue
|
||||
}
|
||||
nameAndLink[key] = true
|
||||
|
||||
if finalName[filename] {
|
||||
fragment := davextra.GetLinkFragment(file.Link)
|
||||
filename = davextra.InsertLinkFragment(filename, fragment)
|
||||
}
|
||||
finalName[filename] = true
|
||||
|
||||
filePath := filepath.Join(currentPath, filename)
|
||||
htmlDoc += fmt.Sprintf("<li><a href=\"%s\">%s</a></li>", filePath, filename)
|
||||
}
|
||||
}
|
||||
|
||||
return htmlDoc, nil
|
||||
}
|
||||
Reference in New Issue
Block a user