mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 One-click upgrade of downloaded marketplace packages https://github.com/siyuan-note/siyuan/issues/8390
This commit is contained in:
parent
4817bc0812
commit
2120637c06
9 changed files with 144 additions and 11 deletions
|
|
@ -1440,6 +1440,10 @@
|
||||||
"231": "Deleting unreferenced data objects in cloud storage...",
|
"231": "Deleting unreferenced data objects in cloud storage...",
|
||||||
"232": "The cloud data storage has been purged. [%d] snapshots and [%d] data objects have been deleted, and a total of [%s] disk space has been released",
|
"232": "The cloud data storage has been purged. [%d] snapshots and [%d] data objects have been deleted, and a total of [%s] disk space has been released",
|
||||||
"233": "Closing user guide...",
|
"233": "Closing user guide...",
|
||||||
"234": "[%d/%d] Updated [%d] of readable paths of doc [%s]"
|
"234": "[%d/%d] Updated [%d] of readable paths of doc [%s]",
|
||||||
|
"235": "[%d/%d] is updating the marketplace package...",
|
||||||
|
"236": "[%d/%d] is updating the marketplace package [%s]...",
|
||||||
|
"237": "[%d] marketplace packages have all been updated successfully",
|
||||||
|
"238": "Marketplace package [%s] update failed, please try again later"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1440,6 +1440,10 @@
|
||||||
"231": "Eliminar objetos de datos no referenciados en el almacenamiento en la nube...",
|
"231": "Eliminar objetos de datos no referenciados en el almacenamiento en la nube...",
|
||||||
"232": "Se ha eliminado el almacenamiento de datos en la nube. Se han eliminado [%d] instantáneas y [%d] objetos de datos, y se ha liberado un total de [%s] espacio en disco",
|
"232": "Se ha eliminado el almacenamiento de datos en la nube. Se han eliminado [%d] instantáneas y [%d] objetos de datos, y se ha liberado un total de [%s] espacio en disco",
|
||||||
"233": "Cerrando la guía del usuario...",
|
"233": "Cerrando la guía del usuario...",
|
||||||
"234": "[%d/%d] Actualizado [%d] de rutas legibles del documento [%s]"
|
"234": "[%d/%d] Actualizado [%d] de rutas legibles del documento [%s]",
|
||||||
|
"235": "[%d/%d] está actualizando el paquete del mercado...",
|
||||||
|
"236": "[%d/%d] está actualizando el paquete del mercado [%s]...",
|
||||||
|
"237": "[%d] todos los paquetes del mercado se han actualizado correctamente",
|
||||||
|
"238": "Error en la actualización del paquete Marketplace [%s], inténtalo de nuevo más tarde"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1440,6 +1440,10 @@
|
||||||
"231": "Suppression des objets de données non référencés dans le stockage cloud...",
|
"231": "Suppression des objets de données non référencés dans le stockage cloud...",
|
||||||
"232": "Le stockage de données cloud a été purgé. [%d] instantanés et [%d] objets de données ont été supprimés, et un total de [%s] espace disque a été libéré",
|
"232": "Le stockage de données cloud a été purgé. [%d] instantanés et [%d] objets de données ont été supprimés, et un total de [%s] espace disque a été libéré",
|
||||||
"233": "Fermeture du guide de l'utilisateur...",
|
"233": "Fermeture du guide de l'utilisateur...",
|
||||||
"234": "[%d/%d] Mise à jour de [%d] des chemins lisibles du document [%s]"
|
"234": "[%d/%d] Mise à jour de [%d] des chemins lisibles du document [%s]",
|
||||||
|
"235": "[%d/%d] met à jour le package Marketplace...",
|
||||||
|
"236": "[%d/%d] met à jour le package Marketplace [%s]...",
|
||||||
|
"237": "[%d] packages Marketplace ont tous été mis à jour avec succès",
|
||||||
|
"238": "La mise à jour du package Marketplace [%s] a échoué, veuillez réessayer plus tard"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1440,6 +1440,10 @@
|
||||||
"231": "正在刪除雲端儲存未引用資料物件...",
|
"231": "正在刪除雲端儲存未引用資料物件...",
|
||||||
"232": "雲端資料儲存清理完畢,已刪除 [%d] 個快照和 [%d] 個資料對象,共釋放 [%s] 磁碟空間",
|
"232": "雲端資料儲存清理完畢,已刪除 [%d] 個快照和 [%d] 個資料對象,共釋放 [%s] 磁碟空間",
|
||||||
"233": "正在關閉用戶指南...",
|
"233": "正在關閉用戶指南...",
|
||||||
"234": "[%d/%d] 已經更新 [%d] 個文件的可讀路徑 [%s]"
|
"234": "[%d/%d] 已經更新 [%d] 個文件的可讀路徑 [%s]",
|
||||||
|
"235": "[%d/%d] 正在更新市集包...",
|
||||||
|
"236": "[%d/%d] 正在更新市集包 [%s]...",
|
||||||
|
"237": "[%d] 個市集包已經全部更新成功",
|
||||||
|
"238": "市集包 [%s] 更新失敗,請稍後再試"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1440,6 +1440,10 @@
|
||||||
"231": "正在删除云端存储未引用数据对象...",
|
"231": "正在删除云端存储未引用数据对象...",
|
||||||
"232": "云端数据存储清理完毕,已删除 [%d] 个快照和 [%d] 个数据对象,共释放 [%s] 磁盘空间",
|
"232": "云端数据存储清理完毕,已删除 [%d] 个快照和 [%d] 个数据对象,共释放 [%s] 磁盘空间",
|
||||||
"233": "正在关闭用户指南...",
|
"233": "正在关闭用户指南...",
|
||||||
"234": "[%d/%d] 已经更新 [%d] 个文档的可读路径 [%s]"
|
"234": "[%d/%d] 已经更新 [%d] 个文档的可读路径 [%s]",
|
||||||
|
"235": "[%d/%d] 正在更新集市包...",
|
||||||
|
"236": "[%d/%d] 正在更新集市包 [%s]...",
|
||||||
|
"237": "[%d] 个集市包已经全部更新成功",
|
||||||
|
"238": "集市包 [%s] 更新失败,请稍后再试"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,19 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func batchUpdatePackage(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
frontend := arg["frontend"].(string)
|
||||||
|
model.BatchUpdateBazaarPackages(frontend)
|
||||||
|
}
|
||||||
|
|
||||||
func getUpdatedPackage(c *gin.Context) {
|
func getUpdatedPackage(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
|
|
@ -330,7 +330,6 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/graph/getGraph", model.CheckAuth, getGraph)
|
ginServer.Handle("POST", "/api/graph/getGraph", model.CheckAuth, getGraph)
|
||||||
ginServer.Handle("POST", "/api/graph/getLocalGraph", model.CheckAuth, getLocalGraph)
|
ginServer.Handle("POST", "/api/graph/getLocalGraph", model.CheckAuth, getLocalGraph)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/bazaar/getUpdatedPackage", model.CheckAuth, getUpdatedPackage)
|
|
||||||
ginServer.Handle("POST", "/api/bazaar/getBazaarPlugin", model.CheckAuth, getBazaarPlugin)
|
ginServer.Handle("POST", "/api/bazaar/getBazaarPlugin", model.CheckAuth, getBazaarPlugin)
|
||||||
ginServer.Handle("POST", "/api/bazaar/getInstalledPlugin", model.CheckAuth, getInstalledPlugin)
|
ginServer.Handle("POST", "/api/bazaar/getInstalledPlugin", model.CheckAuth, getInstalledPlugin)
|
||||||
ginServer.Handle("POST", "/api/bazaar/installBazaarPlugin", model.CheckAuth, model.CheckReadonly, installBazaarPlugin)
|
ginServer.Handle("POST", "/api/bazaar/installBazaarPlugin", model.CheckAuth, model.CheckReadonly, installBazaarPlugin)
|
||||||
|
|
@ -352,6 +351,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/bazaar/installBazaarTheme", model.CheckAuth, model.CheckReadonly, installBazaarTheme)
|
ginServer.Handle("POST", "/api/bazaar/installBazaarTheme", model.CheckAuth, model.CheckReadonly, installBazaarTheme)
|
||||||
ginServer.Handle("POST", "/api/bazaar/uninstallBazaarTheme", model.CheckAuth, model.CheckReadonly, uninstallBazaarTheme)
|
ginServer.Handle("POST", "/api/bazaar/uninstallBazaarTheme", model.CheckAuth, model.CheckReadonly, uninstallBazaarTheme)
|
||||||
ginServer.Handle("POST", "/api/bazaar/getBazaarPackageREAME", model.CheckAuth, getBazaarPackageREAME)
|
ginServer.Handle("POST", "/api/bazaar/getBazaarPackageREAME", model.CheckAuth, getBazaarPackageREAME)
|
||||||
|
ginServer.Handle("POST", "/api/bazaar/getUpdatedPackage", model.CheckAuth, getUpdatedPackage)
|
||||||
|
ginServer.Handle("POST", "/api/bazaar/batchUpdatePackage", model.CheckAuth, batchUpdatePackage)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/repo/initRepoKey", model.CheckAuth, model.CheckReadonly, initRepoKey)
|
ginServer.Handle("POST", "/api/repo/initRepoKey", model.CheckAuth, model.CheckReadonly, initRepoKey)
|
||||||
ginServer.Handle("POST", "/api/repo/initRepoKeyFromPassphrase", model.CheckAuth, model.CheckReadonly, initRepoKeyFromPassphrase)
|
ginServer.Handle("POST", "/api/repo/initRepoKeyFromPassphrase", model.CheckAuth, model.CheckReadonly, initRepoKeyFromPassphrase)
|
||||||
|
|
|
||||||
|
|
@ -530,9 +530,25 @@ func renderREADME(repoURL string, mdData []byte) (ret string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
packageLocks = map[string]*sync.Mutex{}
|
||||||
|
packageLocksLock = sync.Mutex{}
|
||||||
|
)
|
||||||
|
|
||||||
func downloadPackage(repoURLHash string, pushProgress bool, systemID string) (data []byte, err error) {
|
func downloadPackage(repoURLHash string, pushProgress bool, systemID string) (data []byte, err error) {
|
||||||
|
packageLocksLock.Lock()
|
||||||
|
defer packageLocksLock.Unlock()
|
||||||
|
|
||||||
// repoURLHash: https://github.com/88250/Comfortably-Numb@6286912c381ef3f83e455d06ba4d369c498238dc
|
// repoURLHash: https://github.com/88250/Comfortably-Numb@6286912c381ef3f83e455d06ba4d369c498238dc
|
||||||
pushID := repoURLHash[:strings.LastIndex(repoURLHash, "@")]
|
repoURL := repoURLHash[:strings.LastIndex(repoURLHash, "@")]
|
||||||
|
lock, ok := packageLocks[repoURLHash]
|
||||||
|
if !ok {
|
||||||
|
lock = &sync.Mutex{}
|
||||||
|
packageLocks[repoURLHash] = lock
|
||||||
|
}
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
|
||||||
repoURLHash = strings.TrimPrefix(repoURLHash, "https://github.com/")
|
repoURLHash = strings.TrimPrefix(repoURLHash, "https://github.com/")
|
||||||
u := util.BazaarOSSServer + "/package/" + repoURLHash
|
u := util.BazaarOSSServer + "/package/" + repoURLHash
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
@ -540,7 +556,7 @@ func downloadPackage(repoURLHash string, pushProgress bool, systemID string) (da
|
||||||
if pushProgress {
|
if pushProgress {
|
||||||
progress := float32(info.DownloadedSize) / float32(info.Response.ContentLength)
|
progress := float32(info.DownloadedSize) / float32(info.Response.ContentLength)
|
||||||
//logging.LogDebugf("downloading bazaar package [%f]", progress)
|
//logging.LogDebugf("downloading bazaar package [%f]", progress)
|
||||||
util.PushDownloadProgress(pushID, progress)
|
util.PushDownloadProgress(repoURL, progress)
|
||||||
}
|
}
|
||||||
}).Get(u)
|
}).Get(u)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,100 @@ package model
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/88250/gulu"
|
||||||
|
"github.com/siyuan-note/logging"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
"github.com/88250/gulu"
|
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
|
||||||
|
|
||||||
"github.com/siyuan-note/siyuan/kernel/bazaar"
|
"github.com/siyuan-note/siyuan/kernel/bazaar"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func BatchUpdateBazaarPackages(frontend string) {
|
||||||
|
plugins, widgets, icons, themes, templates := UpdatedPackages(frontend)
|
||||||
|
|
||||||
|
total := len(plugins) + len(widgets) + len(icons) + len(themes) + len(templates)
|
||||||
|
if 1 > total {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
util.PushEndlessProgress(fmt.Sprintf(Conf.language(235), 1, total))
|
||||||
|
defer util.PushClearProgress()
|
||||||
|
count := 1
|
||||||
|
for _, plugin := range plugins {
|
||||||
|
err := bazaar.InstallPlugin(plugin.RepoURL, plugin.RepoHash, filepath.Join(util.DataDir, "plugins", plugin.Name), Conf.System.ID)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("update plugin [%s] failed: %s", plugin.Name, err)
|
||||||
|
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count++
|
||||||
|
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, plugin.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, widget := range widgets {
|
||||||
|
err := bazaar.InstallWidget(widget.RepoURL, widget.RepoHash, filepath.Join(util.DataDir, "widgets", widget.Name), Conf.System.ID)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("update widget [%s] failed: %s", widget.Name, err)
|
||||||
|
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count++
|
||||||
|
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, widget.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, icon := range icons {
|
||||||
|
err := bazaar.InstallIcon(icon.RepoURL, icon.RepoHash, filepath.Join(util.IconsPath, icon.Name), Conf.System.ID)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("update icon [%s] failed: %s", icon.Name, err)
|
||||||
|
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count++
|
||||||
|
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, icon.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, template := range templates {
|
||||||
|
err := bazaar.InstallTemplate(template.RepoURL, template.RepoHash, filepath.Join(util.DataDir, "templates", template.Name), Conf.System.ID)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("update template [%s] failed: %s", template.Name, err)
|
||||||
|
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count++
|
||||||
|
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, template.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, theme := range themes {
|
||||||
|
err := bazaar.InstallTheme(theme.RepoURL, theme.RepoHash, filepath.Join(util.ThemesPath, theme.Name), Conf.System.ID)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("update theme [%s] failed: %s", theme.Name, err)
|
||||||
|
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count++
|
||||||
|
util.PushEndlessProgress(fmt.Sprintf(Conf.language(236), count, total, theme.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
util.ReloadUI()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
util.WaitForUILoaded()
|
||||||
|
time.Sleep(500)
|
||||||
|
util.PushMsg(fmt.Sprintf(Conf.language(237), total), 5000)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func UpdatedPackages(frontend string) (plugins []*bazaar.Plugin, widgets []*bazaar.Widget, icons []*bazaar.Icon, themes []*bazaar.Theme, templates []*bazaar.Template) {
|
func UpdatedPackages(frontend string) (plugins []*bazaar.Plugin, widgets []*bazaar.Widget, icons []*bazaar.Icon, themes []*bazaar.Theme, templates []*bazaar.Template) {
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(5)
|
wg.Add(5)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue