Browse Source

Fix mutexes + port argument

master
PrivateGER 3 years ago
parent
commit
8970e63615
Signed by: PrivateGER GPG Key ID: CAE625C962F94C67
  1. 3
      DirectoryIndexers/DirectoryIndexer.go
  2. 14
      main.go

3
DirectoryIndexers/DirectoryIndexer.go

@ -29,7 +29,6 @@ func Index(path string, results chan FileList) {
// Initialize the RWMutex HERE manually because *IT IS A POINTER TO A MUTEX*, so it defaults to a nil value
FL.RWMutex = &sync.RWMutex{}
FL.Lock()
fmt.Println("Scanning archive...")
@ -89,8 +88,6 @@ func Index(path string, results chan FileList) {
}
}
FL.Unlock()
results <- FL
close(results)

14
main.go

@ -6,6 +6,8 @@ import (
"fmt"
"net/http"
"os"
"strconv"
"sync"
"time"
"ytdlp-viewer/DirectoryIndexers"
"ytdlp-viewer/PageHandlers"
@ -14,10 +16,14 @@ import (
func main() {
var path string
flag.StringVar(&path, "path", "./", "the full path to the ytdlp archive (with a / suffix)")
var port int
flag.IntVar(&port, "port", 8000, "the port for the web panel to listen on")
flag.Parse()
var FL DirectoryIndexers.FileList
FL.RWMutex = &sync.RWMutex{}
go func() {
for {
resultChannel := make(chan DirectoryIndexers.FileList)
@ -25,7 +31,11 @@ func main() {
fmt.Println("Starting scanner at", path)
go DirectoryIndexers.Index(path, resultChannel)
FL = <-resultChannel
refreshedFL := <-resultChannel
FL.Lock()
FL.Files = refreshedFL.Files
FL.Unlock()
time.Sleep(60 * time.Second)
}
}()
@ -44,7 +54,7 @@ func main() {
})
http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path))))
err := http.ListenAndServe(":8000", nil)
err := http.ListenAndServe(":" + strconv.Itoa(port), nil)
if err != nil {
fmt.Println(err)
os.Exit(1)

Loading…
Cancel
Save