fix: update use of webApp.Paths

This commit is contained in:
Derrick Hammer 2024-03-03 03:41:30 -05:00
parent 9f65b1b455
commit 3d55254916
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 11 additions and 6 deletions

View File

@ -364,7 +364,9 @@ func (f *S5File) ReadDir(n int) ([]fs.DirEntry, error) {
var entries []fs.DirEntry var entries []fs.DirEntry
dirMap := make(map[string]bool) dirMap := make(map[string]bool)
for path, _ := range webApp.Paths { webApp.Paths.Keys()
for _, path := range webApp.Paths.Keys() {
pathSegments := strings.Split(path, "/") pathSegments := strings.Split(path, "/")
// Check if the path is an immediate child (either a file or a direct subdirectory) // Check if the path is an immediate child (either a file or a direct subdirectory)

View File

@ -32,7 +32,7 @@ func (w webAppFs) Open(name string) (fs.File, error) {
return nil, errors.New("manifest is not a web app") return nil, errors.New("manifest is not a web app")
} }
item, ok := webApp.Paths[name] item, ok := webApp.Paths.Get(name)
if !ok { if !ok {
return nil, fs.ErrNotExist return nil, fs.ErrNotExist

View File

@ -892,7 +892,8 @@ func (s *S5API) getManifestCids(cid *encoding.CID) ([]*encoding.CID, error) {
case types.CIDTypeMetadataWebapp: case types.CIDTypeMetadataWebapp:
webapp := manifest.(*s5libmetadata.WebAppMetadata) 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) 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) { 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 { for filename, upload := range uploads {
hash := upload.Hash hash := upload.Hash
@ -1283,12 +1284,14 @@ func (s *S5API) createAppMetadata(name string, tryFiles []string, errorPages map
if err != nil { if err != nil {
return nil, NewS5Error(ErrKeyInternalError, err, "Failed to create CID for file: "+filename) return nil, NewS5Error(ErrKeyInternalError, err, "Failed to create CID for file: "+filename)
} }
filesMap[filename] = s5libmetadata.WebAppMetadataFileReference{ filesMap.Put(filename, s5libmetadata.WebAppMetadataFileReference{
Cid: cid, Cid: cid,
ContentType: upload.MimeType, ContentType: upload.MimeType,
} })
} }
filesMap.Sort()
extraMetadataMap := make(map[int]interface{}) extraMetadataMap := make(map[int]interface{})
for statusCode, page := range errorPages { for statusCode, page := range errorPages {
extraMetadataMap[statusCode] = page extraMetadataMap[statusCode] = page