@@ -65,49 +65,12 @@ func CheckAcceptMediaType(ctx *context.Context) {
65
65
}
66
66
}
67
67
68
- func getAuthenticatedRepoAndMeta (ctx * context.Context , rc * requestContext , p lfs_module.Pointer , requireWrite bool ) (* models.LFSMetaObject , * models.Repository ) {
69
- if ! p .IsValid () {
70
- log .Info ("Attempt to access invalid LFS OID[%s] in %s/%s" , p .Oid , rc .User , rc .Repo )
71
- writeStatus (ctx , http .StatusUnprocessableEntity )
72
- return nil , nil
73
- }
74
-
75
- repository := getAuthenticatedRepository (ctx , rc , requireWrite )
76
- if repository == nil {
77
- return nil , nil
78
- }
79
-
80
- meta , err := repository .GetLFSMetaObjectByOid (p .Oid )
81
- if err != nil {
82
- log .Error ("Unable to get LFS OID[%s] Error: %v" , p .Oid , err )
83
- writeStatus (ctx , http .StatusNotFound )
84
- return nil , nil
85
- }
86
-
87
- return meta , repository
88
- }
89
-
90
- func getAuthenticatedRepository (ctx * context.Context , rc * requestContext , requireWrite bool ) * models.Repository {
91
- repository , err := models .GetRepositoryByOwnerAndName (rc .User , rc .Repo )
92
- if err != nil {
93
- log .Error ("Unable to get repository: %s/%s Error: %v" , rc .User , rc .Repo , err )
94
- writeStatus (ctx , http .StatusNotFound )
95
- return nil
96
- }
97
-
98
- if ! authenticate (ctx , repository , rc .Authorization , requireWrite ) {
99
- requireAuth (ctx )
100
- return nil
101
- }
102
-
103
- return repository
104
- }
105
-
106
68
// DownloadHandler gets the content from the content store
107
69
func DownloadHandler (ctx * context.Context ) {
108
- rc , p := unpack (ctx )
70
+ rc := getRequestContext (ctx )
71
+ p := lfs_module.Pointer {Oid : ctx .Params ("oid" )}
109
72
110
- meta , _ := getAuthenticatedRepoAndMeta (ctx , rc , p , false )
73
+ meta := getAuthenticatedMeta (ctx , rc , p , false )
111
74
if meta == nil {
112
75
return
113
76
}
@@ -253,7 +216,7 @@ func BatchHandler(ctx *context.Context) {
253
216
if meta == nil {
254
217
_ , err := models .NewLFSMetaObject (& models.LFSMetaObject {Pointer : p , RepositoryID : repository .ID })
255
218
if err != nil {
256
- log .Error ("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v" , p .Oid , rc .User , rc .Repo , metaErr )
219
+ log .Error ("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v" , p .Oid , rc .User , rc .Repo , err )
257
220
writeStatus (ctx , http .StatusInternalServerError )
258
221
return
259
222
}
@@ -322,7 +285,7 @@ func UploadHandler(ctx *context.Context) {
322
285
writeStatus (ctx , http .StatusInternalServerError )
323
286
return
324
287
}
325
- if m .Existing || exisits {
288
+ if meta .Existing || exists {
326
289
ctx .Resp .WriteHeader (http .StatusOK )
327
290
return
328
291
}
@@ -351,7 +314,7 @@ func VerifyHandler(ctx *context.Context) {
351
314
352
315
rc := getRequestContext (ctx )
353
316
354
- meta , _ := getAuthenticatedRepoAndMeta (ctx , rc , p , true )
317
+ meta := getAuthenticatedMeta (ctx , rc , p , true )
355
318
if meta == nil {
356
319
return
357
320
}
@@ -385,6 +348,44 @@ func getRequestContext(ctx *context.Context) *requestContext {
385
348
}
386
349
}
387
350
351
+ func getAuthenticatedMeta (ctx * context.Context , rc * requestContext , p lfs_module.Pointer , requireWrite bool ) * models.LFSMetaObject {
352
+ if ! p .IsValid () {
353
+ log .Info ("Attempt to access invalid LFS OID[%s] in %s/%s" , p .Oid , rc .User , rc .Repo )
354
+ writeStatus (ctx , http .StatusUnprocessableEntity )
355
+ return nil
356
+ }
357
+
358
+ repository := getAuthenticatedRepository (ctx , rc , requireWrite )
359
+ if repository == nil {
360
+ return nil
361
+ }
362
+
363
+ meta , err := repository .GetLFSMetaObjectByOid (p .Oid )
364
+ if err != nil {
365
+ log .Error ("Unable to get LFS OID[%s] Error: %v" , p .Oid , err )
366
+ writeStatus (ctx , http .StatusNotFound )
367
+ return nil
368
+ }
369
+
370
+ return meta
371
+ }
372
+
373
+ func getAuthenticatedRepository (ctx * context.Context , rc * requestContext , requireWrite bool ) * models.Repository {
374
+ repository , err := models .GetRepositoryByOwnerAndName (rc .User , rc .Repo )
375
+ if err != nil {
376
+ log .Error ("Unable to get repository: %s/%s Error: %v" , rc .User , rc .Repo , err )
377
+ writeStatus (ctx , http .StatusNotFound )
378
+ return nil
379
+ }
380
+
381
+ if ! authenticate (ctx , repository , rc .Authorization , requireWrite ) {
382
+ requireAuth (ctx )
383
+ return nil
384
+ }
385
+
386
+ return repository
387
+ }
388
+
388
389
func buildObjectResponse (rc * requestContext , pointer lfs_module.Pointer , download , upload bool , err * lfs_module.ObjectError ) * lfs_module.ObjectResponse {
389
390
rep := & lfs_module.ObjectResponse {Pointer : pointer }
390
391
if err != nil {
@@ -411,13 +412,6 @@ func buildObjectResponse(rc *requestContext, pointer lfs_module.Pointer, downloa
411
412
return rep
412
413
}
413
414
414
- func unpack (ctx * context.Context ) (* requestContext , lfs_module.Pointer ) {
415
- rc := getRequestContext (ctx )
416
- p := lfs_module.Pointer {Oid : ctx .Params ("oid" )}
417
-
418
- return rc , p
419
- }
420
-
421
415
func writeStatus (ctx * context.Context , status int ) {
422
416
writeStatusMessage (ctx , status , http .StatusText (status ))
423
417
}
0 commit comments