Skip to content

Commit

Permalink
Working new http request (without album support)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonedegiacomi committed Jul 19, 2018
1 parent 28e5904 commit cff3249
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions api/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ func (u *Upload) Upload() (*UploadResult, error) {
}

// Enable the photo
uploadedImageURL, err := u.enablePhoto(token)
_, err = u.enablePhoto(token)
if err != nil {
log.Println("[WARNING] Image uploaded but url not found")
return &UploadResult{
Uploaded: true,
}, err
}
}/*
uploadedImageID, err := getImageIDFromURL(uploadedImageURL)
if err != nil {
log.Println("[WARNING] Image uploaded but url not found")
return &UploadResult{
Uploaded: true,
ImageUrl: uploadedImageURL,
}, err
}
}*/

// Add the image to an album if needed
if u.Options.AlbumId != "" {
Expand All @@ -150,7 +150,7 @@ func (u *Upload) Upload() (*UploadResult, error) {
// No errors, image uploaded!
return &UploadResult{
Uploaded: true,
ImageID: uploadedImageID,
ImageUrl: uploadedImageURL,
//ImageID: uploadedImageID,
//ImageUrl: uploadedImageURL,
}, nil
}
10 changes: 6 additions & 4 deletions api/uploadSteps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/url"
"strings"
"github.com/buger/jsonparser"
"strconv"
)

const (
Expand All @@ -19,7 +18,7 @@ const (

// Url to which send the request to enable an uploaded image
//EnablePhotoUrl = "https://photos.google.com/_/PhotosUi/mutate"
EnablePhotoUrl = "https://photos.google.com/u/2/_/PhotosUi/data/batchexecute?f.sid=blablabla&bl=blablabla&hl=it&soc-app=blablabla&soc-device=1&_reqid=blablabla&rt=c"
EnablePhotoUrl = "https://photos.google.com/u/2/_/PhotosUi/data/batchexecute"

// (Magic) Key to send in the request to enable the image
EnablePhotoKey = 137530650
Expand Down Expand Up @@ -205,7 +204,8 @@ func (u *Upload) enablePhoto(uploadTokenBase64 string) (enabledUrl string, err e
if err != nil {
return "", err
}*/
jsonStr := "[[[\"mdpdU\", \"[[[\\\"" + uploadTokenBase64 + "\\\", \\\"" + u.Options.Name + "\\\", " + strconv.Itoa(u.Options.Timestamp) + "]]]\",null,\"generic\"]]]"
jsonStr := fmt.Sprintf("[[[\"mdpdU\", \"[[[\\\"%v\\\", \\\"%v\\\", %v]]]\",null,\"generic\"]]]", uploadTokenBase64, u.Options.Name, u.Options.Timestamp)
//jsonStr := "[[[\"mdpdU\", \"[[[\\\"" + uploadTokenBase64 + "\\\", \\\"" + u.Options.Name + "\\\", " + strconv.Itoa(u.Options.Timestamp) + "]]]\",null,\"generic\"]]]"


// And add it to the form
Expand Down Expand Up @@ -239,6 +239,7 @@ func (u *Upload) enablePhoto(uploadTokenBase64 string) (enabledUrl string, err e
// Skip first characters which are not valid json
jsonRes = jsonRes[6:]

/*
u.idToMoveIntoAlbum, err = jsonparser.GetString(jsonRes, "[0]", "[1]", strconv.Itoa(EnablePhotoKey), "[0]", "[0]", "[1]", "[0]")
if err != nil {
fmt.Println(err)
Expand All @@ -248,7 +249,8 @@ func (u *Upload) enablePhoto(uploadTokenBase64 string) (enabledUrl string, err e
return "", err
} else {
return eUrl, nil
}
}*/
return "", nil
}

// This method add the image to an existing album given the id
Expand Down
4 changes: 2 additions & 2 deletions version/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cff3249

Please sign in to comment.