2022-02-10 05:39:48 +00:00
|
|
|
package databag
|
|
|
|
|
|
|
|
import (
|
2022-03-02 08:01:01 +00:00
|
|
|
"time"
|
|
|
|
"bytes"
|
2022-02-10 05:39:48 +00:00
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
"encoding/base64"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetProfileImage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var data []byte
|
|
|
|
|
2022-03-20 04:04:14 +00:00
|
|
|
account, code, err := ParamAgentToken(r, true);
|
2022-02-10 05:39:48 +00:00
|
|
|
if err != nil {
|
|
|
|
ErrResponse(w, code, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if account.AccountDetail.Image == "" {
|
|
|
|
ErrResponse(w, http.StatusNotFound, errors.New("profile image not set"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err = base64.StdEncoding.DecodeString(account.AccountDetail.Image)
|
|
|
|
if err != nil {
|
|
|
|
ErrResponse(w, http.StatusNotFound, errors.New("profile image not valid"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-02 08:01:01 +00:00
|
|
|
// response with content
|
|
|
|
http.ServeContent(w, r, "image", time.Unix(account.Updated, 0), bytes.NewReader(data))
|
2022-02-10 05:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|