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() { - Motr - - - - - - - - - - - - - - - - - - - - -} - -templ MetaComponent(m Metadata) { - { m.Title } - - - - - - - - - - - - - - - - - - - - -} diff --git a/pkg/metadata/metadata_templ.go b/pkg/metadata/metadata_templ.go deleted file mode 100644 index 1a8bf29..0000000 --- a/pkg/metadata/metadata_templ.go +++ /dev/null @@ -1,351 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.3.857 -package metadata - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import templruntime "github.com/a-h/templ/runtime" - -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 -} - -func DefaultMetaComponent() templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Motr") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - -func MetaComponent(m Metadata) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var2 := templ.GetChildren(ctx) - if templ_7745c5c3_Var2 == nil { - templ_7745c5c3_Var2 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(m.Title) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/metadata/metadata.templ`, Line: 76, Col: 17} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - -var _ = templruntime.GeneratedTemplate diff --git a/pkg/render/render.go b/pkg/render/render.go deleted file mode 100644 index 4e742c2..0000000 --- a/pkg/render/render.go +++ /dev/null @@ -1,41 +0,0 @@ -package render - -import ( - "bytes" - - "github.com/a-h/templ" - "github.com/labstack/echo/v4" -) - -type ( - EchoView func(c echo.Context) error - EchoViewFunc func(c echo.Context, b templ.Component) error - EchoPartialView func(c echo.Context) templ.Component -) - -func Page(cmp templ.Component) echo.HandlerFunc { - return func(c echo.Context) error { - return Component(c, cmp) - } -} - -func Component(c echo.Context, cmp templ.Component) error { - // Create a buffer to store the rendered HTML - buf := &bytes.Buffer{} - // Render the component to the buffer - err := cmp.Render(c.Request().Context(), buf) - if err != nil { - return err - } - - // Set the content type - c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) - - // Write the buffered content to the response - _, err = c.Response().Write(buf.Bytes()) - if err != nil { - return err - } - c.Response().WriteHeader(200) - return nil -}