Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0b1719

Browse files
committed
WIP Files
1 parent b928fff commit d0b1719

File tree

6 files changed

+267
-0
lines changed

6 files changed

+267
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,80 @@ const docTemplate = `{
303303
}
304304
}
305305
},
306+
"/files": {
307+
"post": {
308+
"security": [
309+
{
310+
"CoderSessionToken": []
311+
}
312+
],
313+
"consumes": [
314+
"application/x-tar"
315+
],
316+
"produces": [
317+
"application/json"
318+
],
319+
"tags": [
320+
"Files"
321+
],
322+
"summary": "Upload file",
323+
"operationId": "update-file",
324+
"parameters": [
325+
{
326+
"type": "string",
327+
"default": "application/x-tar",
328+
"description": "Content-Type must be ` + "`" + `application/x-tar` + "`" + `",
329+
"name": "Content-Type",
330+
"in": "header",
331+
"required": true
332+
},
333+
{
334+
"type": "file",
335+
"description": "File to be uploaded",
336+
"name": "file",
337+
"in": "formData",
338+
"required": true
339+
}
340+
],
341+
"responses": {
342+
"201": {
343+
"description": "Created",
344+
"schema": {
345+
"$ref": "#/definitions/codersdk.UploadResponse"
346+
}
347+
}
348+
}
349+
}
350+
},
351+
"/files/{fileID}": {
352+
"get": {
353+
"security": [
354+
{
355+
"CoderSessionToken": []
356+
}
357+
],
358+
"tags": [
359+
"Files"
360+
],
361+
"summary": "Get file by ID",
362+
"operationId": "get-file-by-id",
363+
"parameters": [
364+
{
365+
"type": "string",
366+
"format": "uuid",
367+
"description": "File ID",
368+
"name": "fileID",
369+
"in": "path",
370+
"required": true
371+
}
372+
],
373+
"responses": {
374+
"200": {
375+
"description": "OK"
376+
}
377+
}
378+
}
379+
},
306380
"/organizations/{organization-id}/templates/": {
307381
"post": {
308382
"security": [
@@ -2031,6 +2105,14 @@ const docTemplate = `{
20312105
}
20322106
}
20332107
},
2108+
"codersdk.UploadResponse": {
2109+
"type": "object",
2110+
"properties": {
2111+
"hash": {
2112+
"type": "string"
2113+
}
2114+
}
2115+
},
20342116
"codersdk.User": {
20352117
"type": "object",
20362118
"required": [

coderd/apidoc/swagger.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,72 @@
257257
}
258258
}
259259
},
260+
"/files": {
261+
"post": {
262+
"security": [
263+
{
264+
"CoderSessionToken": []
265+
}
266+
],
267+
"consumes": ["application/x-tar"],
268+
"produces": ["application/json"],
269+
"tags": ["Files"],
270+
"summary": "Upload file",
271+
"operationId": "update-file",
272+
"parameters": [
273+
{
274+
"type": "string",
275+
"default": "application/x-tar",
276+
"description": "Content-Type must be `application/x-tar`",
277+
"name": "Content-Type",
278+
"in": "header",
279+
"required": true
280+
},
281+
{
282+
"type": "file",
283+
"description": "File to be uploaded",
284+
"name": "file",
285+
"in": "formData",
286+
"required": true
287+
}
288+
],
289+
"responses": {
290+
"201": {
291+
"description": "Created",
292+
"schema": {
293+
"$ref": "#/definitions/codersdk.UploadResponse"
294+
}
295+
}
296+
}
297+
}
298+
},
299+
"/files/{fileID}": {
300+
"get": {
301+
"security": [
302+
{
303+
"CoderSessionToken": []
304+
}
305+
],
306+
"tags": ["Files"],
307+
"summary": "Get file by ID",
308+
"operationId": "get-file-by-id",
309+
"parameters": [
310+
{
311+
"type": "string",
312+
"format": "uuid",
313+
"description": "File ID",
314+
"name": "fileID",
315+
"in": "path",
316+
"required": true
317+
}
318+
],
319+
"responses": {
320+
"200": {
321+
"description": "OK"
322+
}
323+
}
324+
}
325+
},
260326
"/organizations/{organization-id}/templates/": {
261327
"post": {
262328
"security": [
@@ -1889,6 +1955,14 @@
18891955
}
18901956
}
18911957
},
1958+
"codersdk.UploadResponse": {
1959+
"type": "object",
1960+
"properties": {
1961+
"hash": {
1962+
"type": "string"
1963+
}
1964+
}
1965+
},
18921966
"codersdk.User": {
18931967
"type": "object",
18941968
"required": ["created_at", "email", "id", "username"],

coderd/files.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ const (
2323
tarMimeType = "application/x-tar"
2424
)
2525

26+
// @Summary Upload file
27+
// @ID update-file
28+
// @Security CoderSessionToken
29+
// @Produce json
30+
// @Accept application/x-tar
31+
// @Tags Files
32+
// @Param Content-Type header string true "Content-Type must be `application/x-tar`" default(application/x-tar)
33+
// @Param file formData file true "File to be uploaded"
34+
// @Success 201 {object} codersdk.UploadResponse
35+
// @Router /files [post]
2636
func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
2737
ctx := r.Context()
2838
apiKey := httpmw.APIKey(r)
@@ -88,6 +98,13 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
8898
})
8999
}
90100

