✨ 现在支持 Web Admin 面板 #4
| @@ -1,8 +1,14 @@ | ||||
| # Building Backend | ||||
| FROM golang:alpine as roadsign-server | ||||
|  | ||||
| RUN apk add nodejs npm | ||||
|  | ||||
| WORKDIR /source | ||||
| 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 | ||||
|  | ||||
| # Runtime | ||||
|   | ||||
							
								
								
									
										29
									
								
								pkg/sideload/processes.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								pkg/sideload/processes.go
									
									
									
									
									
										Normal 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()) | ||||
| 	} | ||||
| } | ||||
| @@ -1,8 +1,11 @@ | ||||
| package sideload | ||||
|  | ||||
| import ( | ||||
| 	"code.smartsheep.studio/goatworks/roadsign/pkg/sideload/view" | ||||
| 	"fmt" | ||||
| 	"github.com/gofiber/fiber/v2/middleware/filesystem" | ||||
| 	jsoniter "github.com/json-iterator/go" | ||||
| 	"net/http" | ||||
|  | ||||
| 	roadsign "code.smartsheep.studio/goatworks/roadsign/pkg" | ||||
| 	"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.All("/connectivity", responseConnectivity) | ||||
| 		cgi.Get("/statistics", getStatistics) | ||||
| 		cgi.Get("/sites", getSites) | ||||
| 		cgi.Get("/sites/cfg/:id", getSiteConfig) | ||||
| 		cgi.Get("/processes", getProcesses) | ||||
| 		cgi.Get("/processes/logs/:id", getProcessLog) | ||||
| 	} | ||||
|  | ||||
| 	webhooks := app.Group("/webhooks").Name("WebHooks") | ||||
|   | ||||
							
								
								
									
										2
									
								
								pkg/sideload/view/.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								pkg/sideload/view/.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| /dist | ||||
| /node_modules | ||||
| @@ -92,7 +92,7 @@ const submitting = ref(false) | ||||
| const publishing = ref(false) | ||||
| const editing = ref(false) | ||||
|  | ||||
| const config = ref<string | null>(null) | ||||
| const config = ref<string | undefined>(undefined) | ||||
|  | ||||
| async function editConfig() { | ||||
|   const resp = await fetch(`/cgi/sites/cfg/${props.id}`) | ||||
| @@ -101,6 +101,8 @@ async function editConfig() { | ||||
| } | ||||
|  | ||||
| async function syncConfig() { | ||||
|   if (config.value == null) return | ||||
|  | ||||
|   let content | ||||
|   try { | ||||
|     content = yaml.load(config.value) | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import SitesTableExpand from "@/components/data/sites-table-expand.vue" | ||||
| import SitesTableAction from "@/components/data/sites-table-action.vue" | ||||
| import SitesTableAdd from "@/components/data/sites-table-add.vue" | ||||
|  | ||||
| const columns = [ | ||||
| const columns: any[] = [ | ||||
|   { | ||||
|     type: "expand", | ||||
|     renderExpand(row: any) { | ||||
|   | ||||
| @@ -32,7 +32,6 @@ type ProcessInstance struct { | ||||
| 	Logger strings.Builder `json:"-"` | ||||
|  | ||||
| 	Status ProcessStatus `json:"status"` | ||||
| 	Logs   string        `json:"logs"` | ||||
| } | ||||
|  | ||||
| func (v *ProcessInstance) BootProcess() error { | ||||
| @@ -117,8 +116,7 @@ func (v *ProcessInstance) StopProcess() error { | ||||
| } | ||||
|  | ||||
| func (v *ProcessInstance) GetLogs() string { | ||||
| 	v.Logs = v.Logger.String() | ||||
| 	return v.Logs | ||||
| 	return v.Logger.String() | ||||
| } | ||||
|  | ||||
| func (v *RoadApp) PreheatProcesses(callbacks ...func(total int, success int)) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user