diff --git a/pkg/cookies/cookies.go b/pkg/cookies/cookies.go deleted file mode 100644 index 8ce9553..0000000 --- a/pkg/cookies/cookies.go +++ /dev/null @@ -1,141 +0,0 @@ -package cookies - -import ( - "encoding/base64" - "net/http" - "time" - - "github.com/labstack/echo/v4" -) - -// CookieKey is a type alias for string. -type CookieKey string - -const ( - // SessionID is the key for the session ID cookie. - SessionID CookieKey = "session.id" - - // SessionChallenge is the key for the session challenge cookie. - SessionChallenge CookieKey = "session.challenge" - - // SessionRole is the key for the session role cookie. - SessionRole CookieKey = "session.role" - - // SessionTTL is the key for the session TTL cookie. - SessionTTL CookieKey = "session.ttl" - - // SessionUser is the key for the session user cookie. - SessionUser CookieKey = "session.user" - - // SessionUserHandle is the key for the session user handle cookie. - SessionUserHandle CookieKey = "session.user.handle" - - // SessionVaultAddress is the key for the session vault address cookie. - SessionVaultAddress CookieKey = "session.vault.address" - - // SessionVaultCID is the key for the session vault CID cookie. - SessionVaultCID CookieKey = "session.vault.cid" - - // SessionVaultSchema is the key for the session vault schema cookie. - SessionVaultSchema CookieKey = "session.vault.schema" - - // User is the key for the User cookie. - User CookieKey = "user" - - // UserHandle is the key for the User Handle cookie. - UserHandle CookieKey = "user.handle" - - // VaultAddress is the key for the Vault address cookie. - VaultAddress CookieKey = "vault.address" - - // VaultCID is the key for the Vault CID cookie. - VaultCID CookieKey = "vault.cid" - - // VaultSchema is the key for the Vault schema cookie. - VaultSchema CookieKey = "vault.schema" -) - -// String returns the string representation of the CookieKey. -func (c CookieKey) String() string { - return string(c) -} - -// ╭───────────────────────────────────────────────────────────╮ -// │ Utility Methods │ -// ╰───────────────────────────────────────────────────────────╯ - -// Exists returns true if the request has the cookie Key. -func (k CookieKey) Exists(c echo.Context) bool { - ck, err := c.Cookie(k.String()) - return err == nil && ck != nil -} - -// MustEqual returns true if the request has the cookie Key. -func (k CookieKey) MustEqual(c echo.Context, value string) bool { - v, err := k.Read(c) - if err != nil { - return false - } - return v == value -} - -// Read returns the cookie value for the Key. -func (k CookieKey) Read(c echo.Context) (string, error) { - cookie, err := c.Cookie(k.String()) - if err != nil { - // Cookie not found or other error - return "", err - } - if cookie == nil || cookie.Value == "" { - // Cookie is empty - return "", http.ErrNoCookie - } - return cookie.Value, nil -} - -// ReadBytes returns the cookie value for the Key. -func (k CookieKey) ReadBytes(c echo.Context) ([]byte, error) { - cookie, err := c.Cookie(k.String()) - if err != nil { - // Cookie not found or other error - return nil, err - } - if cookie == nil || cookie.Value == "" { - // Cookie is empty - return nil, http.ErrNoCookie - } - return base64.RawURLEncoding.DecodeString(cookie.Value) -} - -// ReadUnsafe returns the cookie value for the Key. -func (k CookieKey) ReadUnsafe(c echo.Context) string { - ck, err := c.Cookie(k.String()) - if err != nil { - return "" - } - return ck.Value -} - -// Write sets the cooie value for the Key. -func (k CookieKey) Write(c echo.Context, value string) { - cookie := &http.Cookie{ - Name: k.String(), - Value: value, - Expires: time.Now().Add(24 * time.Hour), - HttpOnly: true, - Path: "/", - } - c.SetCookie(cookie) -} - -// WriteBytes sets the cookie value for the Key. -func (k CookieKey) WriteBytes(c echo.Context, value []byte) { - cookie := &http.Cookie{ - Name: k.String(), - Value: base64.RawURLEncoding.EncodeToString(value), - Expires: time.Now().Add(24 * time.Hour), - HttpOnly: true, - Path: "/", - } - c.SetCookie(cookie) -} diff --git a/pkg/headers/headers.go b/pkg/headers/headers.go deleted file mode 100644 index f4cb90a..0000000 --- a/pkg/headers/headers.go +++ /dev/null @@ -1,56 +0,0 @@ -//go:build js && wasm -// +build js,wasm - -package headers - -import "github.com/labstack/echo/v4" - -type HeaderKey string - -const ( - Authorization HeaderKey = "Authorization" - - // User Agent - Architecture HeaderKey = "Sec-CH-UA-Arch" - Bitness HeaderKey = "Sec-CH-UA-Bitness" - FullVersionList HeaderKey = "Sec-CH-UA-Full-Version-List" - Mobile HeaderKey = "Sec-CH-UA-Mobile" - Model HeaderKey = "Sec-CH-UA-Model" - Platform HeaderKey = "Sec-CH-UA-Platform" - PlatformVersion HeaderKey = "Sec-CH-UA-Platform-Version" - UserAgent HeaderKey = "Sec-CH-UA" - - // Sonr Injected - SonrAPIURL HeaderKey = "X-Sonr-API" - SonrgRPCURL HeaderKey = "X-Sonr-GRPC" - SonrRPCURL HeaderKey = "X-Sonr-RPC" - SonrWSURL HeaderKey = "X-Sonr-WS" -) - -func (h HeaderKey) String() string { - return string(h) -} - -// ╭───────────────────────────────────────────────────────────╮ -// │ Utility Methods │ -// ╰───────────────────────────────────────────────────────────╯ - -// MustEqual returns true if the request has the header Key. -func (k HeaderKey) MustEqual(c echo.Context, value string) bool { - return c.Response().Header().Get(k.String()) == value -} - -// Exists returns true if the request has the header Key. -func (k HeaderKey) Exists(c echo.Context) bool { - return c.Response().Header().Get(k.String()) != "" -} - -// Read returns the header value for the Key. -func (k HeaderKey) Read(c echo.Context) string { - return c.Response().Header().Get(k.String()) -} - -// Write sets the header value for the Key. -func (k HeaderKey) Write(c echo.Context, value string) { - c.Response().Header().Set(k.String(), value) -} diff --git a/pkg/metadata/metadata.templ b/pkg/metadata/metadata.templ deleted file mode 100644 index e27c227..0000000 --- a/pkg/metadata/metadata.templ +++ /dev/null @@ -1,97 +0,0 @@ -package metadata - -import "github.com/labstack/echo/v4" - -func GetMetadata(c echo.Context) Metadata { - return DefaultMetadata() -} - -func GetMetaComponent(c echo.Context) templ.Component { - return MetaComponent(GetMetadata(c)) -} - -func DefaultMetadata() Metadata { - return Metadata{ - Title: "Motr", - Author: "Sonr", - Favicon: "https://cdn.sonr.id/favicon.png", - Robots: "index, follow", - Googlebot: "index, follow", - Google: "nositelinkssearchbox", - Description: "Sonr is a decentralized social network that allows you to create your own personalized digital identity.", - Keywords: "Sonr, social network, decentralized, identity, decentralized social network, decentralized identity, self-sovereign identity, self-sovereign, self-sovereign social network, self-sovereign identity network, sso, sso network, sso identity, sso social network, digital identity, digital social network", - CanonicalURL: "https://sonr.io", - OGImage: "https://cdn.sonr.id/og.png", - OGURL: "https://sonr.io", - OGSiteName: "Sonr", - TwitterSite: "@sonr_io", - TwitterCreator: "@sonr_io", - TwitterImage: "https://cdn.sonr.id/og.png", - } -} - -type Metadata struct { - Title string - Author string - Favicon string - Robots string - Googlebot string - Google string - Description string - Keywords string - CanonicalURL string - OGImage string - OGURL string - OGSiteName string - TwitterSite string - TwitterCreator string - TwitterImage string -} - -templ DefaultMetaComponent() { -