5
5
package lfs
6
6
7
7
import (
8
+ "net/http"
8
9
"strconv"
9
10
"strings"
10
11
@@ -21,19 +22,19 @@ import (
21
22
func checkIsValidRequest (ctx * context.Context ) bool {
22
23
if ! setting .LFS .StartServer {
23
24
log .Debug ("Attempt to access LFS server but LFS server is disabled" )
24
- writeStatus (ctx , 404 )
25
+ writeStatus (ctx , http . StatusNotFound )
25
26
return false
26
27
}
27
28
if ! MetaMatcher (ctx .Req ) {
28
29
log .Info ("Attempt access LOCKs without accepting the correct media type: %s" , metaMediaType )
29
- writeStatus (ctx , 400 )
30
+ writeStatus (ctx , http . StatusBadRequest )
30
31
return false
31
32
}
32
33
if ! ctx .IsSigned {
33
34
user , _ , _ , err := parseToken (ctx .Req .Header .Get ("Authorization" ))
34
35
if err != nil {
35
36
ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
36
- writeStatus (ctx , 401 )
37
+ writeStatus (ctx , http . StatusUnauthorized )
37
38
return false
38
39
}
39
40
ctx .User = user
@@ -44,23 +45,23 @@ func checkIsValidRequest(ctx *context.Context) bool {
44
45
func handleLockListOut (ctx * context.Context , repo * models.Repository , lock * models.LFSLock , err error ) {
45
46
if err != nil {
46
47
if models .IsErrLFSLockNotExist (err ) {
47
- ctx .JSON (200 , api.LFSLockList {
48
+ ctx .JSON (http . StatusOK , api.LFSLockList {
48
49
Locks : []* api.LFSLock {},
49
50
})
50
51
return
51
52
}
52
- ctx .JSON (500 , api.LFSLockError {
53
+ ctx .JSON (http . StatusInternalServerError , api.LFSLockError {
53
54
Message : "unable to list locks : Internal Server Error" ,
54
55
})
55
56
return
56
57
}
57
58
if repo .ID != lock .RepoID {
58
- ctx .JSON (200 , api.LFSLockList {
59
+ ctx .JSON (http . StatusOK , api.LFSLockList {
59
60
Locks : []* api.LFSLock {},
60
61
})
61
62
return
62
63
}
63
- ctx .JSON (200 , api.LFSLockList {
64
+ ctx .JSON (http . StatusOK , api.LFSLockList {
64
65
Locks : []* api.LFSLock {convert .ToLFSLock (lock )},
65
66
})
66
67
}
@@ -86,7 +87,7 @@ func GetListLockHandler(ctx *context.Context) {
86
87
authenticated := authenticate (ctx , repository , rv .Authorization , false )
87
88
if ! authenticated {
88
89
ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
89
- ctx .JSON (401 , api.LFSLockError {
90
+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
90
91
Message : "You must have pull access to list locks" ,
91
92
})
92
93
return
@@ -106,7 +107,7 @@ func GetListLockHandler(ctx *context.Context) {
106
107
if id != "" { //Case where we request a specific id
107
108
v , err := strconv .ParseInt (id , 10 , 64 )
108
109
if err != nil {
109
- ctx .JSON (400 , api.LFSLockError {
110
+ ctx .JSON (http . StatusBadRequest , api.LFSLockError {
110
111
Message : "bad request : " + err .Error (),
111
112
})
112
113
return
@@ -133,7 +134,7 @@ func GetListLockHandler(ctx *context.Context) {
133
134
lockList , err := models .GetLFSLockByRepoID (repository .ID , cursor , limit )
134
135
if err != nil {
135
136
log .Error ("Unable to list locks for repository ID[%d]: Error: %v" , repository .ID , err )
136
- ctx .JSON (500 , api.LFSLockError {
137
+ ctx .JSON (http . StatusInternalServerError , api.LFSLockError {
137
138
Message : "unable to list locks : Internal Server Error" ,
138
139
})
139
140
return
@@ -146,7 +147,7 @@ func GetListLockHandler(ctx *context.Context) {
146
147
if limit > 0 && len (lockList ) == limit {
147
148
next = strconv .Itoa (cursor + 1 )
148
149
}
149
- ctx .JSON (200 , api.LFSLockList {
150
+ ctx .JSON (http . StatusOK , api.LFSLockList {
150
151
Locks : lockListAPI ,
151
152
Next : next ,
152
153
})
@@ -175,7 +176,7 @@ func PostLockHandler(ctx *context.Context) {
175
176
authenticated := authenticate (ctx , repository , authorization , true )
176
177
if ! authenticated {
177
178
ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
178
- ctx .JSON (401 , api.LFSLockError {
179
+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
179
180
Message : "You must have push access to create locks" ,
180
181
})
181
182
return
@@ -199,26 +200,26 @@ func PostLockHandler(ctx *context.Context) {
199
200
})
200
201
if err != nil {
201
202
if models .IsErrLFSLockAlreadyExist (err ) {
202
- ctx .JSON (409 , api.LFSLockError {
203
+ ctx .JSON (http . StatusConflict , api.LFSLockError {
203
204
Lock : convert .ToLFSLock (lock ),
204
205
Message : "already created lock" ,
205
206
})
206
207
return
207
208
}
208
209
if models .IsErrLFSUnauthorizedAction (err ) {
209
210
ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
210
- ctx .JSON (401 , api.LFSLockError {
211
+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
211
212
Message : "You must have push access to create locks : " + err .Error (),
212
213
})
213
214
return
214
215
}
215
216
log .Error ("Unable to CreateLFSLock in repository %-v at %s for user %-v: Error: %v" , repository , req .Path , ctx .User , err )
216
- ctx .JSON (500 , api.LFSLockError {
217
+ ctx .JSON (http . StatusInternalServerError , api.LFSLockError {
217
218
Message : "internal server error : Internal Server Error" ,
218
219
})
219
220
return
220
221
}
221
- ctx .JSON (201 , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
222
+ ctx .JSON (http . StatusCreated , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
222
223
}
223
224
224
225
// VerifyLockHandler list locks for verification
@@ -244,7 +245,7 @@ func VerifyLockHandler(ctx *context.Context) {
244
245
authenticated := authenticate (ctx , repository , authorization , true )
245
246
if ! authenticated {
246
247
ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
247
- ctx .JSON (401 , api.LFSLockError {
248
+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
248
249
Message : "You must have push access to verify locks" ,
249
250
})
250
251
return
@@ -263,7 +264,7 @@ func VerifyLockHandler(ctx *context.Context) {
263
264
lockList , err := models .GetLFSLockByRepoID (repository .ID , cursor , limit )
264
265
if err != nil {
265
266
log .Error ("Unable to list locks for repository ID[%d]: Error: %v" , repository .ID , err )
266
- ctx .JSON (500 , api.LFSLockError {
267
+ ctx .JSON (http . StatusInternalServerError , api.LFSLockError {
267
268
Message : "unable to list locks : Internal Server Error" ,
268
269
})
269
270
return
@@ -281,7 +282,7 @@ func VerifyLockHandler(ctx *context.Context) {
281
282
lockTheirsListAPI = append (lockTheirsListAPI , convert .ToLFSLock (l ))
282
283
}
283
284
}
284
- ctx .JSON (200 , api.LFSLockListVerify {
285
+ ctx .JSON (http . StatusOK , api.LFSLockListVerify {
285
286
Ours : lockOursListAPI ,
286
287
Theirs : lockTheirsListAPI ,
287
288
Next : next ,
@@ -311,7 +312,7 @@ func UnLockHandler(ctx *context.Context) {
311
312
authenticated := authenticate (ctx , repository , authorization , true )
312
313
if ! authenticated {
313
314
ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
314
- ctx .JSON (401 , api.LFSLockError {
315
+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
315
316
Message : "You must have push access to delete locks" ,
316
317
})
317
318
return
@@ -332,16 +333,16 @@ func UnLockHandler(ctx *context.Context) {
332
333
if err != nil {
333
334
if models .IsErrLFSUnauthorizedAction (err ) {
334
335
ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
335
- ctx .JSON (401 , api.LFSLockError {
336
+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
336
337
Message : "You must have push access to delete locks : " + err .Error (),
337
338
})
338
339
return
339
340
}
340
341
log .Error ("Unable to DeleteLFSLockByID[%d] by user %-v with force %t: Error: %v" , ctx .ParamsInt64 ("lid" ), ctx .User , req .Force , err )
341
- ctx .JSON (500 , api.LFSLockError {
342
+ ctx .JSON (http . StatusInternalServerError , api.LFSLockError {
342
343
Message : "unable to delete lock : Internal Server Error" ,
343
344
})
344
345
return
345
346
}
346
- ctx .JSON (200 , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
347
+ ctx .JSON (http . StatusOK , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
347
348
}
0 commit comments