Lots of work
This commit is contained in:
parent
a2a937791d
commit
3086b0e9b4
28 changed files with 1284 additions and 2 deletions
36
server/endpoints_ap.go
Normal file
36
server/endpoints_ap.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"gitlab.com/mstarongitlab/linstrom/server/middlewares"
|
||||
"gitlab.com/mstarongitlab/linstrom/storage"
|
||||
)
|
||||
|
||||
// Mount under /.well-known/webfinger
|
||||
func webfingerHandler(w http.ResponseWriter, r *http.Request) {
|
||||
logEntry, ok := r.Context().Value(middlewares.CONTEXT_KEY_LOGRUS).(*logrus.Entry)
|
||||
if !ok {
|
||||
http.Error(w, "couldn't get logging entry from context", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
store := storage.Storage{}
|
||||
|
||||
requestedResource := r.FormValue("resource")
|
||||
if requestedResource == "" {
|
||||
http.Error(w, "bad request. Include \"resource\" parameter", http.StatusBadRequest)
|
||||
logEntry.Infoln("No resource parameter. Cancelling")
|
||||
return
|
||||
}
|
||||
accName := strings.TrimPrefix(requestedResource, "acc:")
|
||||
acc, err := store.FindLocalAccount(accName)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
logEntry.WithError(err).Warningln("couldn't find account")
|
||||
return
|
||||
}
|
||||
fmt.Fprint(w, acc)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue