♻️ Unified marketplace Package Type Model (#17152)

This commit is contained in:
Jeffrey Chen 2026-03-08 11:09:46 +08:00 committed by GitHub
parent ab83e5d987
commit 3cac07dfd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 1108 additions and 1919 deletions

View file

@ -34,24 +34,24 @@ type WidgetSearchResult struct {
func SearchWidget(keyword string) (ret []*WidgetSearchResult) {
ret = []*WidgetSearchResult{}
widgetsDir := filepath.Join(util.DataDir, "widgets")
entries, err := os.ReadDir(widgetsDir)
widgetsDirPath := filepath.Join(util.DataDir, "widgets")
widgetsDir, err := os.ReadDir(widgetsDirPath)
if err != nil {
logging.LogErrorf("read dir [%s] failed: %s", widgetsDir, err)
logging.LogErrorf("read dir [%s] failed: %s", widgetsDirPath, err)
return
}
k := strings.ToLower(keyword)
var widgets []*bazaar.Widget
for _, entry := range entries {
if !util.IsDirRegularOrSymlink(entry) {
var widgets []*bazaar.Package
for _, dir := range widgetsDir {
if !util.IsDirRegularOrSymlink(dir) {
continue
}
if strings.HasPrefix(entry.Name(), ".") {
dirName := dir.Name()
if strings.HasPrefix(dirName, ".") {
continue
}
widget, _ := bazaar.WidgetJSON(entry.Name())
widget, _ := bazaar.ParsePackageJSON(filepath.Join(widgetsDirPath, dirName, "widget.json"))
if nil == widget {
continue
}
@ -59,10 +59,10 @@ func SearchWidget(keyword string) (ret []*WidgetSearchResult) {
widgets = append(widgets, widget)
}
widgets = filterWidgets(widgets, k)
widgets = bazaar.FilterPackages(widgets, keyword)
for _, widget := range widgets {
b := &WidgetSearchResult{
Name: bazaar.GetPreferredName(widget.Package),
Name: bazaar.GetPreferredLocaleString(widget.DisplayName, widget.Name),
Content: widget.Name,
}
ret = append(ret, b)