Refactor realtime to realtime

This commit is contained in:
2024-06-16 22:59:03 +02:00
parent f182fceafd
commit 369f8f2601
2 changed files with 78 additions and 22 deletions

36
main.go
View File

@@ -5,27 +5,11 @@ import (
"io/ioutil"
"log"
"net/http"
"time"
)
type Response struct {
Page int `json:"page"`
PerPage int `json:"perPage"`
TotalItems int `json:"totalItems"`
TotalPages int `json:"totalPages"`
Items []Item `json:"items"`
}
type Item struct {
CollectionId string `json:"collectionId"`
CollectionName string `json:"collectionName"`
Created string `json:"created"`
Downloaded bool `json:"downloaded"`
Id string `json:"id"`
Link string `json:"link"`
Updated string `json:"updated"`
}
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"
@@ -40,7 +24,7 @@ func main() {
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Println("Error reading response body:", err)
log.Printf("Error reading response body: %+v\n", err)
return
}
if res.StatusCode != http.StatusOK {
@@ -48,11 +32,19 @@ func main() {
return
}
var data Response
var data APIResponse
err = json.Unmarshal(body, &data)
if err != nil {
log.Println("Error unmarshaling JSON:", err)
log.Printf("Error unmarshaling JSON: %+v\n", err)
return
}
log.Printf("Data: %+v\n", data)
// log.Printf("Data: %+v\n", data)
listener := new(RealtimeListener)
listener.Url = POCKETBASE_REALTIME
listener.Collections = []string{COLLECTION_NAME}
listener.initialize()
log.Printf("zzz...\n")
time.Sleep(1 * time.Hour)
}