Move Spaces FromEnv into blob; Upload takes Object; drop logSpaces.

This commit is contained in:
2026-08-21 23:48:18 -07:00
parent 3eb75cfd80
commit a36bc723cc
4 changed files with 45 additions and 39 deletions
+11 -5
View File
@@ -8,18 +8,19 @@ import (
"github.com/google/uuid"
"plumber/internal/blob"
"plumber/internal/geo"
"plumber/internal/store"
)
type profilePage struct {
page
States []struct{ Code, Name string }
Questions []store.RankedQuestion
States []struct{ Code, Name string }
Questions []store.RankedQuestion
QuestionsLabel string
UploadsEnabled bool
Error string
StateVal string
Error string
StateVal string
}
func (s *Server) handleProfileForm(w http.ResponseWriter, r *http.Request) {
@@ -74,7 +75,12 @@ func (s *Server) handleProfile(w http.ResponseWriter, r *http.Request) {
}
key := path.Join("avatars", u.ID, uuid.NewString()+ext)
limited := io.LimitReader(file, (2<<20)+1)
url, upErr := s.cfg.Blob.Upload(r.Context(), key, limited, contentType, hdr.Size)
url, upErr := s.cfg.Blob.Upload(r.Context(), blob.Object{
Key: key,
Body: limited,
ContentType: contentType,
Size: hdr.Size,
})
if upErr != nil {
s.renderProfile(w, r, u, "Could not upload avatar. Try again later.", state)
return
+4 -4
View File
@@ -3,7 +3,6 @@ package web
import (
"bytes"
"context"
"io"
"mime/multipart"
"net/http"
"net/http/httptest"
@@ -13,6 +12,7 @@ import (
"github.com/alexedwards/scs/v2"
"plumber"
"plumber/internal/blob"
)
func newTestServer(t *testing.T) (*Server, *memDB, scs.Store) {
@@ -296,10 +296,10 @@ type fakeBlob struct {
func (f *fakeBlob) Enabled() bool { return true }
func (f *fakeBlob) Upload(_ context.Context, key string, _ io.Reader, _ string, _ int64) (string, error) {
func (f *fakeBlob) Upload(_ context.Context, obj blob.Object) (string, error) {
f.calls++
f.last = key
return "https://cdn.example.com/" + key, nil
f.last = obj.Key
return "https://cdn.example.com/" + obj.Key, nil
}
func TestProfilePageAndState(t *testing.T) {