55package lfs
66
77import (
8+ "net/http"
89 "strconv"
910 "strings"
1011
@@ -21,19 +22,19 @@ import (
2122func checkIsValidRequest (ctx * context.Context ) bool {
2223 if ! setting .LFS .StartServer {
2324 log .Debug ("Attempt to access LFS server but LFS server is disabled" )
24- writeStatus (ctx , 404 )
25+ writeStatus (ctx , http . StatusNotFound )
2526 return false
2627 }
2728 if ! MetaMatcher (ctx .Req ) {
2829 log .Info ("Attempt access LOCKs without accepting the correct media type: %s" , metaMediaType )
29- writeStatus (ctx , 400 )
30+ writeStatus (ctx , http . StatusBadRequest )
3031 return false
3132 }
3233 if ! ctx .IsSigned {
3334 user , _ , _ , err := parseToken (ctx .Req .Header .Get ("Authorization" ))
3435 if err != nil {
3536 ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
36- writeStatus (ctx , 401 )
37+ writeStatus (ctx , http . StatusUnauthorized )
3738 return false
3839 }
3940 ctx .User = user
@@ -44,23 +45,23 @@ func checkIsValidRequest(ctx *context.Context) bool {
4445func handleLockListOut (ctx * context.Context , repo * models.Repository , lock * models.LFSLock , err error ) {
4546 if err != nil {
4647 if models .IsErrLFSLockNotExist (err ) {
47- ctx .JSON (200 , api.LFSLockList {
48+ ctx .JSON (http . StatusOK , api.LFSLockList {
4849 Locks : []* api.LFSLock {},
4950 })
5051 return
5152 }
52- ctx .JSON (500 , api.LFSLockError {
53+ ctx .JSON (http . StatusInternalServerError , api.LFSLockError {
5354 Message : "unable to list locks : Internal Server Error" ,
5455 })
5556 return
5657 }
5758 if repo .ID != lock .RepoID {
58- ctx .JSON (200 , api.LFSLockList {
59+ ctx .JSON (http . StatusOK , api.LFSLockList {
5960 Locks : []* api.LFSLock {},
6061 })
6162 return
6263 }
63- ctx .JSON (200 , api.LFSLockList {
64+ ctx .JSON (http . StatusOK , api.LFSLockList {
6465 Locks : []* api.LFSLock {convert .ToLFSLock (lock )},
6566 })
6667}
@@ -86,7 +87,7 @@ func GetListLockHandler(ctx *context.Context) {
8687 authenticated := authenticate (ctx , repository , rv .Authorization , false )
8788 if ! authenticated {
8889 ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
89- ctx .JSON (401 , api.LFSLockError {
90+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
9091 Message : "You must have pull access to list locks" ,
9192 })
9293 return
@@ -106,7 +107,7 @@ func GetListLockHandler(ctx *context.Context) {
106107 if id != "" { //Case where we request a specific id
107108 v , err := strconv .ParseInt (id , 10 , 64 )
108109 if err != nil {
109- ctx .JSON (400 , api.LFSLockError {
110+ ctx .JSON (http . StatusBadRequest , api.LFSLockError {
110111 Message : "bad request : " + err .Error (),
111112 })
112113 return
@@ -133,7 +134,7 @@ func GetListLockHandler(ctx *context.Context) {
133134 lockList , err := models .GetLFSLockByRepoID (repository .ID , cursor , limit )
134135 if err != nil {
135136 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 {
137138 Message : "unable to list locks : Internal Server Error" ,
138139 })
139140 return
@@ -146,7 +147,7 @@ func GetListLockHandler(ctx *context.Context) {
146147 if limit > 0 && len (lockList ) == limit {
147148 next = strconv .Itoa (cursor + 1 )
148149 }
149- ctx .JSON (200 , api.LFSLockList {
150+ ctx .JSON (http . StatusOK , api.LFSLockList {
150151 Locks : lockListAPI ,
151152 Next : next ,
152153 })
@@ -175,7 +176,7 @@ func PostLockHandler(ctx *context.Context) {
175176 authenticated := authenticate (ctx , repository , authorization , true )
176177 if ! authenticated {
177178 ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
178- ctx .JSON (401 , api.LFSLockError {
179+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
179180 Message : "You must have push access to create locks" ,
180181 })
181182 return
@@ -199,26 +200,26 @@ func PostLockHandler(ctx *context.Context) {
199200 })
200201 if err != nil {
201202 if models .IsErrLFSLockAlreadyExist (err ) {
202- ctx .JSON (409 , api.LFSLockError {
203+ ctx .JSON (http . StatusConflict , api.LFSLockError {
203204 Lock : convert .ToLFSLock (lock ),
204205 Message : "already created lock" ,
205206 })
206207 return
207208 }
208209 if models .IsErrLFSUnauthorizedAction (err ) {
209210 ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
210- ctx .JSON (401 , api.LFSLockError {
211+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
211212 Message : "You must have push access to create locks : " + err .Error (),
212213 })
213214 return
214215 }
215216 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 {
217218 Message : "internal server error : Internal Server Error" ,
218219 })
219220 return
220221 }
221- ctx .JSON (201 , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
222+ ctx .JSON (http . StatusCreated , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
222223}
223224
224225// VerifyLockHandler list locks for verification
@@ -244,7 +245,7 @@ func VerifyLockHandler(ctx *context.Context) {
244245 authenticated := authenticate (ctx , repository , authorization , true )
245246 if ! authenticated {
246247 ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
247- ctx .JSON (401 , api.LFSLockError {
248+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
248249 Message : "You must have push access to verify locks" ,
249250 })
250251 return
@@ -263,7 +264,7 @@ func VerifyLockHandler(ctx *context.Context) {
263264 lockList , err := models .GetLFSLockByRepoID (repository .ID , cursor , limit )
264265 if err != nil {
265266 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 {
267268 Message : "unable to list locks : Internal Server Error" ,
268269 })
269270 return
@@ -281,7 +282,7 @@ func VerifyLockHandler(ctx *context.Context) {
281282 lockTheirsListAPI = append (lockTheirsListAPI , convert .ToLFSLock (l ))
282283 }
283284 }
284- ctx .JSON (200 , api.LFSLockListVerify {
285+ ctx .JSON (http . StatusOK , api.LFSLockListVerify {
285286 Ours : lockOursListAPI ,
286287 Theirs : lockTheirsListAPI ,
287288 Next : next ,
@@ -311,7 +312,7 @@ func UnLockHandler(ctx *context.Context) {
311312 authenticated := authenticate (ctx , repository , authorization , true )
312313 if ! authenticated {
313314 ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
314- ctx .JSON (401 , api.LFSLockError {
315+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
315316 Message : "You must have push access to delete locks" ,
316317 })
317318 return
@@ -332,16 +333,16 @@ func UnLockHandler(ctx *context.Context) {
332333 if err != nil {
333334 if models .IsErrLFSUnauthorizedAction (err ) {
334335 ctx .Resp .Header ().Set ("WWW-Authenticate" , "Basic realm=gitea-lfs" )
335- ctx .JSON (401 , api.LFSLockError {
336+ ctx .JSON (http . StatusUnauthorized , api.LFSLockError {
336337 Message : "You must have push access to delete locks : " + err .Error (),
337338 })
338339 return
339340 }
340341 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 {
342343 Message : "unable to delete lock : Internal Server Error" ,
343344 })
344345 return
345346 }
346- ctx .JSON (200 , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
347+ ctx .JSON (http . StatusOK , api.LFSLockResponse {Lock : convert .ToLFSLock (lock )})
347348}
0 commit comments