mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-23 03:21:35 +02:00
Dateien nach „routers/web“ hochladen
This commit is contained in:
parent
a5154c6001
commit
edf825fcd5
1 changed files with 20 additions and 1 deletions
|
@ -56,6 +56,7 @@ import (
|
|||
"github.com/go-chi/cors"
|
||||
"github.com/klauspost/compress/gzhttp"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"code.forgejo.org/go-chi/binding"
|
||||
)
|
||||
|
||||
var GzipMinSize = gzhttp.DefaultMinSize
|
||||
|
@ -1255,7 +1256,7 @@ func registerRoutes(m *web.Route) {
|
|||
Post(web.Bind(forms.DeleteRepoFileForm{}), repo.DeleteFilePost)
|
||||
m.Combo("/_upload/*", repo.MustBeAbleToUpload).
|
||||
Get(repo.UploadFile).
|
||||
Post(web.Bind(forms.UploadRepoFileForm{}), repo.UploadFilePost)
|
||||
Post(BindUpload(forms.UploadRepoFileForm{}), repo.UploadFilePost)
|
||||
m.Combo("/_diffpatch/*").Get(repo.NewDiffPatch).
|
||||
Post(web.Bind(forms.EditRepoFileForm{}), repo.NewDiffPatchPost)
|
||||
m.Combo("/_cherrypick/{sha:([a-f0-9]{4,64})}/*").Get(repo.CherryPick).
|
||||
|
@ -1671,3 +1672,21 @@ func registerRoutes(m *web.Route) {
|
|||
ctx.NotFound("", nil)
|
||||
})
|
||||
}
|
||||
|
||||
func BindUpload(f forms.UploadRepoFileForm) http.HandlerFunc {
|
||||
return func(resp http.ResponseWriter, req *http.Request) {
|
||||
|
||||
theObj := new(forms.UploadRepoFileForm) // create a new form obj for every request but not use obj directly
|
||||
data := middleware.GetContextData(req.Context())
|
||||
binding.Bind(req, theObj)
|
||||
files := theObj.Files
|
||||
var fullpaths []string
|
||||
for _, fileID := range files {
|
||||
fullPath := req.Form.Get("files_fullpath[" + fileID + "]")
|
||||
fullpaths = append(fullpaths, fullPath)
|
||||
}
|
||||
theObj.FullPaths = fullpaths
|
||||
data.GetData()["__form"] = theObj
|
||||
middleware.AssignForm(theObj, data)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue