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