Refactor
This commit is contained in:
63
downloader/main.go
Normal file
63
downloader/main.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
const POCKETBASE_URL = `https://pocketbase-scratch.site.quack-lab.dev/api/collections`
|
||||
const POCKETBASE_REALTIME = `https://pocketbase-scratch.site.quack-lab.dev/api/realtime`
|
||||
const COLLECTION_NAME = "youtubedownload"
|
||||
const FULL_URL = POCKETBASE_URL + "/" + COLLECTION_NAME + "/records"
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.Lmicroseconds)
|
||||
log.Println(FULL_URL)
|
||||
|
||||
// res, err := http.Get(FULL_URL)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// defer res.Body.Close()
|
||||
// body, err := io.ReadAll(res.Body)
|
||||
// if err != nil {
|
||||
// log.Printf("Error reading response body: %+v\n", err)
|
||||
// return
|
||||
// }
|
||||
// if res.StatusCode != http.StatusOK {
|
||||
// log.Printf("Non-OK HTTP status: %d\nResponse body: %s\n", res.StatusCode, body)
|
||||
// return
|
||||
// }
|
||||
|
||||
// var data APIResponse
|
||||
// err = json.Unmarshal(body, &data)
|
||||
// if err != nil {
|
||||
// log.Printf("Error unmarshaling JSON: %+v\n", err)
|
||||
// return
|
||||
// }
|
||||
// log.Printf("Data: %+v\n", data)
|
||||
|
||||
listener := new(RealtimeListener)
|
||||
listener.Url = POCKETBASE_REALTIME
|
||||
listener.Collections = []string{COLLECTION_NAME}
|
||||
listener.initialize()
|
||||
|
||||
status := make(chan error)
|
||||
for {
|
||||
select {
|
||||
case event := <-listener.Create:
|
||||
log.Printf("Create event: %+v\n", event)
|
||||
eventCopy := event
|
||||
go func() {
|
||||
Download(eventCopy, status)
|
||||
// go DownloadNative(event, status)
|
||||
for status := range status {
|
||||
log.Printf("Status: %s\n", status)
|
||||
}
|
||||
}()
|
||||
case <-time.After(1 * time.Minute):
|
||||
// Perform some action or simply continue to avoid deadlock
|
||||
log.Println("Consumer is alive, but has no new events.")
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user