2024-09-13 13:02:32 +00:00
|
|
|
// TODO: Add EUPL banner everywhere
|
2024-08-28 15:20:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-09-27 14:53:22 +00:00
|
|
|
"embed"
|
|
|
|
"fmt"
|
2024-09-12 06:56:57 +00:00
|
|
|
"io"
|
2024-08-28 15:20:38 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
2024-09-27 14:53:22 +00:00
|
|
|
"time"
|
2024-08-28 15:20:38 +00:00
|
|
|
|
2024-09-27 14:53:22 +00:00
|
|
|
"github.com/go-webauthn/webauthn/webauthn"
|
|
|
|
"github.com/mstarongithub/passkey"
|
2024-08-28 15:20:38 +00:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
2024-09-27 14:53:22 +00:00
|
|
|
|
|
|
|
// "gitlab.com/mstarongitlab/linstrom/ap"
|
2024-08-28 15:20:38 +00:00
|
|
|
"gitlab.com/mstarongitlab/linstrom/config"
|
2024-09-27 14:53:22 +00:00
|
|
|
"gitlab.com/mstarongitlab/linstrom/server"
|
2024-09-12 06:56:57 +00:00
|
|
|
"gitlab.com/mstarongitlab/linstrom/storage"
|
|
|
|
"gitlab.com/mstarongitlab/linstrom/storage/cache"
|
2024-09-27 14:53:22 +00:00
|
|
|
"gitlab.com/mstarongitlab/linstrom/util"
|
2024-08-28 15:20:38 +00:00
|
|
|
)
|
|
|
|
|
2024-09-27 14:53:22 +00:00
|
|
|
//go:embed frontend-reactive/dist/* frontend-reactive/dist/assets
|
|
|
|
var reactiveFS embed.FS
|
|
|
|
|
|
|
|
//go:embed frontend-noscript
|
|
|
|
var nojsFS embed.FS
|
|
|
|
|
2024-08-28 15:20:38 +00:00
|
|
|
func main() {
|
2024-09-12 06:56:57 +00:00
|
|
|
setLogger()
|
2024-08-28 15:20:38 +00:00
|
|
|
setLogLevel()
|
|
|
|
if err := config.ReadAndWriteToGlobal(*flagConfigFile); err != nil {
|
|
|
|
log.Fatal().
|
|
|
|
Err(err).
|
|
|
|
Str("config-file", *flagConfigFile).
|
|
|
|
Msg("Failed to read config and couldn't write default")
|
|
|
|
}
|
2024-09-27 14:53:22 +00:00
|
|
|
// res, err := ap.GetAccountWebfinger("@aufricus_athudath@activitypub.academy")
|
|
|
|
// log.Info().
|
|
|
|
// Err(err).
|
|
|
|
// Any("webfinger", res).
|
|
|
|
// Msg("Webfinger request result for @aufricus_athudath@activitypub.academy")
|
2024-09-12 06:56:57 +00:00
|
|
|
storageCache, err := cache.NewCache(
|
|
|
|
config.GlobalConfig.Storage.MaxInMemoryCacheSize,
|
|
|
|
config.GlobalConfig.Storage.RedisUrl,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("Failed to start cache")
|
|
|
|
}
|
2024-09-15 13:18:05 +00:00
|
|
|
|
2024-09-16 15:42:16 +00:00
|
|
|
// var store *storage.Storage
|
|
|
|
// if config.GlobalConfig.Storage.DbIsPostgres != nil && *config.GlobalConfig.Storage.DbIsPostgres {
|
|
|
|
// store, err = storage.NewStoragePostgres(config.GlobalConfig.Storage.DatabaseUrl, storageCache)
|
|
|
|
// } else {
|
|
|
|
// store, err = storage.NewStorageSqlite(config.GlobalConfig.Storage.DatabaseUrl, storageCache)
|
|
|
|
// }
|
|
|
|
//
|
2024-09-15 13:18:05 +00:00
|
|
|
store, err := storage.NewStorage(config.GlobalConfig.Storage.BuildPostgresDSN(), storageCache)
|
|
|
|
|
2024-09-12 06:56:57 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("Failed to setup storage")
|
|
|
|
}
|
2024-09-27 14:53:22 +00:00
|
|
|
|
|
|
|
pkey, err := passkey.New(passkey.Config{
|
|
|
|
WebauthnConfig: &webauthn.Config{
|
|
|
|
RPDisplayName: "Linstrom",
|
|
|
|
RPID: "localhost",
|
|
|
|
RPOrigins: []string{"http://localhost:8000"},
|
|
|
|
},
|
|
|
|
UserStore: store,
|
|
|
|
SessionStore: store,
|
|
|
|
SessionMaxAge: time.Hour * 24,
|
|
|
|
}, passkey.WithLogger(&util.ZerologWrapper{}))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("Failed to setup passkey support")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(nojsFS.ReadDir("frontend-noscript"))
|
|
|
|
|
|
|
|
server := server.NewServer(
|
|
|
|
store,
|
|
|
|
pkey,
|
|
|
|
util.NewFSWrapper(reactiveFS, "frontend-reactive/dist/", true),
|
|
|
|
util.NewFSWrapper(nojsFS, "frontend-noscript/", true),
|
|
|
|
)
|
|
|
|
server.Start(":8000")
|
2024-09-13 13:02:32 +00:00
|
|
|
// TODO: Set up media server
|
2024-09-15 13:18:05 +00:00
|
|
|
// TODO: Set up queues
|
2024-09-13 13:02:32 +00:00
|
|
|
// TODO: Set up http server
|
|
|
|
// TODO: Set up plugins
|
|
|
|
// TODO: Start everything
|
2024-08-28 15:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setLogLevel() {
|
|
|
|
log.Info().Str("new-level", *flagLogLevel).Msg("Attempting to set log level")
|
|
|
|
switch strings.ToLower(*flagLogLevel) {
|
|
|
|
case "trace":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.TraceLevel)
|
|
|
|
case "debug":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
case "info":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
case "warn":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
|
|
|
case "error":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
|
|
|
|
case "fatal":
|
|
|
|
zerolog.SetGlobalLevel(zerolog.FatalLevel)
|
|
|
|
default:
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
}
|
|
|
|
}
|
2024-09-12 06:56:57 +00:00
|
|
|
|
|
|
|
func setLogger(extraLogWriters ...io.Writer) {
|
|
|
|
if *flagPrettyPrint {
|
|
|
|
console := zerolog.ConsoleWriter{Out: os.Stderr}
|
|
|
|
log.Logger = zerolog.New(zerolog.MultiLevelWriter(append([]io.Writer{console}, extraLogWriters...)...)).
|
|
|
|
With().
|
|
|
|
Timestamp().
|
|
|
|
Logger()
|
|
|
|
} else {
|
|
|
|
log.Logger = zerolog.New(zerolog.MultiLevelWriter(
|
|
|
|
append([]io.Writer{log.Logger}, extraLogWriters...)...,
|
|
|
|
)).With().Timestamp().Logger()
|
|
|
|
}
|
|
|
|
}
|