sketch of submitting external file to WP
This commit is contained in:
parent
6f1b4a7fe9
commit
03c1e1c6ae
29
main.go
29
main.go
@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"federated.computer/wp-sync-slowtwitch/services/wordpress"
|
"bytes"
|
||||||
|
"federated.computer/wp-sync-slowtwitch/utilities"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
|
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
|
||||||
@ -14,19 +17,21 @@ var appCache AppCache
|
|||||||
func main() {
|
func main() {
|
||||||
//Get category and cache
|
//Get category and cache
|
||||||
//Get single category from cache by name
|
//Get single category from cache by name
|
||||||
//Get tag and cache
|
|
||||||
//Get single tag from cache by name
|
|
||||||
//Get photo and cache with URL
|
//Get photo and cache with URL
|
||||||
//Create Category (with parent) + add to cache
|
//Create Category (with parent) + add to cache
|
||||||
//Create Tag + add to cache
|
|
||||||
//Upload Photo + add to cache
|
//Upload Photo + add to cache
|
||||||
//Use cached data to correctly build post form submissions
|
//Use cached data to correctly build post form submissions
|
||||||
|
resp, err := http.Get("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjPm2ryEM65R2LDKe1ov_2ThSg1Po44Pe6ybLGa9hEeKU9qLptSeYVc_ahRzA3ZiKqm73fdgYGCq2ZsfJTLPKjfCqkNtKF6xYwYfRTje3o2jH9VEKSvLyWZwCctQGHC7zREUBnJFZlI0A/s1600/Dogs+Puppies+Background+wallpaper+%25284%2529.jpg")
|
||||||
tag, ok := wordpress.GetTag("golang-tag", baseUrl, wordpressKey, wordpressSecret)
|
utilities.CheckError(err)
|
||||||
if ok {
|
defer utilities.CloseBodyAndCheckError(resp.Body)
|
||||||
appCache.SetTag(tag)
|
body, err := io.ReadAll(resp.Body)
|
||||||
fmt.Println("Found tag:", tag.Name)
|
utilities.CheckError(err)
|
||||||
} else {
|
request, err := http.NewRequest("POST", "https://go-api-playground.local/wp-json/wp/v2/media", bytes.NewReader(body))
|
||||||
fmt.Println("Could not find tag.")
|
request.Header.Set("Content-Disposition", `attachment;filename="Dogs+Puppies+Background+wallpaper+%25284%2529.jpg"`)
|
||||||
}
|
request.SetBasicAuth(wordpressKey, wordpressSecret)
|
||||||
|
rsp, err := http.DefaultClient.Do(request)
|
||||||
|
utilities.CheckError(err)
|
||||||
|
result, err := io.ReadAll(rsp.Body)
|
||||||
|
utilities.CheckError(err)
|
||||||
|
fmt.Println(rsp.StatusCode, string(result))
|
||||||
}
|
}
|
||||||
|
9
services/wordpress/create-image.go
Normal file
9
services/wordpress/create-image.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package wordpress
|
||||||
|
|
||||||
|
type CreateImage struct {
|
||||||
|
Date string `json:"date"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateImageResponse struct {
|
||||||
|
}
|
@ -15,6 +15,7 @@ type CreatePost struct {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Categories []int `json:"categories"`
|
Categories []int `json:"categories"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
|
Date string `json:"date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreatePostResponse struct {
|
type CreatePostResponse struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user