feat: serve media on /media/, not separate domain
This commit is contained in:
parent
7b7b0ca15b
commit
d3eaaaaa9d
5 changed files with 109 additions and 11 deletions
|
@ -148,21 +148,23 @@ func (db *DB) WriteUserAvatar(ctx context.Context,
|
|||
jpegLocation string,
|
||||
err error,
|
||||
) {
|
||||
webpInfo, err := db.minio.PutObject(ctx, db.minioBucket, "/users/"+userID.String()+".webp", webp, -1, minio.PutObjectOptions{
|
||||
_, err = db.minio.PutObject(ctx, db.minioBucket, "/users/"+userID.String()+".webp", webp, -1, minio.PutObjectOptions{
|
||||
ContentType: "image/webp",
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "uploading webp avatar")
|
||||
}
|
||||
|
||||
jpegInfo, err := db.minio.PutObject(ctx, db.minioBucket, "/users/"+userID.String()+".jpg", jpeg, -1, minio.PutObjectOptions{
|
||||
_, err = db.minio.PutObject(ctx, db.minioBucket, "/users/"+userID.String()+".jpg", jpeg, -1, minio.PutObjectOptions{
|
||||
ContentType: "image/jpeg",
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "uploading jpeg avatar")
|
||||
}
|
||||
|
||||
return webpInfo.Location, jpegInfo.Location, nil
|
||||
return db.baseURL.JoinPath("/media/users/" + userID.String() + ".webp").String(),
|
||||
db.baseURL.JoinPath("/media/users/" + userID.String() + ".jpg").String(),
|
||||
nil
|
||||
}
|
||||
|
||||
func (db *DB) WriteMemberAvatar(ctx context.Context,
|
||||
|
@ -172,19 +174,21 @@ func (db *DB) WriteMemberAvatar(ctx context.Context,
|
|||
jpegLocation string,
|
||||
err error,
|
||||
) {
|
||||
webpInfo, err := db.minio.PutObject(ctx, db.minioBucket, "/members/"+memberID.String()+".webp", webp, -1, minio.PutObjectOptions{
|
||||
_, err = db.minio.PutObject(ctx, db.minioBucket, "/members/"+memberID.String()+".webp", webp, -1, minio.PutObjectOptions{
|
||||
ContentType: "image/webp",
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "uploading webp avatar")
|
||||
}
|
||||
|
||||
jpegInfo, err := db.minio.PutObject(ctx, db.minioBucket, "/members/"+memberID.String()+".jpg", jpeg, -1, minio.PutObjectOptions{
|
||||
_, err = db.minio.PutObject(ctx, db.minioBucket, "/members/"+memberID.String()+".jpg", jpeg, -1, minio.PutObjectOptions{
|
||||
ContentType: "image/jpeg",
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", errors.Wrap(err, "uploading jpeg avatar")
|
||||
}
|
||||
|
||||
return webpInfo.Location, jpegInfo.Location, nil
|
||||
return db.baseURL.JoinPath("/media/members/" + memberID.String() + ".webp").String(),
|
||||
db.baseURL.JoinPath("/media/members/" + memberID.String() + ".jpg").String(),
|
||||
nil
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"codeberg.org/u1f320/pronouns.cc/backend/log"
|
||||
|
@ -26,6 +27,7 @@ type DB struct {
|
|||
|
||||
minio *minio.Client
|
||||
minioBucket string
|
||||
baseURL *url.URL
|
||||
}
|
||||
|
||||
func New() (*DB, error) {
|
||||
|
@ -53,12 +55,18 @@ func New() (*DB, error) {
|
|||
return nil, errors.Wrap(err, "creating minio client")
|
||||
}
|
||||
|
||||
baseURL, err := url.Parse(os.Getenv("BASE_URL"))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "parsing base URL")
|
||||
}
|
||||
|
||||
db := &DB{
|
||||
Pool: pool,
|
||||
Redis: redis,
|
||||
|
||||
minio: minioClient,
|
||||
minioBucket: os.Getenv("MINIO_BUCKET"),
|
||||
baseURL: baseURL,
|
||||
}
|
||||
|
||||
return db, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue