mirror of
https://github.com/go-gitea/gitea
synced 2025-02-10 18:57:00 +01:00
finish
This commit is contained in:
parent
9ace44c6b1
commit
78b94ff85b
@ -4,8 +4,7 @@
|
||||
package websocket
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/olahol/melody"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
@ -17,7 +16,7 @@ var m *melody.Melody
|
||||
|
||||
type websocketMessage struct {
|
||||
Action string `json:"action"`
|
||||
Data string `json:"data"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
type subscribeMessageData struct {
|
||||
@ -68,9 +67,10 @@ func handleMessage(s *melody.Session, _msg []byte) {
|
||||
}
|
||||
|
||||
func handleSubscribeMessage(data *sessionData, _data any) error {
|
||||
msgData, ok := _data.(*subscribeMessageData)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid message data")
|
||||
msgData := &subscribeMessageData{}
|
||||
err := mapstructure.Decode(_data, &msgData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data.onURL = msgData.URL
|
||||
|
@ -29,7 +29,7 @@
|
||||
{{template "base/head_style" .}}
|
||||
{{template "custom/header" .}}
|
||||
</head>
|
||||
<body hx-headers='{"x-csrf-token": "{{.CsrfToken}}"}' hx-swap="outerHTML" hx-ext="morph" hx-push-url="false" hx-ext="ws" ws-connect="/-/ws">
|
||||
<body hx-headers='{"x-csrf-token": "{{.CsrfToken}}"}' hx-swap="outerHTML" hx-ext="morph,ws" hx-push-url="false" ws-connect="/-/ws">
|
||||
{{ctx.DataRaceCheck $.Context}}
|
||||
{{template "custom/body_outer_pre" .}}
|
||||
|
||||
|
@ -20,3 +20,8 @@ document.body.addEventListener('htmx:responseError', (event) => {
|
||||
// TODO: add translations
|
||||
showErrorToast(`Error ${event.detail.xhr.status} when calling ${event.detail.requestConfig.path}`);
|
||||
});
|
||||
|
||||
document.body.addEventListener('htmx:wsOpen', (evt) => {
|
||||
const socket = evt.detail.socketWrapper;
|
||||
socket.send(JSON.stringify({action: 'subscribe', data: {url: window.location.href}}));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user