This commit is contained in:
Liang Ding 2022-07-09 11:22:51 +08:00
parent 2880222bc6
commit 70b8a7d8eb
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
16 changed files with 89 additions and 93 deletions

View file

@ -92,7 +92,7 @@ func NetImg2LocalAssets(rootID string) (err error) {
}
}
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(119), u), 15000)
request := httpclient.NewBrowserRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewBrowserRequest()
resp, reqErr := request.Get(u)
if nil != reqErr {
util.LogErrorf("download net img [%s] failed: %s", u, reqErr)
@ -286,7 +286,7 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
}
requestResult := gulu.Ret.NewResult()
request := httpclient.NewCloudFileRequest2m(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudFileRequest2m()
resp, reqErr := request.
SetResult(requestResult).
SetFile("file[]", absAsset).

View file

@ -28,12 +28,12 @@ import (
)
func GetPackageREADME(repoURL, repoHash string) (ret string) {
ret = bazaar.GetPackageREADME(repoURL, repoHash, Conf.System.NetworkProxy.String(), IsSubscriber(), Conf.System.ID)
ret = bazaar.GetPackageREADME(repoURL, repoHash, IsSubscriber(), Conf.System.ID)
return
}
func BazaarWidgets() (widgets []*bazaar.Widget) {
widgets = bazaar.Widgets(Conf.System.NetworkProxy.String())
widgets = bazaar.Widgets()
for _, widget := range widgets {
widget.Installed = gulu.File.IsDir(filepath.Join(util.DataDir, "widgets", widget.Name))
if widget.Installed {
@ -54,7 +54,7 @@ func InstallBazaarWidget(repoURL, repoHash, widgetName string) error {
defer writingDataLock.Unlock()
installPath := filepath.Join(util.DataDir, "widgets", widgetName)
err := bazaar.InstallWidget(repoURL, repoHash, installPath, Conf.System.NetworkProxy.String(), IsSubscriber(), Conf.System.ID)
err := bazaar.InstallWidget(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
if nil != err {
return errors.New(fmt.Sprintf(Conf.Language(46), widgetName))
}
@ -74,7 +74,7 @@ func UninstallBazaarWidget(widgetName string) error {
}
func BazaarIcons() (icons []*bazaar.Icon) {
icons = bazaar.Icons(Conf.System.NetworkProxy.String())
icons = bazaar.Icons()
for _, installed := range Conf.Appearance.Icons {
for _, icon := range icons {
if installed == icon.Name {
@ -96,7 +96,7 @@ func InstallBazaarIcon(repoURL, repoHash, iconName string) error {
defer writingDataLock.Unlock()
installPath := filepath.Join(util.IconsPath, iconName)
err := bazaar.InstallIcon(repoURL, repoHash, installPath, Conf.System.NetworkProxy.String(), IsSubscriber(), Conf.System.ID)
err := bazaar.InstallIcon(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
if nil != err {
return errors.New(fmt.Sprintf(Conf.Language(46), iconName))
}
@ -121,7 +121,7 @@ func UninstallBazaarIcon(iconName string) error {
}
func BazaarThemes() (ret []*bazaar.Theme) {
ret = bazaar.Themes(Conf.System.NetworkProxy.String())
ret = bazaar.Themes()
installs := Conf.Appearance.DarkThemes
installs = append(installs, Conf.Appearance.LightThemes...)
for _, installed := range installs {
@ -145,7 +145,7 @@ func InstallBazaarTheme(repoURL, repoHash, themeName string, mode int, update bo
closeThemeWatchers()
installPath := filepath.Join(util.ThemesPath, themeName)
err := bazaar.InstallTheme(repoURL, repoHash, installPath, Conf.System.NetworkProxy.String(), IsSubscriber(), Conf.System.ID)
err := bazaar.InstallTheme(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
if nil != err {
return errors.New(fmt.Sprintf(Conf.Language(46), themeName))
}
@ -183,7 +183,7 @@ func UninstallBazaarTheme(themeName string) error {
}
func BazaarTemplates() (templates []*bazaar.Template) {
templates = bazaar.Templates(Conf.System.NetworkProxy.String())
templates = bazaar.Templates()
for _, template := range templates {
template.Installed = gulu.File.IsExist(filepath.Join(util.DataDir, "templates", template.Name))
if template.Installed {
@ -202,7 +202,7 @@ func InstallBazaarTemplate(repoURL, repoHash, templateName string) error {
defer writingDataLock.Unlock()
installPath := filepath.Join(util.DataDir, "templates", templateName)
err := bazaar.InstallTemplate(repoURL, repoHash, installPath, Conf.System.NetworkProxy.String(), IsSubscriber(), Conf.System.ID)
err := bazaar.InstallTemplate(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
if nil != err {
return errors.New(fmt.Sprintf(Conf.Language(46), templateName))
}

View file

@ -210,9 +210,6 @@ func InitConf() {
if nil == Conf.System.NetworkProxy {
Conf.System.NetworkProxy = &conf.NetworkProxy{}
}
if "" != Conf.System.NetworkProxy.Scheme {
util.LogInfof("using network proxy [%s]", Conf.System.NetworkProxy.String())
}
if "" == Conf.System.ID {
Conf.System.ID = util.GetDeviceID()
}

View file

@ -38,7 +38,7 @@ func StartFreeTrial() (err error) {
}
requestResult := gulu.Ret.NewResult()
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
_, err = request.
SetResult(requestResult).
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
@ -55,7 +55,7 @@ func StartFreeTrial() (err error) {
func DeactivateUser() (err error) {
requestResult := gulu.Ret.NewResult()
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(requestResult).
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
@ -80,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 := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(requestResult).
SetBody(payload).
@ -113,7 +113,7 @@ func LoadUploadToken() (err error) {
}
requestResult := gulu.Ret.NewResult()
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(requestResult).
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
@ -252,7 +252,7 @@ func loadUserFromConf() *conf.User {
func RemoveCloudShorthands(ids []string) (err error) {
result := map[string]interface{}{}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
body := map[string]interface{}{
"ids": ids,
}
@ -283,7 +283,7 @@ func RemoveCloudShorthands(ids []string) (err error) {
func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
result = map[string]interface{}{}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(&result).
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
@ -320,7 +320,7 @@ var errInvalidUser = errors.New("invalid user")
func getUser(token string) (*conf.User, error) {
result := map[string]interface{}{}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
_, err := request.
SetResult(&result).
SetBody(map[string]string{"token": token}).
@ -351,7 +351,7 @@ func getUser(token string) (*conf.User, error) {
func UseActivationcode(code string) (err error) {
requestResult := gulu.Ret.NewResult()
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
_, err = request.
SetResult(requestResult).
SetBody(map[string]string{"data": code}).
@ -370,7 +370,7 @@ func UseActivationcode(code string) (err error) {
func CheckActivationcode(code string) (retCode int, msg string) {
retCode = 1
requestResult := gulu.Ret.NewResult()
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
_, err := request.
SetResult(requestResult).
SetBody(map[string]string{"data": code}).
@ -390,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 := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
_, err = request.
SetResult(&result).
SetBody(map[string]string{"userName": userName, "userPassword": password, "captcha": captcha}).
@ -416,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 := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
_, err := request.
SetResult(&result).
SetBody(map[string]string{"twofactorAuthCode": code}).

View file

@ -41,7 +41,7 @@ import (
func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, err error) {
result := map[string]interface{}{}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
var resp *req.Response
if Conf.Sync.UseDataRepo {
@ -82,7 +82,7 @@ func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, e
func removeCloudDirPath(dirPath string) (err error) {
result := map[string]interface{}{}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(&result).
SetBody(map[string]string{"dirPath": dirPath, "token": Conf.User.UserToken}).
@ -107,7 +107,7 @@ func removeCloudDirPath(dirPath string) (err error) {
func createCloudSyncDirOSS(name string) (err error) {
result := map[string]interface{}{}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(&result).
SetBody(map[string]string{"name": name, "token": Conf.User.UserToken}).
@ -138,7 +138,7 @@ func createCloudSyncDirOSS(name string) (err error) {
func listCloudSyncDirOSS() (dirs []map[string]interface{}, size int64, err error) {
result := map[string]interface{}{}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetBody(map[string]interface{}{"token": Conf.User.UserToken}).
SetResult(&result).
@ -290,7 +290,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 := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String()).
resp, err := httpclient.NewCloudRequest().
SetResult(&result).
SetBody(map[string]interface{}{"token": Conf.User.UserToken, "path": remoteFileURL}).
Post(util.AliyunServer + "/apis/siyuan/data/getSiYuanFile?uid=" + Conf.User.UserId)
@ -325,9 +325,9 @@ func ossDownload0(localDirPath, cloudDirPath, fetch string, fetchedFiles *int, t
os.Remove(localFilePath)
if bootORExit {
resp, err = httpclient.NewCloudFileRequest15s(Conf.System.NetworkProxy.String()).Get(downloadURL)
resp, err = httpclient.NewCloudFileRequest15s().Get(downloadURL)
} else {
resp, err = httpclient.NewCloudFileRequest2m(Conf.System.NetworkProxy.String()).Get(downloadURL)
resp, err = httpclient.NewCloudFileRequest2m().Get(downloadURL)
}
if nil != err {
util.LogErrorf("download request [%s] failed: %s", downloadURL, err)
@ -470,7 +470,7 @@ func ossRemove0(cloudDirPath string, removes []string) (err error) {
return
}
request := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
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)
@ -524,7 +524,7 @@ func getOssUploadToken(filename, cloudDirPath string, length int64) (ret string,
// 因为需要指定 key所以每次上传文件都必须在云端生成 Token否则有安全隐患
var result map[string]interface{}
req := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String()).
req := httpclient.NewCloudRequest().
SetResult(&result)
req.SetBody(map[string]interface{}{
"token": Conf.User.UserToken,
@ -564,7 +564,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 := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(&result).
SetBody(map[string]string{"syncDir": cloudDir, "token": Conf.User.UserToken}).
@ -604,7 +604,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 := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(&result).
SetBody(map[string]string{"syncDir": cloudDir, "token": Conf.User.UserToken}).
@ -669,7 +669,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 := httpclient.NewCloudRequest(Conf.System.NetworkProxy.String())
request := httpclient.NewCloudRequest()
resp, err := request.
SetResult(&result).
SetBody(map[string]string{"dirPath": cloudDirPath, "token": Conf.User.UserToken}).
@ -694,7 +694,7 @@ func getCloudFileListOSS(cloudDirPath string) (ret map[string]*CloudIndex, err e
retData := result["data"].(map[string]interface{})
downloadURL := retData["url"].(string)
resp, err = httpclient.NewCloudFileRequest15s(Conf.System.NetworkProxy.String()).Get(downloadURL)
resp, err = httpclient.NewCloudFileRequest15s().Get(downloadURL)
if nil != err {
util.LogErrorf("download request [%s] failed: %s", downloadURL, err)
return

View file

@ -667,7 +667,6 @@ func buildCloudInfo() (ret *dejavu.CloudInfo, err error) {
UserID: Conf.User.UserId,
Token: Conf.User.UserToken,
LimitSize: int64(Conf.User.UserSiYuanRepoSize - Conf.User.UserSiYuanAssetSize),
ProxyURL: Conf.System.NetworkProxy.String(),
Server: util.AliyunServer,
}
return

View file

@ -42,7 +42,7 @@ func CheckUpdate(showMsg bool) {
checkUpdateLock.Lock()
defer checkUpdateLock.Unlock()
result, err := util.GetRhyResult(showMsg, Conf.System.NetworkProxy.String())
result, err := util.GetRhyResult(showMsg)
if nil != err {
return
}