Explorar o código

Fixed wildcard bug in agi aglob

Also updated Musicif to list correctly on Artists view
Toby Chui hai 13 horas
pai
achega
44e3e73185

+ 1 - 0
.gitignore

@@ -32,3 +32,4 @@ src/system/cron.json
 src/system/smtp_conf.json
 *.exe~
 /src/tmp
+/src/test

+ 22 - 1
src/mod/filesystem/abstractions/localfs/localfs.go

@@ -129,7 +129,28 @@ func (l LocalFileSystemAbstraction) IsDir(realpath string) bool {
 }
 
 func (l LocalFileSystemAbstraction) Glob(realpathWildcard string) ([]string, error) {
-	return filepath.Glob(realpathWildcard)
+	files, err := filepath.Glob(realpathWildcard)
+	if err != nil {
+		return files, err
+	}
+
+	// filepath.Glob treats [ and ] as character class syntax, so folder names containing
+	// brackets (e.g. "[Hi-Res][FLAC]") return no results. Fall back to a ?-wildcard scan
+	// and then verify matches against the original path to filter out false positives.
+	if (strings.Contains(realpathWildcard, "[") || strings.Contains(realpathWildcard, "]")) && len(files) == 0 {
+		newSearchPath := strings.ReplaceAll(realpathWildcard, "[", "?")
+		newSearchPath = strings.ReplaceAll(newSearchPath, "]", "?")
+		tmpFilelist, _ := filepath.Glob(newSearchPath)
+		dirPath := filepath.ToSlash(filepath.Dir(realpathWildcard))
+		for _, file := range tmpFilelist {
+			file = filepath.ToSlash(file)
+			if strings.Contains(file, dirPath) {
+				files = append(files, file)
+			}
+		}
+	}
+
+	return files, err
 }
 
 func (l LocalFileSystemAbstraction) GetFileSize(realpath string) int64 {

+ 1 - 3
src/web/Musicify/backend/listFolder.js

@@ -14,12 +14,10 @@ function main() {
 
     var decodedFolder = decodeURIComponent(folder);
     // Remove trailing wildcard/slash if present
-    decodedFolder = decodedFolder.replace(/\/\*$/, "").replace(/\/$/, "");
-
+    decodedFolder = decodedFolder.replace(/\/\*$/, "").replace(/\/$/, ""); // I tried to comment this but not working
     var results = filelib.aglob(decodedFolder + "/*", "user");
     var subfolders = [];
     var songs = [];
-
     for (var i = 0; i < results.length; i++) {
         var f = results[i];
         if (isHiddenFile(f)) continue;

+ 3 - 3
src/web/Musicify/index.html

@@ -949,7 +949,7 @@
                             <p>Organise your music into sub-folders under your Music directory to see artists here.</p>
                         </div>
                     </template>
-                    <template x-for="artist in artists" :key="artist.name">
+                    <template x-for="artist in artists" :key="artist.path">
                         <div>
                             <div class="artist-row" x-on:click="selectArtist(artist)">
                                 <div class="artist-avatar" x-text="artist.name.charAt(0)"></div>
@@ -961,11 +961,11 @@
                                     <i class="ui play icon" style="margin:0;"></i>
                                 </button>
                                 <i class="ui chevron right icon artist-expand"
-                                   :class="{open: selectedArtist && selectedArtist.name === artist.name}"
+                                   :class="{open: selectedArtist && selectedArtist.path === artist.path}"
                                    style="margin:0;"></i>
                             </div>
                             <!-- Expanded song list -->
-                            <div x-show="selectedArtist && selectedArtist.name === artist.name"
+                            <div x-show="selectedArtist && selectedArtist.path === artist.path"
                                  style="background:var(--bg2);border-radius:0 0 8px 8px;margin-bottom:4px;">
                                 <template x-for="(song, idx) in artist.songs" :key="song.filepath">
                                     <div class="song-row" :class="{active: isCurrentTrack(song)}"

+ 1 - 1
src/web/Musicify/musicify.js

@@ -278,7 +278,7 @@ function musicifyApp() {
         },
 
         selectArtist(artist) {
-            this.selectedArtist = (this.selectedArtist && this.selectedArtist.name === artist.name) ? null : artist;
+            this.selectedArtist = (this.selectedArtist && this.selectedArtist.path === artist.path) ? null : artist;
         },
 
         // ════════════════════════════════════════════════════════════════════