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 // 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.RWMutex = &sync.RWMutex{}
FL.Lock()
fmt.Println("Scanning archive...") fmt.Println("Scanning archive...")
@ -89,8 +88,6 @@ func Index(path string, results chan FileList) {
} }
} }
FL.Unlock()
results <- FL results <- FL
close(results) close(results)

14
main.go

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

Loading…
Cancel
Save