Files
browser/platform/api/source_rcon_handlers.go
T

70 lines
2.4 KiB
Go

package api
import (
"net/http"
"browser.local/platform/dto"
)
// sourceRCONCommands godoc
// @Summary Queue a direct SCUM Source RCON chat or command
// @Description Queues one non-retryable command without persisting the raw command, RCON password, or response body.
// @Tags scum-rcon
// @Accept json
// @Produce json
// @Param id path string true "Server instance ID"
// @Param body body dto.SourceRCONCommandRequestBody true "SCUM Source RCON chat or command request"
// @Success 202 {object} dto.SourceRCONCommandResponse
// @Failure 400 {object} dto.ErrorResponse
// @Failure 401 {object} dto.ErrorResponse
// @Failure 403 {object} dto.ErrorResponse
// @Failure 405 {object} dto.ErrorResponse
// @Router /api/v1/server-instances/{id}/rcon/commands [post]
func (h *coreHandlers) sourceRCONCommands(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
writeMethodNotAllowed(w, http.MethodPost)
return
}
request, err := decodeJSON[dto.SourceRCONCommandRequestBody](r)
if err != nil {
writeDecodeError(w, err)
return
}
dispatch, err := h.core.DispatchSourceRCONCommandForSession(bearerToken(r), request.ToDomain(r.PathValue("id")))
if err != nil {
writeServiceError(w, err)
return
}
writeJSON(w, http.StatusAccepted, dto.SourceRCONCommandFromDomain(dispatch))
}
// runSourceRCONInput godoc
// @Summary Read one transient SCUM Source RCON command
// @Description Returns the raw command exactly once only to the signed active Run lease; browser clients never receive this payload.
// @Tags run-job-channel
// @Accept json
// @Produce json
// @Param body body dto.SourceRCONExecutionInputRequest true "Fenced Source RCON input request"
// @Success 200 {object} dto.SourceRCONExecutionInputResponse
// @Failure 400 {object} dto.ErrorResponse
// @Failure 401 {object} dto.ErrorResponse
// @Failure 405 {object} dto.ErrorResponse
// @Router /api/v1/run/jobs/source-rcon-input [post]
func (h *coreHandlers) runSourceRCONInput(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
writeMethodNotAllowed(w, http.MethodPost)
return
}
request, err := decodeJSON[dto.SourceRCONExecutionInputRequest](r)
if err != nil {
writeDecodeError(w, err)
return
}
input, err := h.core.GetSourceRCONExecutionInput(request.ToDomain())
if err != nil {
writeServiceError(w, err)
return
}
writeJSON(w, http.StatusOK, dto.SourceRCONExecutionInputFromDomain(input))
}