diff --git a/api/s5/file.go b/api/s5/file.go index c4ddffc..9246a87 100644 --- a/api/s5/file.go +++ b/api/s5/file.go @@ -364,7 +364,9 @@ func (f *S5File) ReadDir(n int) ([]fs.DirEntry, error) { var entries []fs.DirEntry dirMap := make(map[string]bool) - for path, _ := range webApp.Paths { + webApp.Paths.Keys() + + for _, path := range webApp.Paths.Keys() { pathSegments := strings.Split(path, "/") // Check if the path is an immediate child (either a file or a direct subdirectory) diff --git a/api/s5/fs_webapp.go b/api/s5/fs_webapp.go index b1bbeec..a7b41eb 100644 --- a/api/s5/fs_webapp.go +++ b/api/s5/fs_webapp.go @@ -32,7 +32,7 @@ func (w webAppFs) Open(name string) (fs.File, error) { return nil, errors.New("manifest is not a web app") } - item, ok := webApp.Paths[name] + item, ok := webApp.Paths.Get(name) if !ok { return nil, fs.ErrNotExist diff --git a/api/s5/s5.go b/api/s5/s5.go index 4b723b2..39c51b2 100644 --- a/api/s5/s5.go +++ b/api/s5/s5.go @@ -892,7 +892,8 @@ func (s *S5API) getManifestCids(cid *encoding.CID) ([]*encoding.CID, error) { case types.CIDTypeMetadataWebapp: webapp := manifest.(*s5libmetadata.WebAppMetadata) - lo.ForEach(lo.Values(webapp.Paths), func(f s5libmetadata.WebAppMetadataFileReference, _i int) { + + lo.ForEach(webapp.Paths.Values(), func(f s5libmetadata.WebAppMetadataFileReference, _i int) { cids = append(cids, f.Cid) }) } @@ -1274,7 +1275,7 @@ func (s *S5API) processMultipartFiles(r *http.Request) (map[string]*metadata.Upl } func (s *S5API) createAppMetadata(name string, tryFiles []string, errorPages map[int]string, uploads map[string]*metadata.UploadMetadata) (*s5libmetadata.WebAppMetadata, error) { - filesMap := make(map[string]s5libmetadata.WebAppMetadataFileReference, len(uploads)) + filesMap := s5libmetadata.NewWebAppFileMap() for filename, upload := range uploads { hash := upload.Hash @@ -1283,12 +1284,14 @@ func (s *S5API) createAppMetadata(name string, tryFiles []string, errorPages map if err != nil { return nil, NewS5Error(ErrKeyInternalError, err, "Failed to create CID for file: "+filename) } - filesMap[filename] = s5libmetadata.WebAppMetadataFileReference{ + filesMap.Put(filename, s5libmetadata.WebAppMetadataFileReference{ Cid: cid, ContentType: upload.MimeType, - } + }) } + filesMap.Sort() + extraMetadataMap := make(map[int]interface{}) for statusCode, page := range errorPages { extraMetadataMap[statusCode] = page