diff --git a/docs/docs.go b/docs/docs.go index 2f0dacc9..fbf7f217 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1641,6 +1641,47 @@ const docTemplate = `{ "required": true } ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/api.ProcessReport" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/api.Error" + } + } + } + } + }, + "/api/v3/process/{id}/report/{at}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get the logs and the log history of a process.", + "produces": [ + "application/json" + ], + "tags": [ + "v16.?.?" + ], + "summary": "Get the logs of a process", + "operationId": "process-3-get-report-at", + "parameters": [ + { + "type": "string", + "description": "Process ID", + "name": "id", + "in": "path", + "required": true + } + ], "responses": { "200": { "description": "OK", diff --git a/docs/swagger.json b/docs/swagger.json index e8e48fc9..c1bb0ae7 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1634,6 +1634,47 @@ "required": true } ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/api.ProcessReport" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/api.Error" + } + } + } + } + }, + "/api/v3/process/{id}/report/{at}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get the logs and the log history of a process.", + "produces": [ + "application/json" + ], + "tags": [ + "v16.?.?" + ], + "summary": "Get the logs of a process", + "operationId": "process-3-get-report-at", + "parameters": [ + { + "type": "string", + "description": "Process ID", + "name": "id", + "in": "path", + "required": true + } + ], "responses": { "200": { "description": "OK", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index b648985e..cb179598 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2994,6 +2994,32 @@ paths: type: string produces: - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/api.ProcessReport' + "404": + description: Not Found + schema: + $ref: '#/definitions/api.Error' + security: + - ApiKeyAuth: [] + summary: Get the logs of a process + tags: + - v16.7.2 + /api/v3/process/{id}/report/{at}: + get: + description: Get the logs and the log history of a process. + operationId: process-3-get-report-at + parameters: + - description: Process ID + in: path + name: id + required: true + type: string + produces: + - application/json responses: "200": description: OK @@ -3011,7 +3037,7 @@ paths: - ApiKeyAuth: [] summary: Get the logs of a process tags: - - v16.7.2 + - v16.?.? /api/v3/process/{id}/state: get: description: Get the state and progress data of a process. diff --git a/http/handler/api/restream.go b/http/handler/api/restream.go index c61f363a..3f743f92 100644 --- a/http/handler/api/restream.go +++ b/http/handler/api/restream.go @@ -2,6 +2,7 @@ package api import ( "net/http" + "strconv" "strings" "github.com/datarhei/core/v16/http/api" @@ -320,7 +321,6 @@ func (h *RestreamHandler) GetState(c echo.Context) error { // @Param id path string true "Process ID" // @Success 200 {object} api.ProcessReport // @Failure 404 {object} api.Error -// @Failure 400 {object} api.Error // @Security ApiKeyAuth // @Router /api/v3/process/{id}/report [get] func (h *RestreamHandler) GetReport(c echo.Context) error { @@ -337,6 +337,42 @@ func (h *RestreamHandler) GetReport(c echo.Context) error { return c.JSON(http.StatusOK, report) } +// GetReport return the current log and the log history of a process +// @Summary Get the logs of a process +// @Description Get the logs and the log history of a process. +// @Tags v16.?.? +// @ID process-3-get-report-at +// @Produce json +// @Param id path string true "Process ID" +// @Success 200 {object} api.ProcessReport +// @Failure 404 {object} api.Error +// @Failure 400 {object} api.Error +// @Security ApiKeyAuth +// @Router /api/v3/process/{id}/report/{at} [get] +func (h *RestreamHandler) GetReportAt(c echo.Context) error { + id := util.PathParam(c, "id") + at, err := strconv.ParseInt(util.PathParam(c, "at"), 10, 64) + if err != nil { + return api.Err(http.StatusBadRequest, "Invalid process report date", "%s", err) + } + + l, err := h.restream.GetProcessLog(id) + if err != nil { + return api.Err(http.StatusNotFound, "Unknown process ID", "%s", err) + } + + report := api.ProcessReport{} + report.Unmarshal(l) + + for _, r := range report.History { + if r.CreatedAt == at { + return c.JSON(http.StatusOK, r) + } + } + + return api.Err(http.StatusNotFound, "Unknown process report date") +} + // Probe probes a process // @Summary Probe a process // @Description Probe an existing process to get a detailed stream information on the inputs. diff --git a/http/server.go b/http/server.go index 21c88ad4..7ce50f6e 100644 --- a/http/server.go +++ b/http/server.go @@ -555,6 +555,7 @@ func (s *server) setRoutesV3(v3 *echo.Group) { v3.GET("/process/:id/config", s.v3handler.restream.GetConfig) v3.GET("/process/:id/state", s.v3handler.restream.GetState) v3.GET("/process/:id/report", s.v3handler.restream.GetReport) + v3.GET("/process/:id/report/:at", s.v3handler.restream.GetReportAt) v3.GET("/process/:id/probe", s.v3handler.restream.Probe) v3.GET("/process/:id/metadata", s.v3handler.restream.GetProcessMetadata)