Merge branch 'main' of gitlab.com:mstarongitlab/linstrom

also delete server-old with all its problems
This commit is contained in:
Melody Becker 2024-09-13 20:41:47 +02:00
commit d99efca667
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
47 changed files with 2200 additions and 694 deletions

38
server/endpoints_ap.go Normal file
View 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)
}

View 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