fixed broken images issue

This commit is contained in:
Ross Trottier 2024-05-29 09:11:01 -06:00
parent ffde450209
commit ee3ae47d4f
5 changed files with 28 additions and 10 deletions

View File

@ -7,15 +7,15 @@ import (
)
// WP Config
const baseUrl = "http://go-api-playground.local/"
const wordpressKey = "admin"
const wordpressSecret = "KStj VH7E 9UZf FV8C ptGQ F4Tl"
const baseUrl = "https://slowtwitch.cloud/"
const wordpressKey = "admin@slowtwitch.cloud"
const wordpressSecret = "rcI0 7qAM Q1CR xi6n sGcB 4XFN"
// DB Config
const slowtwitchAdminUser = "admin"
const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv"
const slowtwitchDbName = "slowtwitch"
const migrationDbName = "slowtwitch_transfer_threaded_test"
const migrationDbName = "slowtwitch_transfer"
const federatedDbUrl = "slowtwitch.northend.network"
const federatedDbPort = "3306"

Binary file not shown.

View File

@ -44,6 +44,8 @@ func (migration *MigrateAuthors) Execute() []EditorResult {
if err == nil {
wordpressId = result.Id
isSuccess = true
} else {
fmt.Println("error creating user:", err)
}
editorResult := EditorResult{

View File

@ -180,7 +180,9 @@ func (migration MigratePosts) Execute() []PostResult {
}
imageResults = append(imageResults, imageResult)
//replace old links with new in post html
strings.ReplaceAll(html, imageUrl, wordpressImage.Link)
//TODO Wordpress path vs link? If path works I prefer that
newImagePath := "/wp-content/uploads/" + wordpressImage.MediaDetails.File
html = strings.ReplaceAll(html, imagePath, newImagePath)
//create redirect
imageRedirect := wordpress.CreateRedirect{
Title: postBase.Title + "image-" + string((i + 1)),
@ -271,7 +273,7 @@ func (migration MigratePosts) Execute() []PostResult {
postResults = append(postResults, batchResults...)
}
}
// Update related posts once work is done
// Update related posts once work is done -- Why are there duplicates?
updatePostRelationships(postResults, migration)
return postResults
@ -366,7 +368,7 @@ func getSuccessfulWordpressImageIds(imageResults []ImageResult) []int {
var output []int
for _, imageResult := range imageResults {
if imageResult.IsSuccess {
if imageResult.WordpressId > 0 && imageResult.IsSuccess {
output = append(output, imageResult.WordpressId)
}
}
@ -392,3 +394,12 @@ func updateAcfImages(imageResults []ImageResult, postId int, baseUrl, user, pass
}
}
}
func getContentType(filename string) string {
if strings.Contains(filename, "png") {
return ".png"
} else if strings.Contains(filename, "gif") {
return ".gif"
}
return ".jpeg"
}

View File

@ -14,9 +14,14 @@ type CreateImage struct {
}
type CreateImageResponse struct {
Id int `json:"id"`
Link string `json:"link"`
Slug string `json:"slug"`
Id int `json:"id"`
Link string `json:"link"`
Slug string `json:"slug"`
MediaDetails MediaDetails `json:"media_details"`
}
type MediaDetails struct {
File string `json:"file"`
}
func (parameters *CreateImage) Execute(baseUrl, user, pass string) (CreateImageResponse, error) {