Merge branch 'main' of gitlab.com:mstarongitlab/linstrom
also delete server-old with all its problems
This commit is contained in:
commit
d99efca667
47 changed files with 2200 additions and 694 deletions
38
server/endpoints_ap.go
Normal file
38
server/endpoints_ap.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"gitlab.com/mstarongitlab/linstrom/storage"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Mount under /.well-known/webfinger
|
||||
func webfingerHandler(w http.ResponseWriter, r *http.Request) {
|
||||
logger := zerolog.Ctx(r.Context())
|
||||
store := storage.Storage{}
|
||||
|
||||
requestedResource := r.FormValue("resource")
|
||||
if requestedResource == "" {
|
||||
http.Error(w, "bad request. Include \"resource\" parameter", http.StatusBadRequest)
|
||||
logger.Debug().Msg("Resource parameter missing. Cancelling")
|
||||
return
|
||||
}
|
||||
accName := strings.TrimPrefix(requestedResource, "acc:")
|
||||
acc, err := store.FindAccountByFullHandle(accName)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
http.Error(w, "account not found", http.StatusNotFound)
|
||||
logger.Debug().Str("account-name", accName).Msg("Account not found")
|
||||
} else {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
logger.Error().Err(err).Msg("Error while searching for account")
|
||||
return
|
||||
}
|
||||
}
|
||||
fmt.Fprint(w, acc)
|
||||
}
|
13
server/remoteServer/remoteServer.go
Normal file
13
server/remoteServer/remoteServer.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package remotestorage
|
||||
|
||||
import "gitlab.com/mstarongitlab/linstrom/storage"
|
||||
|
||||
// Wrapper around db storage
|
||||
// storage.Storage is for the db and cache access only,
|
||||
// while this one wraps storage.Storage to also provide remote fetching of missing resources.
|
||||
// So if an account doesn't exist in db or cache, this wrapper will attempt to fetch it
|
||||
type RemoteStorage struct {
|
||||
store *storage.Storage
|
||||
}
|
||||
|
||||
// TODO: Implement just about everything storage has, but with remote fetching if storage fails
|
Loading…
Add table
Add a link
Reference in a new issue