mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 11:39:17 +00:00
34 lines
673 B
Go
34 lines
673 B
Go
|
package databag
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"net/http"
|
||
|
"encoding/base64"
|
||
|
)
|
||
|
|
||
|
func GetProfileImage(w http.ResponseWriter, r *http.Request) {
|
||
|
var data []byte
|
||
|
|
||
|
account, code, err := BearerAppToken(r, true);
|
||
|
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
|
||
|
}
|
||
|
|
||
|
w.Header().Set("Content-Type", http.DetectContentType(data))
|
||
|
w.Write(data);
|
||
|
}
|
||
|
|
||
|
|