mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-08 05:32:33 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
790493097c
8 changed files with 116 additions and 22 deletions
|
|
@ -1133,7 +1133,7 @@
|
|||
"appearance1": "Tema del bloque de código",
|
||||
"appearance10": "Configuración del botón de cierre",
|
||||
"appearance11": "Minimizar a la bandeja del sistema después de hacer clic en el botón de cierre",
|
||||
"appearance16": "Ocultar la barra de estado inferior",
|
||||
"appearance16": "Barra de estado inferior",
|
||||
"appearance17": "Al habilitar, la barra de estado se ocultará",
|
||||
"appearance18": "Configurar el interruptor de mensajes de la barra de estado",
|
||||
"min": "Minimizar",
|
||||
|
|
@ -1389,24 +1389,24 @@
|
|||
"_label": "Español",
|
||||
"_time": {
|
||||
"albl": "hace",
|
||||
"blbl": "a partir de ahora",
|
||||
"blbl": "en",
|
||||
"now": "ahora",
|
||||
"1s": "1 segundo %s",
|
||||
"xs": "%d segundos %s",
|
||||
"1m": "1 minuto %s",
|
||||
"xm": "%d minutos %s",
|
||||
"1h": "1 hora %s",
|
||||
"xh": "%d horas %s",
|
||||
"1d": "1 día %s",
|
||||
"xd": "%d días %s",
|
||||
"1w": "1 semana %s",
|
||||
"xw": "%d semanas %s",
|
||||
"1M": "1 mes %s",
|
||||
"xM": "%d meses %s",
|
||||
"1y": "1 año %s",
|
||||
"2y": "2 años %s",
|
||||
"xy": "%d años %s",
|
||||
"max": "mucho tiempo %s"
|
||||
"1s": "%s 1 segundo",
|
||||
"xs": "%s %d segundos",
|
||||
"1m": "%s 1 minuto",
|
||||
"xm": "%s %d minutos",
|
||||
"1h": "%s 1 hora",
|
||||
"xh": "%s %d horas",
|
||||
"1d": "%s 1 día",
|
||||
"xd": "%s %d días",
|
||||
"1w": "%s 1 semana",
|
||||
"xw": "%s %d semanas",
|
||||
"1M": "%s 1 mes",
|
||||
"xM": "%s %d meses",
|
||||
"1y": "%s 1 año",
|
||||
"2y": "%s 2 años",
|
||||
"xy": "%s %d años",
|
||||
"max": "%s mucho tiempo"
|
||||
},
|
||||
"_taskAction": {
|
||||
"task.repo.checkout": "Ejecutar el pago desde la instantánea",
|
||||
|
|
@ -1459,7 +1459,7 @@
|
|||
"13": "No se puede crear un archivo que empiece por .",
|
||||
"14": "Exportación fallida: %s",
|
||||
"15": "No se encontró el bloque de contenido con id [%s]",
|
||||
"16": "Intitulado",
|
||||
"16": "Sin título",
|
||||
"17": "La sincronización inicial falló en el arranque. Puede producirse una sobreescritura de datos imprevisible si continúa operando. Por favor, realice primero una sincronización",
|
||||
"18": "Falló la obtención de la cuenta de usuario de la comunidad",
|
||||
"19": "La información del usuario ha caducado, por favor, inicie sesión de nuevo",
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import {initMessage} from "./dialog/message";
|
|||
import {getAllTabs} from "./layout/getAll";
|
||||
import {getLocalStorage} from "./protyle/util/compatibility";
|
||||
import {getSearch} from "./util/functions";
|
||||
import {checkPublishServiceClosed} from "./util/processMessage";
|
||||
import {hideAllElements} from "./protyle/ui/hideElements";
|
||||
import {loadPlugins, reloadPlugin} from "./plugin/loader";
|
||||
import "./assets/scss/base.scss";
|
||||
|
|
@ -46,6 +47,9 @@ export class App {
|
|||
public appId: string;
|
||||
|
||||
constructor() {
|
||||
if (checkPublishServiceClosed()) {
|
||||
return;
|
||||
}
|
||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||
addBaseURL();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
|
|||
import {getLocalStorage, writeText} from "../protyle/util/compatibility";
|
||||
import {getCurrentEditor, openMobileFileById} from "./editor";
|
||||
import {getSearch} from "../util/functions";
|
||||
import {checkPublishServiceClosed} from "../util/processMessage";
|
||||
import {initRightMenu} from "./menu";
|
||||
import {openChangelog} from "../boot/openChangelog";
|
||||
import {registerServiceWorker} from "../util/serviceWorker";
|
||||
|
|
@ -37,6 +38,9 @@ class App {
|
|||
public appId: string;
|
||||
|
||||
constructor() {
|
||||
if (checkPublishServiceClosed()) {
|
||||
return;
|
||||
}
|
||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||
addBaseURL();
|
||||
this.appId = Constants.SIYUAN_APPID;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {hideMessage, showMessage} from "../dialog/message";
|
|||
import {setStorageVal} from "../protyle/util/compatibility";
|
||||
import {Constants} from "../constants";
|
||||
import {fetchPost} from "./fetch";
|
||||
import {isBrowser} from "./functions";
|
||||
|
||||
export const processMessage = (response: IWebSocketData) => {
|
||||
if ("msg" === response.cmd) {
|
||||
|
|
@ -61,6 +62,10 @@ export const processMessage = (response: IWebSocketData) => {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
if ("closepublishpage" === response.cmd) {
|
||||
handlePublishServiceClosed(response.msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 小于 0 为提示:-2 提示;-1 报错,大于 0 的错误需处理,等于 0 的为正常操作
|
||||
if (response.code < 0) {
|
||||
|
|
@ -70,3 +75,22 @@ export const processMessage = (response: IWebSocketData) => {
|
|||
|
||||
return response;
|
||||
};
|
||||
|
||||
export const handlePublishServiceClosed = (msg: string) => {
|
||||
if (isBrowser()) {
|
||||
sessionStorage.setItem("siyuanPublishServiceClosed", msg || "");
|
||||
window.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
export const checkPublishServiceClosed = (): boolean => {
|
||||
if (isBrowser()) {
|
||||
const publishServiceClosedMsg = sessionStorage.getItem("siyuanPublishServiceClosed");
|
||||
if (publishServiceClosedMsg) {
|
||||
sessionStorage.removeItem("siyuanPublishServiceClosed");
|
||||
document.body.innerHTML = `<div style="display:flex;align-items:center;justify-content:center;height:100vh">${publishServiceClosedMsg}</div>`;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -159,3 +159,15 @@ func GetClaimRole(claims jwt.MapClaims) Role {
|
|||
}
|
||||
return RoleVisitor
|
||||
}
|
||||
|
||||
// IsPublishServiceToken 检查 token 是否来自发布服务
|
||||
func IsPublishServiceToken(token *jwt.Token) bool {
|
||||
if token == nil || !token.Valid {
|
||||
return false
|
||||
}
|
||||
claims := GetTokenClaims(token)
|
||||
if tokenIssuer, ok := claims["iss"].(string); ok {
|
||||
return tokenIssuer == iss
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ func initPublishService() {
|
|||
if err := initPublishListener(); err == nil {
|
||||
go startPublishReverseProxyService()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func initPublishListener() (err error) {
|
||||
|
|
@ -93,6 +92,9 @@ func closePublishListener() {
|
|||
return
|
||||
}
|
||||
|
||||
// 关闭所有发布服务的 WebSocket 连接
|
||||
util.ClosePublishServiceSessions()
|
||||
|
||||
if err := server.Shutdown(context.Background()); err != nil {
|
||||
logging.LogErrorf("shutdown server failed: %s", err)
|
||||
}
|
||||
|
|
@ -101,7 +103,6 @@ func closePublishListener() {
|
|||
logging.LogErrorf("close server failed: %s", err)
|
||||
}
|
||||
server, listener = nil, nil
|
||||
return
|
||||
}
|
||||
|
||||
func startPublishReverseProxyService() {
|
||||
|
|
|
|||
|
|
@ -671,6 +671,13 @@ func serveWebSocket(ginServer *gin.Engine) {
|
|||
return
|
||||
}
|
||||
|
||||
// 标记发布服务的连接
|
||||
if token := model.ParseXAuthToken(s.Request); token != nil {
|
||||
if model.IsPublishServiceToken(token) {
|
||||
s.Set("isPublish", true)
|
||||
}
|
||||
}
|
||||
|
||||
util.AddPushChan(s)
|
||||
//sessionId, _ := s.Get("id")
|
||||
//logging.LogInfof("ws [%s] connected", sessionId)
|
||||
|
|
|
|||
|
|
@ -177,7 +177,6 @@ func PushTxErr(msg string, code int, data interface{}) {
|
|||
|
||||
func PushUpdateMsg(msgId string, msg string, timeout int) {
|
||||
BroadcastByType("main", "msg", 0, msg, map[string]interface{}{"id": msgId, "closeTimeout": timeout})
|
||||
return
|
||||
}
|
||||
|
||||
func PushMsg(msg string, timeout int) (msgId string) {
|
||||
|
|
@ -454,3 +453,46 @@ func CountSessions() (ret int) {
|
|||
})
|
||||
return
|
||||
}
|
||||
|
||||
// ClosePublishServiceSessions 关闭所有发布服务的 WebSocket 连接
|
||||
func ClosePublishServiceSessions() {
|
||||
if WebSocketServer == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 收集所有发布服务的会话
|
||||
var publishSessions []*melody.Session
|
||||
sessions.Range(func(key, value interface{}) bool {
|
||||
appSessions := value.(*sync.Map)
|
||||
appSessions.Range(func(key, value interface{}) bool {
|
||||
session := value.(*melody.Session)
|
||||
if isPublish, ok := session.Get("isPublish"); ok && isPublish == true {
|
||||
publishSessions = append(publishSessions, session)
|
||||
}
|
||||
return true
|
||||
})
|
||||
return true
|
||||
})
|
||||
|
||||
// 发送消息通知客户端关闭页面
|
||||
for _, session := range publishSessions {
|
||||
event := NewResult()
|
||||
event.Cmd = "closepublishpage"
|
||||
event.Code = 0
|
||||
event.Msg = "SiYuan publish service closed"
|
||||
event.Data = map[string]interface{}{
|
||||
"reason": "publish service closed",
|
||||
}
|
||||
session.Write(event.Bytes())
|
||||
}
|
||||
|
||||
// 等待一小段时间让消息发送完成、客户端刷新页面之后显示消息
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// 关闭所有发布服务的 WebSocket 连接
|
||||
for _, session := range publishSessions {
|
||||
// 使用 "close websocket" 作为关闭消息,客户端检测到后会停止重连
|
||||
session.CloseWithMsg([]byte(" close websocket: publish service closed"))
|
||||
RemovePushChan(session)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue