mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-08 05:50:47 +00:00
replace AbortWithError calls by custom function that sets the content type correctly
This commit is contained in:
committed by
Benj Fassbind
parent
81582bffd2
commit
ecc41f0c0f
+12
-12
@@ -24,7 +24,7 @@ func verifyPath(path string) bool {
|
||||
|
||||
func verifyDir(c *gin.Context) bool {
|
||||
if !verifyPath(c.Params.ByName("dir")) {
|
||||
c.AbortWithError(400, fmt.Errorf("wrong dir"))
|
||||
AbortWithJSONError(c, 400, fmt.Errorf("wrong dir"))
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func apiFilesListDirs(c *gin.Context) {
|
||||
})
|
||||
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
c.AbortWithError(400, err)
|
||||
AbortWithJSONError(c, 400, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,13 +70,13 @@ func apiFilesUpload(c *gin.Context) {
|
||||
err := os.MkdirAll(path, 0777)
|
||||
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
AbortWithJSONError(c, 500, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = c.Request.ParseMultipartForm(10 * 1024 * 1024)
|
||||
if err != nil {
|
||||
c.AbortWithError(400, err)
|
||||
AbortWithJSONError(c, 400, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func apiFilesUpload(c *gin.Context) {
|
||||
for _, file := range files {
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
AbortWithJSONError(c, 500, err)
|
||||
return
|
||||
}
|
||||
defer src.Close()
|
||||
@@ -94,14 +94,14 @@ func apiFilesUpload(c *gin.Context) {
|
||||
destPath := filepath.Join(path, filepath.Base(file.Filename))
|
||||
dst, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
AbortWithJSONError(c, 500, err)
|
||||
return
|
||||
}
|
||||
defer dst.Close()
|
||||
|
||||
_, err = io.Copy(dst, src)
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
AbortWithJSONError(c, 500, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -138,9 +138,9 @@ func apiFilesListFiles(c *gin.Context) {
|
||||
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
c.AbortWithError(404, err)
|
||||
AbortWithJSONError(c, 404, err)
|
||||
} else {
|
||||
c.AbortWithError(500, err)
|
||||
AbortWithJSONError(c, 500, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func apiFilesDeleteDir(c *gin.Context) {
|
||||
|
||||
err := os.RemoveAll(filepath.Join(context.UploadPath(), c.Params.ByName("dir")))
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
AbortWithJSONError(c, 500, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -170,14 +170,14 @@ func apiFilesDeleteFile(c *gin.Context) {
|
||||
}
|
||||
|
||||
if !verifyPath(c.Params.ByName("name")) {
|
||||
c.AbortWithError(400, fmt.Errorf("wrong file"))
|
||||
AbortWithJSONError(c, 400, fmt.Errorf("wrong file"))
|
||||
return
|
||||
}
|
||||
|
||||
err := os.Remove(filepath.Join(context.UploadPath(), c.Params.ByName("dir"), c.Params.ByName("name")))
|
||||
if err != nil {
|
||||
if err1, ok := err.(*os.PathError); !ok || !os.IsNotExist(err1.Err) {
|
||||
c.AbortWithError(500, err)
|
||||
AbortWithJSONError(c, 500, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user