(rw http.ResponseWriter, r *http.Request)
| 140 | } |
| 141 | |
| 142 | func (api *API) HandleReadFileLines(rw http.ResponseWriter, r *http.Request) { |
| 143 | ctx := r.Context() |
| 144 | |
| 145 | query := r.URL.Query() |
| 146 | parser := httpapi.NewQueryParamParser().RequiredNotEmpty("path") |
| 147 | path := parser.String(query, "", "path") |
| 148 | offset := parser.PositiveInt64(query, 1, "offset") |
| 149 | limit := parser.PositiveInt64(query, 0, "limit") |
| 150 | maxFileSize := parser.PositiveInt64(query, workspacesdk.DefaultMaxFileSize, "max_file_size") |
| 151 | maxLineBytes := parser.PositiveInt64(query, workspacesdk.DefaultMaxLineBytes, "max_line_bytes") |
| 152 | maxResponseLines := parser.PositiveInt64(query, workspacesdk.DefaultMaxResponseLines, "max_response_lines") |
| 153 | maxResponseBytes := parser.PositiveInt64(query, workspacesdk.DefaultMaxResponseBytes, "max_response_bytes") |
| 154 | parser.ErrorExcessParams(query) |
| 155 | if len(parser.Errors) > 0 { |
| 156 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 157 | Message: "Query parameters have invalid values.", |
| 158 | Validations: parser.Errors, |
| 159 | }) |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | resp := api.readFileLines(ctx, path, offset, limit, workspacesdk.ReadFileLinesLimits{ |
| 164 | MaxFileSize: maxFileSize, |
| 165 | MaxLineBytes: int(maxLineBytes), |
| 166 | MaxResponseLines: int(maxResponseLines), |
| 167 | MaxResponseBytes: int(maxResponseBytes), |
| 168 | }) |
| 169 | httpapi.Write(ctx, rw, http.StatusOK, resp) |
| 170 | } |
| 171 | |
| 172 | func (api *API) readFileLines(_ context.Context, path string, offset, limit int64, limits workspacesdk.ReadFileLinesLimits) ReadFileLinesResponse { |
| 173 | errResp := func(msg string) ReadFileLinesResponse { |
nothing calls this directly
no test coverage detected