add download api at develop branch
This commit is contained in:
parent
fb725c6b3a
commit
3388516c8b
Binary file not shown.
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
@ -82,6 +82,7 @@ import (
|
|||
"code.gitea.io/gitea/routers/api/v1/settings"
|
||||
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
|
||||
"code.gitea.io/gitea/routers/api/v1/user"
|
||||
"code.gitea.io/gitea/routers/api/v1/trace"
|
||||
|
||||
"gitea.com/macaron/binding"
|
||||
"gitea.com/macaron/macaron"
|
||||
|
@ -990,6 +991,12 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Group("/topics", func() {
|
||||
m.Get("/search", repo.TopicSearch)
|
||||
})
|
||||
|
||||
m.Group("/log", func() {
|
||||
m.Get("/list", trace.GetLogList)
|
||||
m.Get("/download/:filename", trace.DownloadLog)
|
||||
// m.Combo("/download").Post(bind(trace.LogDownloadOptions{}), trace.DownloadLog)
|
||||
})
|
||||
}, securityHeaders(), context.APIContexter(), sudo())
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package trace
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"os"
|
||||
// "path/filepath"
|
||||
"io/ioutil"
|
||||
// "net/http"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
type LogDownloadOptions struct {
|
||||
FileName string `json:"filename" binding:"Required"`
|
||||
}
|
||||
|
||||
func GetLogList(ctx *context.APIContext) {
|
||||
var logList []string
|
||||
|
||||
dir_list, err := ioutil.ReadDir(setting.LogRootPath)
|
||||
if err != nil {
|
||||
ctx.ServerError("logList", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i:=0; i<len(dir_list); i++ {
|
||||
// fmt.Println(i, "=", v.Name())
|
||||
logList = append(logList, dir_list[i].Name())
|
||||
}
|
||||
|
||||
ctx.JSON(200, &logList)
|
||||
}
|
||||
|
||||
type NotFoundError struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func DownloadLog(ctx *context.APIContext) {
|
||||
file_path := ctx.Params(":filename")
|
||||
// file_path := data.FileName
|
||||
path := setting.LogRootPath+"/"+file_path
|
||||
b, err := PathExists(path)
|
||||
if !b || err != nil {
|
||||
// ctx.Error(http.StatusNotFound, "NoSuchFile", fmt.Sprintf("no such file: %s", file_path))
|
||||
ctx.JSON(200, &NotFoundError{Message: "no such file!"})
|
||||
} else {
|
||||
ctx.ServeFile(path, file_path)
|
||||
}
|
||||
}
|
||||
|
||||
func PathExists(path string) (bool, error) {
|
||||
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
|
@ -33,6 +33,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
"code.gitea.io/gitea/modules/userlog"
|
||||
)
|
||||
|
||||
// HTTP implmentation git smart HTTP protocol
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit d4c86e31027a1e099df108bf1c5ec1754c4578ed
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 0db5d458480499a7dcd1aa1040f3e77936400c06
|
Binary file not shown.
Loading…
Reference in New Issue