Every like gives me a bigger pumpkin head

okay resume should now hopefully acutally work. had to give goat a second read

+34 -9
+34 -9
main.go
··· 25 xdraw "golang.org/x/image/draw" 26 ) 27 28 type PumpkinHead struct { 29 bodyImg image.Image 30 headImg image.Image ··· 40 return p.callCount 41 } 42 43 func NewPumpkinHead(bodyPath, headPath string) (*PumpkinHead, error) { 44 // Load body image 45 bodyFile, err := os.Open(bodyPath) ··· 73 }, nil 74 } 75 76 func (p *PumpkinHead) GrowHead() (image.Image, error) { 77 p.callCount++ 78 ··· 100 // Calculate position to center the head on top of the body 101 // Place head in upper portion of the image 102 headX := (bodyBounds.Dx() - newHeadWidth) / 2 103 - headY := bodyBounds.Dy()/8 - newHeadHeight/2 + 350 // the 1900 is to line up with my head 104 105 headPos := image.Rect(headX, headY, headX+newHeadWidth, headY+newHeadHeight) 106 ··· 120 return buf, nil 121 } 122 123 func saveToFiles(pumpkin *PumpkinHead, outputDir string, newPic image.Image) { 124 125 // Create output directory if it doesn't exist ··· 144 } 145 } 146 147 type AuthSession struct { 148 DID syntax.DID `json:"did"` 149 Password string `json:"password"` ··· 152 PDS string `json:"pds"` 153 } 154 155 type AtProtoStuff struct { 156 authSession AuthSession 157 Client *atclient.APIClient 158 } 159 160 func Login(ctx context.Context, host, did, password string) (*AtProtoStuff, error) { 161 162 client, err := atclient.LoginWithPasswordHost(ctx, host, did, password, "", nil) ··· 178 RefreshToken: passAuth.Session.RefreshToken, 179 } 180 181 - //client.Client. 182 return &AtProtoStuff{ 183 authSession: sess, 184 Client: client, 185 }, nil 186 } 187 188 func (a *AtProtoStuff) authRefreshCallback(ctx context.Context, data atclient.PasswordSessionData) { 189 fmt.Println("auth refresh callback") 190 ··· 196 197 func (a *AtProtoStuff) updatePumpkinHead(ctx context.Context, image io.Reader) (err error) { 198 199 - client := atclient.ResumePasswordSession(atclient.PasswordSessionData{ 200 - AccessToken: a.authSession.AccessToken, 201 - RefreshToken: a.authSession.RefreshToken, 202 - AccountDID: a.authSession.DID, 203 - Host: a.authSession.PDS, 204 - }, a.authRefreshCallback) 205 206 profileNsid := "app.bsky.actor.profile" 207 selfKey := "self" ··· 296 pdsHost := os.Getenv("PDS_HOST") 297 appPassword := os.Getenv("APP_PASSWORD") 298 299 - fmt.Fprintf(os.Stderr, "Logging wirg DID %s to %s\n", usersDid, pdsHost) 300 301 var atProtoStuff *AtProtoStuff 302 atProtoStuff, err = Login(ctx, pdsHost, usersDid, appPassword)
··· 25 xdraw "golang.org/x/image/draw" 26 ) 27 28 + // PumpkinHead context for increasing the pumpkin head/ 29 type PumpkinHead struct { 30 bodyImg image.Image 31 headImg image.Image ··· 41 return p.callCount 42 } 43 44 + // NewPumpkinHead commence pumpkinhead 45 func NewPumpkinHead(bodyPath, headPath string) (*PumpkinHead, error) { 46 // Load body image 47 bodyFile, err := os.Open(bodyPath) ··· 75 }, nil 76 } 77 78 + // GrowHead Increases the pumpkin head by values in PumpkinHead.scaleStep 79 func (p *PumpkinHead) GrowHead() (image.Image, error) { 80 p.callCount++ 81 ··· 103 // Calculate position to center the head on top of the body 104 // Place head in upper portion of the image 105 headX := (bodyBounds.Dx() - newHeadWidth) / 2 106 + headY := bodyBounds.Dy()/8 - newHeadHeight/2 + 350 // the 350 is to line up with my head 107 108 headPos := image.Rect(headX, headY, headX+newHeadWidth, headY+newHeadHeight) 109 ··· 123 return buf, nil 124 } 125 126 + // saveToFiles saves the image to a file. Mostly used for testing 127 func saveToFiles(pumpkin *PumpkinHead, outputDir string, newPic image.Image) { 128 129 // Create output directory if it doesn't exist ··· 148 } 149 } 150 151 + // AuthSession stores the auth session data. ty goat 152 type AuthSession struct { 153 DID syntax.DID `json:"did"` 154 Password string `json:"password"` ··· 157 PDS string `json:"pds"` 158 } 159 160 + // AtProtoStuff stores the atproto stuff. or more correctly the context of auth and a authenticated client 161 type AtProtoStuff struct { 162 authSession AuthSession 163 Client *atclient.APIClient 164 } 165 166 + // Login logs into their PDS and sets AtProtoStuff 167 func Login(ctx context.Context, host, did, password string) (*AtProtoStuff, error) { 168 169 client, err := atclient.LoginWithPasswordHost(ctx, host, did, password, "", nil) ··· 185 RefreshToken: passAuth.Session.RefreshToken, 186 } 187 188 return &AtProtoStuff{ 189 authSession: sess, 190 Client: client, 191 }, nil 192 } 193 194 + // loadAuthClient ty again goat 195 + func (a *AtProtoStuff) loadAuthClient(ctx context.Context) (*atclient.APIClient, error) { 196 + 197 + // first try to resume session 198 + client := atclient.ResumePasswordSession(atclient.PasswordSessionData{ 199 + AccessToken: a.authSession.AccessToken, 200 + RefreshToken: a.authSession.RefreshToken, 201 + AccountDID: a.authSession.DID, 202 + Host: a.authSession.PDS, 203 + }, a.authRefreshCallback) 204 + 205 + // check that auth is working 206 + _, err := comatproto.ServerGetSession(ctx, client) 207 + if nil == err { 208 + return client, nil 209 + } 210 + 211 + return atclient.LoginWithPasswordHost(ctx, a.authSession.PDS, a.authSession.DID.String(), a.authSession.Password, "", nil) 212 + } 213 + 214 + // authRefreshCallback is called when the auth session expires and refreshes the auth session 215 func (a *AtProtoStuff) authRefreshCallback(ctx context.Context, data atclient.PasswordSessionData) { 216 fmt.Println("auth refresh callback") 217 ··· 223 224 func (a *AtProtoStuff) updatePumpkinHead(ctx context.Context, image io.Reader) (err error) { 225 226 + client, err := a.loadAuthClient(ctx) 227 + if err != nil { 228 + return err 229 + } 230 231 profileNsid := "app.bsky.actor.profile" 232 selfKey := "self" ··· 321 pdsHost := os.Getenv("PDS_HOST") 322 appPassword := os.Getenv("APP_PASSWORD") 323 324 + fmt.Fprintf(os.Stderr, "Logging with DID %s to %s\n", usersDid, pdsHost) 325 326 var atProtoStuff *AtProtoStuff 327 atProtoStuff, err = Login(ctx, pdsHost, usersDid, appPassword)