add support for sub folders
This commit is contained in:
parent
d2a360caf1
commit
2c1c506a45
2 changed files with 181 additions and 462 deletions
24
main.go
24
main.go
|
|
@ -11,33 +11,23 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
dir := flag.String("dir", ".", "Directory containing ISO files to serve")
|
||||
addr := flag.String("addr", ":8080", "Address to listen on")
|
||||
dir := flag.String("dir", ".", "Directory to serve")
|
||||
addr := flag.String("addr", ":8080", "Address")
|
||||
flag.Parse()
|
||||
|
||||
info, err := os.Stat(*dir)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot access directory %q: %v", *dir, err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
log.Fatalf("%q is not a directory", *dir)
|
||||
if info, err := os.Stat(*dir); err != nil || !info.IsDir() {
|
||||
log.Fatalf("Invalid directory: %s", *dir)
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
h := handlers.New(*dir)
|
||||
|
||||
// Routes:
|
||||
// GET / → list all ISOs in the directory
|
||||
// GET /browse/{iso} → list root of ISO
|
||||
// GET /browse/{iso}/{path...} → list directory inside ISO
|
||||
// GET /file/{iso}/{path...} → stream/view a file from inside ISO
|
||||
// GET /raw/{filename} → serve raw disk files (ISOs, covers, descriptions)
|
||||
mux.HandleFunc("/", h.ListISOs)
|
||||
// Routes
|
||||
mux.HandleFunc("/browse/", h.BrowseISO)
|
||||
mux.HandleFunc("/file/", h.DownloadFile)
|
||||
mux.HandleFunc("/raw/", h.RawFile)
|
||||
mux.HandleFunc("/", h.ListISOs) // Catch-all for directory navigation
|
||||
|
||||
fmt.Printf("ISOSilo listening on %s\n", *addr)
|
||||
fmt.Printf("Serving ISOs from: %s\n", *dir)
|
||||
fmt.Printf("ISOSilo running at %s\n", *addr)
|
||||
log.Fatal(http.ListenAndServe(*addr, mux))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue