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"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const POCKETBASE_URL = `https://pocketbase-scratch.site.quack-lab.dev/api/collections`
|
const URL = `https://youtube-download-ws-server.site.quack-lab.dev/download`
|
||||||
const POCKETBASE_REALTIME = `https://pocketbase-scratch.site.quack-lab.dev/api/realtime`
|
|
||||||
const COLLECTION_NAME = "youtubedownload"
|
|
||||||
const FULL_URL = POCKETBASE_URL + "/" + COLLECTION_NAME + "/records"
|
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
Link string `json:"link"`
|
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
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -49,7 +33,7 @@ func main() {
|
|||||||
func Download(url string) {
|
func Download(url string) {
|
||||||
defer wg.Done()
|
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 {
|
if err != nil {
|
||||||
log.Printf("Error creating POST request: %++v", err)
|
log.Printf("Error creating POST request: %++v", err)
|
||||||
return
|
return
|
||||||
@@ -82,14 +66,6 @@ func Download(url string) {
|
|||||||
log.Printf("Error reading response body: %++v", err)
|
log.Printf("Error reading response body: %++v", err)
|
||||||
return
|
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
|
return
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Enqueued %s", url)
|
log.Printf("Enqueued %s", url)
|
||||||
|
Reference in New Issue
Block a user