fix build view ui

This commit is contained in:
wxiaoguang
2022-10-21 22:30:06 +08:00
committed by Jason Song
parent 34a1bb2c20
commit ea5e769428
8 changed files with 40 additions and 71 deletions

View File

@@ -1,51 +0,0 @@
package dev
import (
"fmt"
"io"
"net/http"
"os"
"sync"
"time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/dbfs"
"code.gitea.io/gitea/modules/context"
)
var demoLogWriterOnce sync.Once
func TermDemo(ctx *context.Context) {
demoLogWriterOnce.Do(func() {
go func() {
f, _ := dbfs.OpenFile(db.DefaultContext, "termdemo.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND)
count := 0
for {
count++
s := fmt.Sprintf("\x1B[1;3;31mDemo Log\x1B[0m, count=%d\r\n", count)
_, _ = f.Write([]byte(s))
time.Sleep(time.Second)
}
}()
})
cmd := ctx.FormString("cmd")
if cmd == "tail" {
offset := ctx.FormInt64("offset")
f, _ := dbfs.OpenFile(db.DefaultContext, "termdemo.log", os.O_RDONLY)
if offset == -1 {
_, _ = f.Seek(0, io.SeekEnd)
} else {
_, _ = f.Seek(offset, io.SeekStart)
}
buf, _ := io.ReadAll(f)
offset, _ = f.Seek(0, io.SeekCurrent)
ctx.JSON(http.StatusOK, map[string]interface{}{
"offset": offset,
"content": string(buf),
})
return
}
ctx.HTML(http.StatusOK, "dev/termdemo")
}

View File

@@ -25,6 +25,7 @@ func View(ctx *context.Context) {
run := job.Run
ctx.Data["Build"] = run
// ctx.Data["Build"] = &bots_model.Run{Title: "test", Index: 123, Status: bots_model.StatusRunning}
ctx.HTML(http.StatusOK, tplViewBuild)
}

View File

@@ -19,7 +19,6 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/metrics"
"code.gitea.io/gitea/modules/public"
_ "code.gitea.io/gitea/modules/session" // to registers all internal adapters
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/structs"
@@ -46,6 +45,8 @@ import (
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/lfs"
_ "code.gitea.io/gitea/modules/session" // to registers all internal adapters
"gitea.com/go-chi/captcha"
"gitea.com/go-chi/session"
"github.com/NYTimes/gziphandler"
@@ -661,6 +662,7 @@ func RegisterRoutes(m *web.Route) {
if !setting.IsProd {
m.Any("/dev/termdemo", dev.TermDemo)
m.Get("/template/*", dev.TemplatePreview)
}
reqRepoAdmin := context.RequireRepoAdmin()