@@ -14,7 +14,7 @@ import (
14
14
"regexp"
15
15
"strconv"
16
16
"strings"
17
- "time "
17
+ "errors "
18
18
19
19
"code.gitea.io/gitea/models"
20
20
"code.gitea.io/gitea/modules/context"
@@ -29,6 +29,11 @@ const (
29
29
metaMediaType = "application/vnd.git-lfs+json"
30
30
)
31
31
32
+ var (
33
+ errHashMismatch = errors .New ("Content hash does not match OID" )
34
+ errSizeMismatch = errors .New ("Content size does not match" )
35
+ )
36
+
32
37
// RequestVars contain variables from the HTTP request. Variables from routing, json body decoding, and
33
38
// some headers are stored.
34
39
type RequestVars struct {
@@ -48,27 +53,6 @@ type BatchVars struct {
48
53
Objects []* RequestVars `json:"objects"`
49
54
}
50
55
51
- // BatchResponse contains multiple object metadata Representation structures
52
- // for use with the batch API.
53
- type BatchResponse struct {
54
- Transfer string `json:"transfer,omitempty"`
55
- Objects []* Representation `json:"objects"`
56
- }
57
-
58
- // Representation is object metadata as seen by clients of the lfs server.
59
- type Representation struct {
60
- Oid string `json:"oid"`
61
- Size int64 `json:"size"`
62
- Actions map [string ]* link `json:"actions"`
63
- Error * ObjectError `json:"error,omitempty"`
64
- }
65
-
66
- // ObjectError defines the JSON structure returned to the client in case of an error
67
- type ObjectError struct {
68
- Code int `json:"code"`
69
- Message string `json:"message"`
70
- }
71
-
72
56
// Claims is a JWT Token Claims
73
57
type Claims struct {
74
58
RepoID int64
@@ -87,13 +71,6 @@ func (v *RequestVars) VerifyLink() string {
87
71
return setting .AppURL + path .Join (v .User , v .Repo + ".git" , "info/lfs/verify" )
88
72
}
89
73
90
- // link provides a structure used to build a hypermedia representation of an HTTP link.
91
- type link struct {
92
- Href string `json:"href"`
93
- Header map [string ]string `json:"header,omitempty"`
94
- ExpiresAt time.Time `json:"expires_at,omitempty"`
95
- }
96
-
97
74
var oidRegExp = regexp .MustCompile (`^[A-Fa-f0-9]+$` )
98
75
99
76
func isOidValid (oid string ) bool {
@@ -187,10 +164,10 @@ func getContentHandler(ctx *context.Context) {
187
164
}
188
165
}
189
166
190
- contentStore := & ContentStore {ObjectStorage : storage .LFS }
167
+ contentStore := & models. ContentStore {ObjectStorage : storage .LFS }
191
168
content , err := contentStore .Get (meta , fromByte )
192
169
if err != nil {
193
- if IsErrRangeNotSatisfiable (err ) {
170
+ if models . IsErrRangeNotSatisfiable (err ) {
194
171
writeStatus (ctx , http .StatusRequestedRangeNotSatisfiable )
195
172
} else {
196
173
// Errors are logged in contentStore.Get
@@ -292,7 +269,7 @@ func PostHandler(ctx *context.Context) {
292
269
ctx .Resp .Header ().Set ("Content-Type" , metaMediaType )
293
270
294
271
sentStatus := 202
295
- contentStore := & ContentStore {ObjectStorage : storage .LFS }
272
+ contentStore := & models. ContentStore {ObjectStorage : storage .LFS }
296
273
exist , err := contentStore .Exists (meta )
297
274
if err != nil {
298
275
log .Error ("Unable to check if LFS OID[%s] exist on %s / %s. Error: %v" , rv .Oid , rv .User , rv .Repo , err )
@@ -327,7 +304,7 @@ func BatchHandler(ctx *context.Context) {
327
304
328
305
bv := unpackbatch (ctx )
329
306
330
- var responseObjects []* Representation
307
+ var responseObjects []* models. Representation
331
308
332
309
// Create a response object
333
310
for _ , object := range bv .Objects {
@@ -353,7 +330,7 @@ func BatchHandler(ctx *context.Context) {
353
330
return
354
331
}
355
332
356
- contentStore := & ContentStore {ObjectStorage : storage .LFS }
333
+ contentStore := & models. ContentStore {ObjectStorage : storage .LFS }
357
334
358
335
meta , err := repository .GetLFSMetaObjectByOid (object .Oid )
359
336
if err == nil { // Object is found and exists
@@ -392,7 +369,7 @@ func BatchHandler(ctx *context.Context) {
392
369
393
370
ctx .Resp .Header ().Set ("Content-Type" , metaMediaType )
394
371
395
- respobj := & BatchResponse {Objects : responseObjects }
372
+ respobj := & models. BatchResponse {Objects : responseObjects }
396
373
397
374
enc := json .NewEncoder (ctx .Resp )
398
375
if err := enc .Encode (respobj ); err != nil {
@@ -411,7 +388,7 @@ func PutHandler(ctx *context.Context) {
411
388
return
412
389
}
413
390
414
- contentStore := & ContentStore {ObjectStorage : storage .LFS }
391
+ contentStore := & models. ContentStore {ObjectStorage : storage .LFS }
415
392
defer ctx .Req .Body .Close ()
416
393
if err := contentStore .Put (meta , ctx .Req .Body ); err != nil {
417
394
// Put will log the error itself
@@ -452,7 +429,7 @@ func VerifyHandler(ctx *context.Context) {
452
429
return
453
430
}
454
431
455
- contentStore := & ContentStore {ObjectStorage : storage .LFS }
432
+ contentStore := & models. ContentStore {ObjectStorage : storage .LFS }
456
433
ok , err := contentStore .Verify (meta )
457
434
if err != nil {
458
435
// Error will be logged in Verify
@@ -470,11 +447,11 @@ func VerifyHandler(ctx *context.Context) {
470
447
471
448
// Represent takes a RequestVars and Meta and turns it into a Representation suitable
472
449
// for json encoding
473
- func Represent (rv * RequestVars , meta * models.LFSMetaObject , download , upload bool ) * Representation {
474
- rep := & Representation {
450
+ func Represent (rv * RequestVars , meta * models.LFSMetaObject , download , upload bool ) * models. Representation {
451
+ rep := & models. Representation {
475
452
Oid : meta .Oid ,
476
453
Size : meta .Size ,
477
- Actions : make (map [string ]* link ),
454
+ Actions : make (map [string ]* models. Link ),
478
455
}
479
456
480
457
header := make (map [string ]string )
@@ -487,11 +464,11 @@ func Represent(rv *RequestVars, meta *models.LFSMetaObject, download, upload boo
487
464
}
488
465
489
466
if download {
490
- rep .Actions ["download" ] = & link {Href : rv .ObjectLink (), Header : header }
467
+ rep .Actions ["download" ] = & models. Link {Href : rv .ObjectLink (), Header : header }
491
468
}
492
469
493
470
if upload {
494
- rep .Actions ["upload" ] = & link {Href : rv .ObjectLink (), Header : header }
471
+ rep .Actions ["upload" ] = & models. Link {Href : rv .ObjectLink (), Header : header }
495
472
}
496
473
497
474
if upload && ! download {
@@ -504,7 +481,7 @@ func Represent(rv *RequestVars, meta *models.LFSMetaObject, download, upload boo
504
481
// This is only needed to workaround https://github.com/git-lfs/git-lfs/issues/3662
505
482
verifyHeader ["Accept" ] = metaMediaType
506
483
507
- rep .Actions ["verify" ] = & link {Href : rv .VerifyLink (), Header : verifyHeader }
484
+ rep .Actions ["verify" ] = & models. Link {Href : rv .VerifyLink (), Header : verifyHeader }
508
485
}
509
486
510
487
return rep
0 commit comments