Rework DL to use new endpoint
This commit is contained in:
28
dl/dl.go
28
dl/dl.go
@@ -11,28 +11,12 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
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"
|
||||
const URL = `https://youtube-download-ws-server.site.quack-lab.dev/download`
|
||||
|
||||
type Item struct {
|
||||
Link string `json:"link"`
|
||||
}
|
||||
|
||||
type APIError struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data APIErrorData `json:"data"`
|
||||
}
|
||||
type APIErrorData struct {
|
||||
Link APIErrorLink `json:"link"`
|
||||
}
|
||||
type APIErrorLink struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
func main() {
|
||||
@@ -49,7 +33,7 @@ func main() {
|
||||
func Download(url string) {
|
||||
defer wg.Done()
|
||||
|
||||
req, err := http.NewRequestWithContext(context.Background(), "POST", FULL_URL, nil)
|
||||
req, err := http.NewRequestWithContext(context.Background(), "POST", URL, nil)
|
||||
if err != nil {
|
||||
log.Printf("Error creating POST request: %++v", err)
|
||||
return
|
||||
@@ -82,14 +66,6 @@ func Download(url string) {
|
||||
log.Printf("Error reading response body: %++v", err)
|
||||
return
|
||||
}
|
||||
var data APIError
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshaling JSON: %++v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("API error: %++v", data)
|
||||
return
|
||||
} else {
|
||||
log.Printf("Enqueued %s", url)
|
||||
|
Reference in New Issue
Block a user