github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/lfs/shared.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package lfs
     7  
     8  import (
     9  	"time"
    10  )
    11  
    12  const (
    13  	// MediaType contains the media type for LFS server requests
    14  	MediaType = "application/vnd.git-lfs+json"
    15  )
    16  
    17  // BatchRequest contains multiple requests processed in one batch operation.
    18  // https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests
    19  type BatchRequest struct {
    20  	Operation string     `json:"operation"`
    21  	Transfers []string   `json:"transfers,omitempty"`
    22  	Ref       *Reference `json:"ref,omitempty"`
    23  	Objects   []Pointer  `json:"objects"`
    24  }
    25  
    26  // Reference contains a git reference.
    27  // https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#ref-property
    28  type Reference struct {
    29  	Name string `json:"name"`
    30  }
    31  
    32  // Pointer contains LFS pointer data
    33  type Pointer struct {
    34  	Oid  string `json:"oid" xorm:"UNIQUE(s) INDEX NOT NULL"`
    35  	Size int64  `json:"size" xorm:"NOT NULL"`
    36  }
    37  
    38  // BatchResponse contains multiple object metadata Representation structures
    39  // for use with the batch API.
    40  // https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#successful-responses
    41  type BatchResponse struct {
    42  	Transfer string            `json:"transfer,omitempty"`
    43  	Objects  []*ObjectResponse `json:"objects"`
    44  }
    45  
    46  // ObjectResponse is object metadata as seen by clients of the LFS server.
    47  type ObjectResponse struct {
    48  	Pointer
    49  	Actions map[string]*Link `json:"actions,omitempty"`
    50  	Error   *ObjectError     `json:"error,omitempty"`
    51  }
    52  
    53  // Link provides a structure with information about how to access a object.
    54  type Link struct {
    55  	Href      string            `json:"href"`
    56  	Header    map[string]string `json:"header,omitempty"`
    57  	ExpiresAt *time.Time        `json:"expires_at,omitempty"`
    58  }
    59  
    60  // ObjectError defines the JSON structure returned to the client in case of an error.
    61  type ObjectError struct {
    62  	Code    int    `json:"code"`
    63  	Message string `json:"message"`
    64  }
    65  
    66  // PointerBlob associates a Git blob with a Pointer.
    67  type PointerBlob struct {
    68  	Hash string
    69  	Pointer
    70  }
    71  
    72  // ErrorResponse describes the error to the client.
    73  type ErrorResponse struct {
    74  	Message          string
    75  	DocumentationURL string `json:"documentation_url,omitempty"`
    76  	RequestID        string `json:"request_id,omitempty"`
    77  }