1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-05 18:17:19 +00:00

Refactor repo contents API and add "contents-ext" API (#34822)

See the updated swagger document for details.
This commit is contained in:
wxiaoguang
2025-06-25 10:34:21 +08:00
committed by GitHub
parent 7be1a5e585
commit dbd9c69909
18 changed files with 481 additions and 262 deletions

View File

@ -15,15 +15,13 @@ import (
"strings"
)
// spec: https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md
const (
blobSizeCutoff = 1024
MetaFileMaxSize = 1024 // spec says the maximum size of a pointer file must be smaller than 1024
// MetaFileIdentifier is the string appearing at the first line of LFS pointer files.
// https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md
MetaFileIdentifier = "version https://git-lfs.github.com/spec/v1"
MetaFileIdentifier = "version https://git-lfs.github.com/spec/v1" // the first line of a pointer file
// MetaFileOidPrefix appears in LFS pointer files on a line before the sha256 hash.
MetaFileOidPrefix = "oid sha256:"
MetaFileOidPrefix = "oid sha256:" // spec says the only supported hash is sha256 at the moment
)
var (
@ -39,7 +37,7 @@ var (
// ReadPointer tries to read LFS pointer data from the reader
func ReadPointer(reader io.Reader) (Pointer, error) {
buf := make([]byte, blobSizeCutoff)
buf := make([]byte, MetaFileMaxSize)
n, err := io.ReadFull(reader, buf)
if err != nil && err != io.ErrUnexpectedEOF {
return Pointer{}, err
@ -65,6 +63,7 @@ func ReadPointerFromBuffer(buf []byte) (Pointer, error) {
return p, ErrInvalidStructure
}
// spec says "key/value pairs MUST be sorted alphabetically in ascending order (version is exception and must be the first)"
oid := strings.TrimPrefix(splitLines[1], MetaFileOidPrefix)
if len(oid) != 64 || !oidPattern.MatchString(oid) {
return p, ErrInvalidOIDFormat