现在支持 Web Admin 面板 #4

Merged
LittleSheep merged 2 commits from features/web-admin into master 2024-01-01 10:18:28 +00:00
7 changed files with 54 additions and 5 deletions
Showing only changes of commit 14a7d936d2 - Show all commits

View File

@ -1,8 +1,14 @@
# Building Backend # Building Backend
FROM golang:alpine as roadsign-server FROM golang:alpine as roadsign-server
RUN apk add nodejs npm
WORKDIR /source WORKDIR /source
COPY . . COPY . .
WORKDIR /source/pkg/sideload/view
RUN npm install
RUN npm run build
WORKDIR /source
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs -o /dist ./pkg/cmd/server/main.go RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs -o /dist ./pkg/cmd/server/main.go
# Runtime # Runtime

29
pkg/sideload/processes.go Normal file
View File

@ -0,0 +1,29 @@
package sideload
import (
"code.smartsheep.studio/goatworks/roadsign/pkg/sign"
"github.com/gofiber/fiber/v2"
"github.com/samber/lo"
)
func getProcesses(c *fiber.Ctx) error {
processes := lo.FlatMap(sign.App.Sites, func(item *sign.SiteConfig, idx int) []*sign.ProcessInstance {
return item.Processes
})
return c.JSON(processes)
}
func getProcessLog(c *fiber.Ctx) error {
processes := lo.FlatMap(sign.App.Sites, func(item *sign.SiteConfig, idx int) []*sign.ProcessInstance {
return item.Processes
})
if target, ok := lo.Find(processes, func(item *sign.ProcessInstance) bool {
return item.ID == c.Params("id")
}); !ok {
return fiber.NewError(fiber.StatusNotFound)
} else {
return c.SendString(target.GetLogs())
}
}

View File

@ -1,8 +1,11 @@
package sideload package sideload
import ( import (
"code.smartsheep.studio/goatworks/roadsign/pkg/sideload/view"
"fmt" "fmt"
"github.com/gofiber/fiber/v2/middleware/filesystem"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"net/http"
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg" roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
@ -39,12 +42,21 @@ func InitSideload() *fiber.App {
}, },
})) }))
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(view.FS),
PathPrefix: "dist",
Index: "index.html",
NotFoundFile: "index.html",
}))
cgi := app.Group("/cgi").Name("CGI") cgi := app.Group("/cgi").Name("CGI")
{ {
cgi.All("/connectivity", responseConnectivity) cgi.All("/connectivity", responseConnectivity)
cgi.Get("/statistics", getStatistics) cgi.Get("/statistics", getStatistics)
cgi.Get("/sites", getSites) cgi.Get("/sites", getSites)
cgi.Get("/sites/cfg/:id", getSiteConfig) cgi.Get("/sites/cfg/:id", getSiteConfig)
cgi.Get("/processes", getProcesses)
cgi.Get("/processes/logs/:id", getProcessLog)
} }
webhooks := app.Group("/webhooks").Name("WebHooks") webhooks := app.Group("/webhooks").Name("WebHooks")

View File

@ -0,0 +1,2 @@
/dist
/node_modules

View File

@ -92,7 +92,7 @@ const submitting = ref(false)
const publishing = ref(false) const publishing = ref(false)
const editing = ref(false) const editing = ref(false)
const config = ref<string | null>(null) const config = ref<string | undefined>(undefined)
async function editConfig() { async function editConfig() {
const resp = await fetch(`/cgi/sites/cfg/${props.id}`) const resp = await fetch(`/cgi/sites/cfg/${props.id}`)
@ -101,6 +101,8 @@ async function editConfig() {
} }
async function syncConfig() { async function syncConfig() {
if (config.value == null) return
let content let content
try { try {
content = yaml.load(config.value) content = yaml.load(config.value)

View File

@ -21,7 +21,7 @@ import SitesTableExpand from "@/components/data/sites-table-expand.vue"
import SitesTableAction from "@/components/data/sites-table-action.vue" import SitesTableAction from "@/components/data/sites-table-action.vue"
import SitesTableAdd from "@/components/data/sites-table-add.vue" import SitesTableAdd from "@/components/data/sites-table-add.vue"
const columns = [ const columns: any[] = [
{ {
type: "expand", type: "expand",
renderExpand(row: any) { renderExpand(row: any) {

View File

@ -32,7 +32,6 @@ type ProcessInstance struct {
Logger strings.Builder `json:"-"` Logger strings.Builder `json:"-"`
Status ProcessStatus `json:"status"` Status ProcessStatus `json:"status"`
Logs string `json:"logs"`
} }
func (v *ProcessInstance) BootProcess() error { func (v *ProcessInstance) BootProcess() error {
@ -117,8 +116,7 @@ func (v *ProcessInstance) StopProcess() error {
} }
func (v *ProcessInstance) GetLogs() string { func (v *ProcessInstance) GetLogs() string {
v.Logs = v.Logger.String() return v.Logger.String()
return v.Logs
} }
func (v *RoadApp) PreheatProcesses(callbacks ...func(total int, success int)) { func (v *RoadApp) PreheatProcesses(callbacks ...func(total int, success int)) {