瀏覽代碼

:art: Official data sync counts the number of cloud storage API calls https://github.com/siyuan-note/siyuan/issues/8048

Liang Ding 2 年之前
父節點
當前提交
78a5c05d28
共有 4 個文件被更改,包括 12 次插入2 次删除
  1. 2 0
      app/src/config/repos.ts
  2. 3 1
      kernel/api/repo.go
  3. 2 0
      kernel/conf/user.go
  4. 5 1
      kernel/model/repository.go

+ 2 - 0
app/src/config/repos.ts

@@ -176,6 +176,8 @@ const bindProviderEvent = () => {
         <ul class="b3-list">
             <li class="b3-list-item" style="cursor: auto;">${window.siyuan.languages.upload}<span class="fn__space"></span><span class="ft__on-surface">${response.data.hTrafficUploadSize}</span></li>
             <li class="b3-list-item" style="cursor: auto;">${window.siyuan.languages.download}<span class="fn__space"></span><span class="ft__on-surface">${response.data.hTrafficDownloadSize}</span></li>
+            <li class="b3-list-item" style="cursor: auto;">API GET<span class="fn__space"></span><span class="ft__on-surface">${response.data.hTrafficAPIGet}</span></li>
+            <li class="b3-list-item" style="cursor: auto;">API PUT<span class="fn__space"></span><span class="ft__on-surface">${response.data.hTrafficAPIPut}</span></li>
         </ul>
     </div>
 </div>`;

+ 3 - 1
kernel/api/repo.go

@@ -83,7 +83,7 @@ func getCloudSpace(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 
-	sync, backup, hSize, hAssetSize, hTotalSize, exchangeSize, hTrafficUploadSize, hTrafficDownloadSize, err := model.GetCloudSpace()
+	sync, backup, hSize, hAssetSize, hTotalSize, exchangeSize, hTrafficUploadSize, hTrafficDownloadSize, htrafficAPIGet, hTrafficAPIPut, err := model.GetCloudSpace()
 	if nil != err {
 		ret.Code = 1
 		ret.Msg = err.Error()
@@ -100,6 +100,8 @@ func getCloudSpace(c *gin.Context) {
 		"hExchangeSize":        exchangeSize,
 		"hTrafficUploadSize":   hTrafficUploadSize,
 		"hTrafficDownloadSize": hTrafficDownloadSize,
+		"hTrafficAPIGet":       htrafficAPIGet,
+		"hTrafficAPIPut":       hTrafficAPIPut,
 	}
 }
 

+ 2 - 0
kernel/conf/user.go

@@ -34,6 +34,8 @@ type User struct {
 	UserSiYuanAssetSize             float64      `json:"userSiYuanAssetSize"`
 	UserTrafficUpload               float64      `json:"userTrafficUpload"`
 	UserTrafficDownload             float64      `json:"userTrafficDownload"`
+	UserTrafficAPIGet               float64      `json:"userTrafficAPIGet"`
+	UserTrafficAPIPut               float64      `json:"userTrafficAPIPut"`
 	UserTrafficTime                 float64      `json:"userTrafficTime"`
 	UserSiYuanSubscriptionPlan      float64      `json:"userSiYuanSubscriptionPlan"`   // -1:未订阅,0:标准订阅,1:教育订阅,2:试用
 	UserSiYuanSubscriptionStatus    float64      `json:"userSiYuanSubscriptionStatus"` // -1:未订阅,0:订阅可用,1:订阅封禁,2:订阅过期

+ 5 - 1
kernel/model/repository.go

@@ -1599,7 +1599,7 @@ type Sync struct {
 	SaveDir   string `json:"saveDir"`   // 本地同步数据存放目录路径
 }
 
-func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize, hExchangeSize, hTrafficUploadSize, hTrafficDownloadSize string, err error) {
+func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize, hExchangeSize, hTrafficUploadSize, hTrafficDownloadSize, hTrafficAPIGet, hTrafficAPIPut string, err error) {
 	stat, err := getCloudSpaceOSS()
 	if nil != err {
 		err = errors.New(Conf.Language(30) + " " + err.Error())
@@ -1630,6 +1630,8 @@ func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize, hExchan
 	hExchangeSize = "-"
 	hTrafficUploadSize = "-"
 	hTrafficDownloadSize = "-"
+	hTrafficAPIGet = "-"
+	hTrafficAPIPut = "-"
 	if conf.ProviderSiYuan == Conf.Sync.Provider {
 		s.HSize = humanize.Bytes(uint64(syncSize))
 		b.HSize = humanize.Bytes(uint64(backupSize))
@@ -1639,6 +1641,8 @@ func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize, hExchan
 		hExchangeSize = humanize.Bytes(uint64(Conf.User.UserSiYuanPointExchangeRepoSize))
 		hTrafficUploadSize = humanize.Bytes(uint64(Conf.User.UserTrafficUpload))
 		hTrafficDownloadSize = humanize.Bytes(uint64(Conf.User.UserTrafficDownload))
+		hTrafficAPIGet = fmt.Sprintf("%d", int(Conf.User.UserTrafficAPIGet))
+		hTrafficAPIPut = fmt.Sprintf("%d", int(Conf.User.UserTrafficAPIPut))
 	}
 	return
 }