1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Add API endpoint to request contents of multiple files simultaniously (#34139)

Adds an API POST endpoint under `/repos/{owner}/{repo}/file-contents`
which receives a list of paths and returns a list of the contents of
these files.

This API endpoint will be helpful for applications like headless CMS
(reference: https://github.com/sveltia/sveltia-cms/issues/198) which
need to retrieve a large number of files by reducing the amount of
needed API calls.

Close #33495

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Denys Konovalov
2025-04-21 19:20:11 +02:00
committed by GitHub
parent e947f309b1
commit 9a071a596f
24 changed files with 581 additions and 415 deletions

View File

@@ -6863,7 +6863,7 @@
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default the repositorys default branch (usually master)",
"description": "The name of the commit/branch/tag. Default to the repositorys default branch.",
"name": "ref",
"in": "query"
}
@@ -6966,7 +6966,7 @@
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default the repositorys default branch (usually master)",
"description": "The name of the commit/branch/tag. Default to the repositorys default branch.",
"name": "ref",
"in": "query"
}
@@ -7248,7 +7248,7 @@
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default the repositorys default branch (usually master)",
"description": "The name of the commit/branch/tag. Default to the repositorys default branch.",
"name": "ref",
"in": "query"
}
@@ -7263,6 +7263,105 @@
}
}
},
"/repos/{owner}/{repo}/file-contents": {
"get": {
"description": "See the POST method. This GET method supports to use JSON encoded request body in query parameter.",
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Get the metadata and contents of requested files",
"operationId": "repoGetFileContents",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default to the repositorys default branch.",
"name": "ref",
"in": "query"
},
{
"type": "string",
"description": "The JSON encoded body (see the POST request): {\"files\": [\"filename1\", \"filename2\"]}",
"name": "body",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"$ref": "#/responses/ContentsListResponse"
},
"404": {
"$ref": "#/responses/notFound"
}
}
},
"post": {
"description": "Uses automatic pagination based on default page size and max response size and returns the maximum allowed number of files. Files which could not be retrieved are null. Files which are too large are being returned with `encoding == null`, `content == null` and `size \u003e 0`, they can be requested separately by using the `download_url`.",
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Get the metadata and contents of requested files",
"operationId": "repoGetFileContentsPost",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "string",
"description": "The name of the commit/branch/tag. Default to the repositorys default branch.",
"name": "ref",
"in": "query"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/GetFilesOptions"
}
}
],
"responses": {
"200": {
"$ref": "#/responses/ContentsListResponse"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
},
"/repos/{owner}/{repo}/forks": {
"get": {
"produces": [
@@ -23623,6 +23722,11 @@
"format": "int64",
"x-go-name": "DefaultMaxBlobSize"
},
"default_max_response_size": {
"type": "integer",
"format": "int64",
"x-go-name": "DefaultMaxResponseSize"
},
"default_paging_num": {
"type": "integer",
"format": "int64",
@@ -23789,6 +23893,20 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"GetFilesOptions": {
"description": "GetFilesOptions options for retrieving metadate and content of multiple files",
"type": "object",
"properties": {
"files": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Files"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"GitBlobResponse": {
"description": "GitBlobResponse represents a git blob",
"type": "object",