101+
// @Summary Get file by ID
102+
// @ID get-file-by-id
103+
// @Security CoderSessionToken
104+
// @Tags Files
105+
// @Param fileID path string true "File ID" format(uuid)
106+
// @Success 200
107+
// @Router /files/{fileID} [get]
91108
func (api *API) fileByID(rw http.ResponseWriter, r *http.Request) {
92109
ctx := r.Context()
93110

docs/api/files.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Files
2+
3+
> This page is incomplete, stay tuned.
4+
5+
## Upload file
6+
7+
### Code samples
8+
9+
```shell
10+
# Example request using curl
11+
curl -X POST http://coder-server:8080/api/v2/files \
12+
-H 'Content-Type: application/x-www-form-urlencoded' \
13+
-H 'Accept: application/json' \
14+
-H 'Content-Type: application/x-tar' \
15+
-H 'Coder-Session-Token: API_KEY'
16+
```
17+
18+
`POST /files`
19+
20+
> Body parameter
21+
22+
```yaml
23+
file: string
24+
```
25+
26+
### Parameters
27+
28+
| Name | In | Type | Required | Description |
29+
| -------------- | ------ | -------------- | -------- | ---------------------------------------- |
30+
| `Content-Type` | header | string | true | Content-Type must be `application/x-tar` |
31+
| `body` | body | object | true | |
32+
| `» file` | body | string(binary) | true | File to be uploaded |
33+
34+
### Example responses
35+
36+
> 201 Response
37+
38+
```json
39+
{
40+
"hash": "string"
41+
}
42+
```
43+
44+
### Responses
45+
46+
| Status | Meaning | Description | Schema |
47+
| ------ | ------------------------------------------------------------ | ----------- | ------------------------------------------------------------ |
48+
| 201 | [Created](https://tools.ietf.org/html/rfc7231#section-6.3.2) | Created | [codersdk.UploadResponse](schemas.md#codersdkuploadresponse) |
49+
50+
To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.
51+
52+
## Get file by ID
53+
54+
### Code samples
55+
56+
```shell
57+
# Example request using curl
58+
curl -X GET http://coder-server:8080/api/v2/files/{fileID} \
59+
-H 'Coder-Session-Token: API_KEY'
60+
```
61+
62+
`GET /files/{fileID}`
63+
64+
### Parameters
65+
66+
| Name | In | Type | Required | Description |
67+
| -------- | ---- | ------------ | -------- | ----------- |
68+
| `fileID` | path | string(uuid) | true | File ID |
69+
70+
### Responses
71+
72+
| Status | Meaning | Description | Schema |
73+
| ------ | ------------------------------------------------------- | ----------- | ------ |
74+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | |
75+
76+
To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.

docs/api/schemas.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,20 @@ CreateParameterRequest is a structure used to create a new parameter value for a
27112711
| -------- | ------- | -------- | ------------ | ----------- |
27122712
| `ttl_ms` | integer | false | | |
27132713

2714+
## codersdk.UploadResponse
2715+
2716+
```json
2717+
{
2718+
"hash": "string"
2719+
}
2720+
```
2721+
2722+
### Properties
2723+
2724+
| Name | Type | Required | Restrictions | Description |
2725+
| ------ | ------ | -------- | ------------ | ----------- |
2726+
| `hash` | string | false | | |
2727+
27142728
## codersdk.User
27152729

27162730
```json

docs/manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@
345345
"title": "Authorization",
346346
"path": "./api/authorization.md"
347347
},
348+
{
349+
"title": "Files",
350+
"path": "./api/files.md"
351+
},
348352
{
349353
"title": "Templates",
350354
"path": "./api/templates.md"

0 commit comments

Comments
 (0)