fix: fix parsing of app upload settings, as they are json, and errorPages needs to be errorFiles

This commit is contained in:
Derrick Hammer 2024-03-02 04:51:28 -05:00
parent a9c2ecade0
commit 0c0cdfd2b1
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 35 additions and 4 deletions

View File

@ -1149,15 +1149,46 @@ func (s *S5API) pinEntity(ctx context.Context, userId uint, cid *encoding.CID) e
return nil return nil
} }
type dirTryFiles []string
type dirErrorFiles map[int]string
func (d *dirTryFiles) UnmarshalText(data []byte) error {
var out []string
err := json.Unmarshal(data, &out)
if err != nil {
return err
}
*d = out
return nil
}
func (d *dirErrorFiles) UnmarshalText(data []byte) error {
var out map[int]string
err := json.Unmarshal(data, &out)
if err != nil {
return err
}
*d = out
return nil
}
func (s *S5API) directoryUpload(jc jape.Context) { func (s *S5API) directoryUpload(jc jape.Context) {
// Decode form fields // Decode form fields
var ( var (
tryFiles []string tryFiles dirTryFiles
errorPages map[int]string errorFiles dirErrorFiles
name string name string
) )
if err := jc.DecodeForm("tryFiles", &tryFiles); err != nil || jc.DecodeForm("errorPages", &errorPages) != nil || jc.DecodeForm("name", &name) != nil { if err := jc.DecodeForm("tryFiles", &tryFiles); err != nil || jc.DecodeForm("errorFiles", &errorFiles) != nil || jc.DecodeForm("name", &name) != nil {
return
} }
// Verify content type // Verify content type
@ -1179,7 +1210,7 @@ func (s *S5API) directoryUpload(jc jape.Context) {
} }
// Generate metadata for the directory upload // Generate metadata for the directory upload
app, err := s.createAppMetadata(name, tryFiles, errorPages, uploads) app, err := s.createAppMetadata(name, tryFiles, errorFiles, uploads)
if err != nil { if err != nil {
s.sendErrorResponse(jc, err) s.sendErrorResponse(jc, err)
return return