An experimental IndieWeb site built in Go.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix media endpoint upload

remove redundant slash in endpoint URL, seek to start of file after
checking header, allow tokens with `create` scope

+14 -3
+10 -3
main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "context" 4 5 "encoding/json" 5 6 "fmt" 6 7 "io" ··· 118 119 }, 119 120 } 120 121 }), 121 - micropub.WithMediaEndpoint(s.profileURL+"/micropub/media"), 122 + micropub.WithMediaEndpoint(s.profileURL+"micropub/media"), 122 123 ) 123 124 124 125 r.Get("/", mpHandler.ServeHTTP) 125 126 r.Post("/", mpHandler.ServeHTTP) 126 127 r.Post("/media", micropub.NewMediaHandler( 127 128 mp.HandleMediaUpload, 128 - mp.HasScope, 129 + func(r *http.Request, scope string) bool { 130 + // IndieKit checks for a `media` scope, not commonly requested 131 + hasMediaScope := mp.HasScope(r, scope) 132 + hasCreateScope := mp.HasScope(r, "create") 133 + 134 + return hasMediaScope || hasCreateScope 135 + }, 129 136 ).ServeHTTP) 130 137 }) 131 138 ··· 170 177 func (s *server) serveMedia(w http.ResponseWriter, r *http.Request) { 171 178 key := strings.TrimPrefix(r.URL.Path, "/") 172 179 173 - res, err := s.db.Media.GetObject(r.Context(), &s3.GetObjectInput{ 180 + res, err := s.db.Media.GetObject(context.TODO(), &s3.GetObjectInput{ 174 181 Bucket: aws.String(os.Getenv("AWS_S3_BUCKET_NAME")), 175 182 Key: &key, 176 183 })
+4
micropub.go
··· 74 74 defer file.Close() 75 75 76 76 kind, err := filetype.MatchReader(file) 77 + if _, err := file.Seek(0, 0); err != nil { 78 + return "", fmt.Errorf("%w: %w", errors.New("failed to reset cursor"), err) 79 + } 80 + 77 81 if err != nil { 78 82 return "", fmt.Errorf("%w: %w", errors.New("failed to upload"), err) 79 83 }