Remove dupe
This commit is contained in:
parent
904e0a574d
commit
01b766dacc
|
@ -270,51 +270,6 @@ func postServerDownloadRemoteFile(c *gin.Context) {
|
|||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// Writes the contents of the remote URL to a file on a server.
|
||||
func postServerDownloadRemoteFile(c *gin.Context) {
|
||||
s := ExtractServer(c)
|
||||
var data struct {
|
||||
URL string `binding:"required" json:"url"`
|
||||
BasePath string `json:"path"`
|
||||
}
|
||||
if err := c.BindJSON(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
u, err := url.Parse(data.URL)
|
||||
if err != nil {
|
||||
if e, ok := err.(*url.Error); ok {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
|
||||
"error": "An error occurred while parsing that URL: " + e.Err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := http.Get(u.String())
|
||||
if err != nil {
|
||||
TrackedServerError(err, s).AbortWithServerError(c)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
filename := strings.Split(u.Path, "/")
|
||||
if err := s.Filesystem().Writefile(filepath.Join(data.BasePath, filename[len(filename)-1]), resp.Body); err != nil {
|
||||
if errors.Is(err, filesystem.ErrIsDirectory) {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Cannot write file, name conflicts with an existing directory by the same name.",
|
||||
})
|
||||
return
|
||||
}
|
||||
TrackedServerError(err, s).AbortFilesystemError(c)
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// Create a directory on a server.
|
||||
func postServerCreateDirectory(c *gin.Context) {
|
||||
s := GetServer(c.Param("server"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user