removed stale account endpoints

This commit is contained in:
Roland Osborne 2022-03-09 11:27:50 -08:00
parent 2ae2f857f8
commit e25b95277c
4 changed files with 71 additions and 77 deletions

View File

@ -185,36 +185,6 @@ paths:
'500':
description: internal server error
/admin/accounts/{accountId}/image:
get:
tags:
- admin
description: Get profile image of specified account. Access granted to admin username and password
operationId: get-node-account-image
security:
- basicAuth: []
parameters:
- name: accountId
in: path
description: id of specified account
required: true
schema:
type: string
responses:
'200':
description: success
content:
application/octet-stream: # content specific
schema:
type: string
format: binary
'401':
description: permission denied
'405':
description: invalid image
'500':
description: internal server error
/admin/accounts/{accountId}:
delete:
tags:
@ -316,7 +286,32 @@ paths:
type: array
items:
$ref: '#/components/schemas/Profile'
'401':
description: permission denied
'500':
description: internal server error
/account/listing/{guid}/image:
get:
tags:
- account
description: Get profile image of searchable accounts. Endpoint is publically accessible.
operationId: get-account-listing-image
parameters:
- name: guid
in: path
description: filter for specified guid
required: true
schema:
type: string
responses:
'200':
description: success
content:
application/octet-stream: # content specific
schema:
type: string
format: binary
'401':
description: permission denied
'500':
@ -386,24 +381,6 @@ paths:
type: boolean
/account/profile:
get:
tags:
- account
description: Get account profile. Access granted to account's username and password.
operationId: get-account-profile
security:
- basicAuth: []
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Profile'
'401':
description: authentication error
'500':
description: internal server error
post:
tags:
- account

View File

@ -23,21 +23,6 @@ func GetAccountAsset(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
func GetAccountDid(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func GetAccountImage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func GetAccountProfile(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func RemoveAccount(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)

View File

@ -0,0 +1,39 @@
package databag
import (
"time"
"bytes"
"errors"
"net/http"
"gorm.io/gorm"
"databag/internal/store"
"encoding/base64"
)
func GetAccountListingImage(w http.ResponseWriter, r *http.Request) {
var account store.Account
if err := store.DB.Preload("AccountDetail").Where("searchable = ? AND disabled = ?", true, false).First(&account).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusNotFound, err)
} else {
ErrResponse(w, http.StatusInternalServerError, err)
}
return
}
if account.AccountDetail.Image == "" {
ErrResponse(w, http.StatusNotFound, errors.New("image not set"))
return
}
data, err := base64.StdEncoding.DecodeString(account.AccountDetail.Image)
if err != nil {
ErrResponse(w, http.StatusNotFound, errors.New("image not valid"))
return
}
// response with content
http.ServeContent(w, r, "image", time.Unix(account.Updated, 0), bytes.NewReader(data))
}

View File

@ -97,24 +97,17 @@ var routes = Routes{
},
Route{
"GetAccountDid",
"GetAccountListing",
strings.ToUpper("Get"),
"/account/did",
GetAccountDid,
"/account/listing",
GetAccountListing,
},
Route{
"GetAccountImage",
"GetAccountListingImage",
strings.ToUpper("Get"),
"/account/profile/image",
GetAccountImage,
},
Route{
"GetAccountProfile",
strings.ToUpper("Get"),
"/account/profile",
GetAccountProfile,
"/account/listing/{guid}/image",
GetAccountListingImage,
},
Route{