Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-03-29 16:06:53 +08:00
commit 1b8f59a898
10 changed files with 68 additions and 37 deletions

View file

@ -1026,7 +1026,7 @@
"73": "Importing, please wait...",
"74": "The kernel has not been fully booted [%d%%], please try again later",
"75": "Attempt to access file failed",
"76": "TODO",
"76": "The network connectivity verification of the cloud storage service provider is abnormal, please check the network configuration",
"77": "Invalid dir path [%s]",
"78": "The old and new paths are repeated",
"79": "Only supports importing Markdown document",

View file

@ -1026,7 +1026,7 @@
"73": "Importando, por favor espere...",
"74": "El kernel no ha sido arrancado completamente [%d%%], por favor, inténtelo de nuevo más tarde",
"75": "Error al intentar acceder al archivo",
"76": "TODO",
"76": "La verificaci\u00f3n de conectividad de red del proveedor de servicios de almacenamiento en la nube es anormal, verifique la configuraci\u00f3n de red",
"77": "Ruta inválida [%s]",
"78": "Los viejos y nuevos caminos se repiten",
"79": "Sólo admite la importación de documentos Markdown",

View file

@ -1026,7 +1026,7 @@
"73": "En cours d'importation, veuillez patienter...",
"74": "Le kernel n'a pas été complètement démarré [%d%%], veuillez réessayer plus tard.",
"75": "La tentative d'accès au fichier a échoué",
"76": "TODO",
"76": "La vérification de la connectivité réseau du fournisseur de service de stockage cloud est anormale, veuillez vérifier la configuration réseau",
"77": "Chemin d'accès invalide [%s]",
"78": "Les anciens et les nouveaux chemins sont répétés",
"79": "Prise en charge de l'importation de documents Markdown uniquement",

View file

@ -1026,7 +1026,7 @@
"73": "正在導入,請稍等...",
"74": "kernel尚未完全啟動 [%d%%],請稍後再試",
"75": "嘗試訪問資料檔失敗",
"76": "TODO",
"76": "雲端存儲服務提供商網絡連通性校驗異常,請檢查網絡配置",
"77": "不可用的目錄路徑 [%s]",
"78": "新老路徑重複",
"79": "僅支援導入 Markdown 文檔",

View file

@ -1026,7 +1026,7 @@
"73": "正在导入,请稍等...",
"74": "内核尚未完全启动 [%d%%],请稍后再试",
"75": "尝试访问文件失败",
"76": "TODO",
"76": "云端存储服务提供商网络连通性校验异常,请检查网络配置",
"77": "不可用的目录路径 [%s]",
"78": "新老路径重复",
"79": "仅支持导入 Markdown 文档",

View file

@ -945,23 +945,10 @@ powerMonitor.on("suspend", () => {
powerMonitor.on("resume", async () => {
// 桌面端系统休眠唤醒后判断网络连通性后再执行数据同步 https://github.com/siyuan-note/siyuan/issues/6687
writeLog("system resume");
const eNet = require("electron").net
const isOnline = async () => {
try {
const result = await fetch("https://www.baidu.com", {timeout: 1000});
return 200 === result.status;
} catch (e) {
try {
const result = await fetch("https://icanhazip.com", {timeout: 1000});
return 200 === result.status;
} catch (e) {
try {
const result = await fetch("https://api.ipify.org", {timeout: 1000});
return 200 === result.status;
} catch (e) {
return false;
}
}
}
return eNet.isOnline()
};
let online = false;
for (let i = 0; i < 7; i++) {

View file

@ -62,3 +62,7 @@ const (
ProviderS3 = 2 // ProviderS3 为 S3 协议对象存储提供的云端存储服务
ProviderWebDAV = 3 // ProviderWebDAV 为 WebDAV 协议提供的云端存储服务
)
func NewSyncProviderCheckURL() string {
return "https://www.baidu.com"
}

View file

@ -297,7 +297,7 @@ func InitConf() {
if 0 > Conf.Editor.BacklinkExpandCount {
Conf.Editor.BacklinkExpandCount = 0
}
if 0> Conf.Editor.BackmentionExpandCount {
if 0 > Conf.Editor.BackmentionExpandCount {
Conf.Editor.BackmentionExpandCount = 0
}

View file

@ -46,7 +46,7 @@ func SyncDataDownload() {
}
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
if !util.IsOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)
return
}
@ -82,7 +82,7 @@ func SyncDataUpload() {
}
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
if !util.IsOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)
return
}
@ -136,7 +136,7 @@ func BootSyncData() {
return
}
if !util.IsOnline() {
if !isProviderOnline() {
BootSyncSucc = 1
util.PushErrMsg(Conf.Language(28), 7000)
return
@ -182,7 +182,7 @@ func syncData(boot, exit, byHand bool) {
}
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
if !util.IsOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
if !isProviderOnline() { // 这个操作比较耗时,所以要先推送 syncing 事件后再判断网络,这样才能给用户更即时的反馈
util.BroadcastByType("main", "syncing", 2, Conf.Language(28), nil)
return
}
@ -565,3 +565,22 @@ func IncSync() {
func planSyncAfter(d time.Duration) {
syncPlanTime = time.Now().Add(d)
}
func isProviderOnline() (ret bool) {
checkURL := util.SiYuanSyncServer
switch Conf.Sync.Provider {
case conf.ProviderSiYuan:
case conf.ProviderS3:
checkURL = Conf.Sync.S3.Endpoint
case conf.ProviderWebDAV:
checkURL = Conf.Sync.WebDAV.Endpoint
default:
logging.LogWarnf("unknown provider: %d", Conf.Sync.Provider)
util.IsOnline("")
}
if ret = util.IsOnline(checkURL); !ret {
util.PushErrMsg(Conf.Language(76), 5000)
}
return
}

View file

@ -18,6 +18,7 @@ package util
import (
"net/http"
"net/url"
"strings"
"time"
@ -30,21 +31,36 @@ import (
"github.com/siyuan-note/logging"
)
func IsOnline() (ret bool) {
c := req.C().SetTimeout(1 * time.Second)
resp, err := c.R().Head("https://www.baidu.com")
if nil != err {
resp, err = c.R().Head("https://icanhazip.com")
if nil != err {
resp, err = c.R().Head("https://api.ipify.org")
func IsOnline(checkURL string) bool {
if "" == checkURL {
if isOnline("https://www.baidu.com") {
return true
}
if isOnline("https://icanhazip.com") {
return true
}
if isOnline("https://api.ipify.org") {
return true
}
logging.LogWarnf("network is offline")
return false
}
ret = nil == err && nil != resp && nil != resp.Response
if !ret {
logging.LogWarnf("network is offline: %v", err)
if isOnline(checkURL) {
return true
}
return
logging.LogWarnf("network is offline [checkURL=%s]", checkURL)
return false
}
func isOnline(checkURL string) bool {
c := req.C().SetTimeout(1 * time.Second)
_, err := c.R().Head("https://www.baidu.com")
return nil == err
}
func GetRemoteAddr(session *melody.Session) string {
@ -82,6 +98,11 @@ func InvalidIDPattern(idArg string, result *gulu.Result) bool {
return true
}
func IsValidURL(str string) bool {
_, err := url.Parse(str)
return nil == err
}
func initHttpClient() {
http.DefaultClient = httpclient.GetCloudFileClient2Min()
http.DefaultTransport = httpclient.NewTransport(false)