fix: remove leading / from s3 paths

This commit is contained in:
Sam 2023-05-22 15:59:49 +02:00
parent 295b76aad2
commit bf34c77269
No known key found for this signature in database
GPG key ID: B4EF20DDE721CAA1
3 changed files with 10 additions and 10 deletions

View file

@ -111,7 +111,7 @@ func (db *DB) WriteMemberAvatar(ctx context.Context,
} }
hash = hex.EncodeToString(hasher.Sum(nil)) hash = hex.EncodeToString(hasher.Sum(nil))
_, err = db.minio.PutObject(ctx, db.minioBucket, "/members/"+memberID.String()+"/"+hash+".webp", webp, -1, minio.PutObjectOptions{ _, err = db.minio.PutObject(ctx, db.minioBucket, "members/"+memberID.String()+"/"+hash+".webp", webp, -1, minio.PutObjectOptions{
ContentType: "image/webp", ContentType: "image/webp",
SendContentMd5: true, SendContentMd5: true,
}) })
@ -119,7 +119,7 @@ func (db *DB) WriteMemberAvatar(ctx context.Context,
return "", errors.Wrap(err, "uploading webp avatar") return "", errors.Wrap(err, "uploading webp avatar")
} }
_, err = db.minio.PutObject(ctx, db.minioBucket, "/members/"+memberID.String()+"/"+hash+".jpg", jpeg, -1, minio.PutObjectOptions{ _, err = db.minio.PutObject(ctx, db.minioBucket, "members/"+memberID.String()+"/"+hash+".jpg", jpeg, -1, minio.PutObjectOptions{
ContentType: "image/jpeg", ContentType: "image/jpeg",
SendContentMd5: true, SendContentMd5: true,
}) })
@ -131,12 +131,12 @@ func (db *DB) WriteMemberAvatar(ctx context.Context,
} }
func (db *DB) DeleteUserAvatar(ctx context.Context, userID xid.ID, hash string) error { func (db *DB) DeleteUserAvatar(ctx context.Context, userID xid.ID, hash string) error {
err := db.minio.RemoveObject(ctx, db.minioBucket, "/users/"+userID.String()+"/"+hash+".webp", minio.RemoveObjectOptions{}) err := db.minio.RemoveObject(ctx, db.minioBucket, "users/"+userID.String()+"/"+hash+".webp", minio.RemoveObjectOptions{})
if err != nil { if err != nil {
return errors.Wrap(err, "deleting webp avatar") return errors.Wrap(err, "deleting webp avatar")
} }
err = db.minio.RemoveObject(ctx, db.minioBucket, "/users/"+userID.String()+"/"+hash+".jpg", minio.RemoveObjectOptions{}) err = db.minio.RemoveObject(ctx, db.minioBucket, "users/"+userID.String()+"/"+hash+".jpg", minio.RemoveObjectOptions{})
if err != nil { if err != nil {
return errors.Wrap(err, "deleting jpeg avatar") return errors.Wrap(err, "deleting jpeg avatar")
} }
@ -145,12 +145,12 @@ func (db *DB) DeleteUserAvatar(ctx context.Context, userID xid.ID, hash string)
} }
func (db *DB) DeleteMemberAvatar(ctx context.Context, memberID xid.ID, hash string) error { func (db *DB) DeleteMemberAvatar(ctx context.Context, memberID xid.ID, hash string) error {
err := db.minio.RemoveObject(ctx, db.minioBucket, "/members/"+memberID.String()+"/"+hash+".webp", minio.RemoveObjectOptions{}) err := db.minio.RemoveObject(ctx, db.minioBucket, "members/"+memberID.String()+"/"+hash+".webp", minio.RemoveObjectOptions{})
if err != nil { if err != nil {
return errors.Wrap(err, "deleting webp avatar") return errors.Wrap(err, "deleting webp avatar")
} }
err = db.minio.RemoveObject(ctx, db.minioBucket, "/members/"+memberID.String()+"/"+hash+".jpg", minio.RemoveObjectOptions{}) err = db.minio.RemoveObject(ctx, db.minioBucket, "members/"+memberID.String()+"/"+hash+".jpg", minio.RemoveObjectOptions{})
if err != nil { if err != nil {
return errors.Wrap(err, "deleting jpeg avatar") return errors.Wrap(err, "deleting jpeg avatar")
} }
@ -159,7 +159,7 @@ func (db *DB) DeleteMemberAvatar(ctx context.Context, memberID xid.ID, hash stri
} }
func (db *DB) UserAvatar(ctx context.Context, userID xid.ID, hash string) (io.ReadCloser, error) { func (db *DB) UserAvatar(ctx context.Context, userID xid.ID, hash string) (io.ReadCloser, error) {
obj, err := db.minio.GetObject(ctx, db.minioBucket, "/users/"+userID.String()+"/"+hash+".webp", minio.GetObjectOptions{}) obj, err := db.minio.GetObject(ctx, db.minioBucket, "users/"+userID.String()+"/"+hash+".webp", minio.GetObjectOptions{})
if err != nil { if err != nil {
return nil, errors.Wrap(err, "getting object") return nil, errors.Wrap(err, "getting object")
} }
@ -167,7 +167,7 @@ func (db *DB) UserAvatar(ctx context.Context, userID xid.ID, hash string) (io.Re
} }
func (db *DB) MemberAvatar(ctx context.Context, memberID xid.ID, hash string) (io.ReadCloser, error) { func (db *DB) MemberAvatar(ctx context.Context, memberID xid.ID, hash string) (io.ReadCloser, error) {
obj, err := db.minio.GetObject(ctx, db.minioBucket, "/members/"+memberID.String()+"/"+hash+".webp", minio.GetObjectOptions{}) obj, err := db.minio.GetObject(ctx, db.minioBucket, "members/"+memberID.String()+"/"+hash+".webp", minio.GetObjectOptions{})
if err != nil { if err != nil {
return nil, errors.Wrap(err, "getting object") return nil, errors.Wrap(err, "getting object")
} }

View file

@ -20,7 +20,7 @@ type DataExport struct {
} }
func (de DataExport) Path() string { func (de DataExport) Path() string {
return "/exports/" + de.UserID.String() + "/" + de.Filename + ".zip" return "exports/" + de.UserID.String() + "/" + de.Filename + ".zip"
} }
const ErrNoExport = errors.Sentinel("no data export exists") const ErrNoExport = errors.Sentinel("no data export exists")

View file

@ -69,7 +69,7 @@
Download your export file below: Download your export file below:
</p> </p>
<p> <p>
<Button color="primary" href="{PUBLIC_MEDIA_URL}{data.exportData.path}" target="_blank" <Button color="primary" href="{PUBLIC_MEDIA_URL}/{data.exportData.path}" target="_blank"
>Download data export</Button >Download data export</Button
> >
</p> </p>