mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-14 19:18:06 +01:00
♻️ 内核中的 HTTP 客户端拆分项目 https://github.com/siyuan-note/siyuan/issues/5269
This commit is contained in:
parent
25ddad5957
commit
779e4fc4ae
13 changed files with 59 additions and 150 deletions
|
|
@ -36,6 +36,7 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -91,7 +92,7 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
|||
}
|
||||
}
|
||||
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(119), u), 15000)
|
||||
request := util.NewBrowserRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewBrowserRequest(Conf.System.NetworkProxy.String())
|
||||
resp, reqErr := request.Get(u)
|
||||
if nil != reqErr {
|
||||
util.LogErrorf("download net img [%s] failed: %s", u, reqErr)
|
||||
|
|
@ -285,7 +286,7 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
|
|||
}
|
||||
|
||||
requestResult := gulu.Ret.NewResult()
|
||||
request := util.NewCloudFileRequest2m(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudFileRequest2m(Conf.System.NetworkProxy.String())
|
||||
resp, reqErr := request.
|
||||
SetResult(requestResult).
|
||||
SetFile("file[]", absAsset).
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -37,7 +38,7 @@ func StartFreeTrial() (err error) {
|
|||
}
|
||||
|
||||
requestResult := gulu.Ret.NewResult()
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
_, err = request.
|
||||
SetResult(requestResult).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
|
|
@ -54,7 +55,7 @@ func StartFreeTrial() (err error) {
|
|||
|
||||
func DeactivateUser() (err error) {
|
||||
requestResult := gulu.Ret.NewResult()
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(requestResult).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
|
|
@ -79,7 +80,7 @@ func DeactivateUser() (err error) {
|
|||
func SetCloudBlockReminder(id, data string, timed int64) (err error) {
|
||||
requestResult := gulu.Ret.NewResult()
|
||||
payload := map[string]interface{}{"dataId": id, "data": data, "timed": timed}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(requestResult).
|
||||
SetBody(payload).
|
||||
|
|
@ -112,7 +113,7 @@ func LoadUploadToken() (err error) {
|
|||
}
|
||||
|
||||
requestResult := gulu.Ret.NewResult()
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(requestResult).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
|
|
@ -251,7 +252,7 @@ func loadUserFromConf() *conf.User {
|
|||
|
||||
func RemoveCloudShorthands(ids []string) (err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
body := map[string]interface{}{
|
||||
"ids": ids,
|
||||
}
|
||||
|
|
@ -282,7 +283,7 @@ func RemoveCloudShorthands(ids []string) (err error) {
|
|||
|
||||
func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
|
||||
result = map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
|
|
@ -319,7 +320,7 @@ var errInvalidUser = errors.New("invalid user")
|
|||
|
||||
func getUser(token string) (*conf.User, error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
_, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"token": token}).
|
||||
|
|
@ -350,7 +351,7 @@ func getUser(token string) (*conf.User, error) {
|
|||
|
||||
func UseActivationcode(code string) (err error) {
|
||||
requestResult := gulu.Ret.NewResult()
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
_, err = request.
|
||||
SetResult(requestResult).
|
||||
SetBody(map[string]string{"data": code}).
|
||||
|
|
@ -369,7 +370,7 @@ func UseActivationcode(code string) (err error) {
|
|||
func CheckActivationcode(code string) (retCode int, msg string) {
|
||||
retCode = 1
|
||||
requestResult := gulu.Ret.NewResult()
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
_, err := request.
|
||||
SetResult(requestResult).
|
||||
SetBody(map[string]string{"data": code}).
|
||||
|
|
@ -389,7 +390,7 @@ func CheckActivationcode(code string) (retCode int, msg string) {
|
|||
|
||||
func Login(userName, password, captcha string) (ret *gulu.Result, err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
_, err = request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"userName": userName, "userPassword": password, "captcha": captcha}).
|
||||
|
|
@ -415,7 +416,7 @@ func Login(userName, password, captcha string) (ret *gulu.Result, err error) {
|
|||
|
||||
func Login2fa(token, code string) (map[string]interface{}, error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
_, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"twofactorAuthCode": code}).
|
||||
|
|
|
|||
|
|
@ -34,12 +34,13 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
"github.com/qiniu/go-sdk/v7/storage"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"token": Conf.User.UserToken}).
|
||||
|
|
@ -69,7 +70,7 @@ func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, e
|
|||
|
||||
func removeCloudDirPath(dirPath string) (err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"dirPath": dirPath, "token": Conf.User.UserToken}).
|
||||
|
|
@ -94,7 +95,7 @@ func removeCloudDirPath(dirPath string) (err error) {
|
|||
|
||||
func createCloudSyncDirOSS(name string) (err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"name": name, "token": Conf.User.UserToken}).
|
||||
|
|
@ -125,7 +126,7 @@ func createCloudSyncDirOSS(name string) (err error) {
|
|||
|
||||
func listCloudSyncDirOSS() (dirs []map[string]interface{}, size int64, err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetBody(map[string]interface{}{"token": Conf.User.UserToken}).
|
||||
SetResult(&result).
|
||||
|
|
@ -277,7 +278,7 @@ func ossDownload0(localDirPath, cloudDirPath, fetch string, fetchedFiles *int, t
|
|||
localFilePath := filepath.Join(localDirPath, fetch)
|
||||
remoteFileURL := path.Join(cloudDirPath, fetch)
|
||||
var result map[string]interface{}
|
||||
resp, err := util.NewCloudRequest(Conf.System.NetworkProxy.String()).
|
||||
resp, err := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String()).
|
||||
SetResult(&result).
|
||||
SetBody(map[string]interface{}{"token": Conf.User.UserToken, "path": remoteFileURL}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/data/getSiYuanFile?uid=" + Conf.User.UserId)
|
||||
|
|
@ -312,9 +313,9 @@ func ossDownload0(localDirPath, cloudDirPath, fetch string, fetchedFiles *int, t
|
|||
os.Remove(localFilePath)
|
||||
|
||||
if bootORExit {
|
||||
resp, err = util.NewCloudFileRequest15s(Conf.System.NetworkProxy.String()).Get(downloadURL)
|
||||
resp, err = httpclient.NewCloudFileRequest15s(Conf.System.NetworkProxy.String()).Get(downloadURL)
|
||||
} else {
|
||||
resp, err = util.NewCloudFileRequest2m(Conf.System.NetworkProxy.String()).Get(downloadURL)
|
||||
resp, err = httpclient.NewCloudFileRequest2m(Conf.System.NetworkProxy.String()).Get(downloadURL)
|
||||
}
|
||||
if nil != err {
|
||||
util.LogErrorf("download request [%s] failed: %s", downloadURL, err)
|
||||
|
|
@ -457,7 +458,7 @@ func ossRemove0(cloudDirPath string, removes []string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetBody(map[string]interface{}{"token": Conf.User.UserToken, "dirPath": cloudDirPath, "paths": removes}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/data/removeSiYuanFile?uid=" + Conf.User.UserId)
|
||||
|
|
@ -511,7 +512,7 @@ func getOssUploadToken(filename, cloudDirPath string, length int64) (ret string,
|
|||
// 因为需要指定 key,所以每次上传文件都必须在云端生成 Token,否则有安全隐患
|
||||
|
||||
var result map[string]interface{}
|
||||
req := util.NewCloudRequest(Conf.System.NetworkProxy.String()).
|
||||
req := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String()).
|
||||
SetResult(&result)
|
||||
req.SetBody(map[string]interface{}{
|
||||
"token": Conf.User.UserToken,
|
||||
|
|
@ -551,7 +552,7 @@ func getOssUploadToken(filename, cloudDirPath string, length int64) (ret string,
|
|||
func getCloudSyncVer(cloudDir string) (cloudSyncVer int64, err error) {
|
||||
start := time.Now()
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"syncDir": cloudDir, "token": Conf.User.UserToken}).
|
||||
|
|
@ -591,7 +592,7 @@ func getCloudSyncVer(cloudDir string) (cloudSyncVer int64, err error) {
|
|||
func getCloudSync(cloudDir string) (assetSize, backupSize int64, device string, err error) {
|
||||
start := time.Now()
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"syncDir": cloudDir, "token": Conf.User.UserToken}).
|
||||
|
|
@ -656,7 +657,7 @@ func getLocalFileListOSS(isBackup bool) (ret map[string]*CloudIndex, err error)
|
|||
|
||||
func getCloudFileListOSS(cloudDirPath string) (ret map[string]*CloudIndex, err error) {
|
||||
result := map[string]interface{}{}
|
||||
request := util.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
|
||||
resp, err := request.
|
||||
SetResult(&result).
|
||||
SetBody(map[string]string{"dirPath": cloudDirPath, "token": Conf.User.UserToken}).
|
||||
|
|
@ -681,7 +682,7 @@ func getCloudFileListOSS(cloudDirPath string) (ret map[string]*CloudIndex, err e
|
|||
|
||||
retData := result["data"].(map[string]interface{})
|
||||
downloadURL := retData["url"].(string)
|
||||
resp, err = util.NewCloudFileRequest15s(Conf.System.NetworkProxy.String()).Get(downloadURL)
|
||||
resp, err = httpclient.NewCloudFileRequest15s(Conf.System.NetworkProxy.String()).Get(downloadURL)
|
||||
if nil != err {
|
||||
util.LogErrorf("download request [%s] failed: %s", downloadURL, err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue