-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1509c58
commit 25b8dd4
Showing
24 changed files
with
1,247 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package events | ||
|
||
type ( | ||
AccountCreated struct { | ||
ID int64 | ||
Email string | ||
} | ||
|
||
AccountProfileUpdated struct { | ||
ID int64 | ||
Name string | ||
About string | ||
Callsign string | ||
} | ||
|
||
AccountSessionOpened struct { | ||
ID int64 | ||
UserAgent string | ||
IP string | ||
} | ||
) | ||
|
||
func (AccountCreated) Event() string { return "account.created" } | ||
func (AccountProfileUpdated) Event() string { return "account.profile_updated" } | ||
func (AccountSessionOpened) Event() string { return "account.session_opened" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,5 @@ | ||
package events | ||
|
||
import "fmt" | ||
|
||
type subscriber struct { | ||
connection chan any | ||
} | ||
|
||
type Bus struct { | ||
subscribers map[string][]subscriber | ||
} | ||
|
||
func NewBus() *Bus { | ||
return &Bus{ | ||
subscribers: make(map[string][]subscriber), | ||
} | ||
} | ||
|
||
func (b *Bus) Subscribe(event any) chan any { | ||
c := make(chan any) | ||
s := subscriber{connection: c} | ||
b.subscribers[fmt.Sprintf("%T", event)] = append(b.subscribers[fmt.Sprintf("%T", event)], s) | ||
return c | ||
} | ||
|
||
func (b *Bus) Publish(event any) { | ||
for _, s := range b.subscribers[fmt.Sprintf("%T", event)] { | ||
s.connection <- event | ||
} | ||
type Event interface { | ||
Event() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package handlers | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/go-chi/chi" | ||
"github.com/ryanfaerman/netctl/internal/middleware" | ||
"github.com/ryanfaerman/netctl/internal/services" | ||
"github.com/ryanfaerman/netctl/internal/views" | ||
"github.com/ryanfaerman/netctl/web" | ||
"github.com/ryanfaerman/netctl/web/named" | ||
) | ||
|
||
type Markdown struct{} | ||
|
||
func init() { | ||
global.handlers = append(global.handlers, Markdown{}) | ||
} | ||
|
||
func (h Markdown) Routes(r chi.Router) { | ||
r.Use(middleware.HTMXOnly) | ||
web.CSRFExempt("/-/tools/markdown-render/*") | ||
r.Post(named.Route("markdown-preview", "/-/tools/markdown-render/{name}"), h.Preview) | ||
r.Post(named.Route("markdown-editor", "/-/tools/markdown-editor/{name}"), h.Editor) | ||
} | ||
|
||
func (h Markdown) Preview(w http.ResponseWriter, r *http.Request) { | ||
r.ParseForm() | ||
// ctx := services.CSRF.GetContext(r.Context(), r) | ||
field := chi.URLParam(r, "name") | ||
if field == "" { | ||
ErrorHandler(errors.New("no field name provided"))(w, r) | ||
return | ||
} | ||
|
||
attrs, err := views.DecodeInputAttrs(r.Form.Get(fmt.Sprintf("_%s-config", field))) | ||
if err != nil { | ||
ErrorHandler(err)(w, r) | ||
return | ||
} | ||
|
||
attrs.Value = r.Form.Get(field) | ||
attrs.MarkdownModePreview = true | ||
if attrs.Value != "" { | ||
attrs.MarkdownPreviewBody = services.Markdown.MustRenderString(attrs.Value) | ||
} | ||
|
||
views.InputTextArea(field, attrs).Render(r.Context(), w) | ||
} | ||
|
||
func (h Markdown) Editor(w http.ResponseWriter, r *http.Request) { | ||
r.ParseForm() | ||
// ctx := services.CSRF.GetContext(r.Context(), r) | ||
field := chi.URLParam(r, "name") | ||
if field == "" { | ||
ErrorHandler(errors.New("no field name provided"))(w, r) | ||
return | ||
} | ||
|
||
attrs, err := views.DecodeInputAttrs(r.Form.Get(fmt.Sprintf("_%s-config", field))) | ||
if err != nil { | ||
ErrorHandler(err)(w, r) | ||
return | ||
} | ||
|
||
attrs.Value = r.Form.Get(field) | ||
attrs.MarkdownModePreview = false | ||
|
||
views.InputTextArea(field, attrs).Render(r.Context(), w) | ||
} |
Oops, something went wrong.