1package lfs
  2
  3import (
  4	"time"
  5)
  6
  7const (
  8	// MediaType contains the media type for LFS server requests.
  9	MediaType = "application/vnd.git-lfs+json"
 10
 11	// OperationDownload is the operation name for a download request.
 12	OperationDownload = "download"
 13
 14	// OperationUpload is the operation name for an upload request.
 15	OperationUpload = "upload"
 16
 17	// ActionDownload is the action name for a download request.
 18	ActionDownload = OperationDownload
 19
 20	// ActionUpload is the action name for an upload request.
 21	ActionUpload = OperationUpload
 22
 23	// ActionVerify is the action name for a verify request.
 24	ActionVerify = "verify"
 25
 26	// DefaultLocksLimit is the default number of locks to return in a single
 27	// request.
 28	DefaultLocksLimit = 20
 29)
 30
 31// Pointer contains LFS pointer data
 32type Pointer struct {
 33	Oid  string `json:"oid"`
 34	Size int64  `json:"size"`
 35}
 36
 37// PointerBlob associates a Git blob with a Pointer.
 38type PointerBlob struct {
 39	Hash string
 40	Pointer
 41}
 42
 43// ErrorResponse describes the error to the client.
 44type ErrorResponse struct {
 45	Message          string `json:"message,omitempty"`
 46	DocumentationURL string `json:"documentation_url,omitempty"`
 47	RequestID        string `json:"request_id,omitempty"`
 48}
 49
 50// BatchResponse contains multiple object metadata Representation structures
 51// for use with the batch API.
 52// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#successful-responses
 53type BatchResponse struct {
 54	Transfer string            `json:"transfer,omitempty"`
 55	Objects  []*ObjectResponse `json:"objects"`
 56	HashAlgo string            `json:"hash_algo,omitempty"`
 57}
 58
 59// ObjectResponse is object metadata as seen by clients of the LFS server.
 60type ObjectResponse struct {
 61	Pointer
 62	Actions map[string]*Link `json:"actions,omitempty"`
 63	Error   *ObjectError     `json:"error,omitempty"`
 64}
 65
 66// Link provides a structure with information about how to access a object.
 67type Link struct {
 68	Href      string            `json:"href"`
 69	Header    map[string]string `json:"header,omitempty"`
 70	ExpiresAt *time.Time        `json:"expires_at,omitempty"`
 71	ExpiresIn *time.Duration    `json:"expires_in,omitempty"`
 72}
 73
 74// ObjectError defines the JSON structure returned to the client in case of an error.
 75type ObjectError struct {
 76	Code    int    `json:"code"`
 77	Message string `json:"message"`
 78}
 79
 80// BatchRequest contains multiple requests processed in one batch operation.
 81// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests
 82type BatchRequest struct {
 83	Operation string     `json:"operation"`
 84	Transfers []string   `json:"transfers,omitempty"`
 85	Ref       *Reference `json:"ref,omitempty"`
 86	Objects   []Pointer  `json:"objects"`
 87	HashAlgo  string     `json:"hash_algo,omitempty"`
 88}
 89
 90// Reference contains a git reference.
 91// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#ref-property
 92type Reference struct {
 93	Name string `json:"name"`
 94}
 95
 96// AuthenticateResponse is the git-lfs-authenticate JSON response object.
 97type AuthenticateResponse struct {
 98	Header    map[string]string `json:"header"`
 99	Href      string            `json:"href"`
100	ExpiresIn time.Duration     `json:"expires_in"`
101	ExpiresAt time.Time         `json:"expires_at"`
102}
103
104// LockCreateRequest contains the request data for creating a lock.
105// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
106// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-create-request-schema.json
107type LockCreateRequest struct {
108	Path string    `json:"path"`
109	Ref  Reference `json:"ref,omitempty"`
110}
111
112// Owner contains the owner data for a lock.
113type Owner struct {
114	Name string `json:"name"`
115}
116
117// Lock contains the response data for creating a lock.
118// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
119// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-create-response-schema.json
120type Lock struct {
121	ID       string    `json:"id"`
122	Path     string    `json:"path"`
123	LockedAt time.Time `json:"locked_at"`
124	Owner    Owner     `json:"owner,omitempty"`
125}
126
127// LockDeleteRequest contains the request data for deleting a lock.
128// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
129// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-delete-request-schema.json
130type LockDeleteRequest struct {
131	Force bool      `json:"force,omitempty"`
132	Ref   Reference `json:"ref,omitempty"`
133}
134
135// LockListResponse contains the response data for listing locks.
136// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
137// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-list-response-schema.json
138type LockListResponse struct {
139	Locks      []Lock `json:"locks"`
140	NextCursor string `json:"next_cursor,omitempty"`
141}
142
143// LockVerifyRequest contains the request data for verifying a lock.
144type LockVerifyRequest struct {
145	Ref    Reference `json:"ref,omitempty"`
146	Cursor string    `json:"cursor,omitempty"`
147	Limit  int       `json:"limit,omitempty"`
148}
149
150// LockVerifyResponse contains the response data for verifying a lock.
151// https://github.com/git-lfs/git-lfs/blob/main/docs/api/locking.md
152// https://github.com/git-lfs/git-lfs/blob/main/locking/schemas/http-lock-verify-response-schema.json
153type LockVerifyResponse struct {
154	Ours       []Lock `json:"ours"`
155	Theirs     []Lock `json:"theirs"`
156	NextCursor string `json:"next_cursor,omitempty"`
157}
158
159// LockResponse contains the response data for a lock.
160type LockResponse struct {
161	Lock Lock `json:"lock"`
162	ErrorResponse
163}