feat: vendor gitea 1.16.2

This commit is contained in:
2026-06-02 08:36:01 +00:00
parent 247cd60f69
commit 54798b4615
2145 changed files with 162965 additions and 126447 deletions
@@ -10,8 +10,11 @@ import (
"io"
"net/url"
"os"
"path"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
)
@@ -56,6 +59,37 @@ type Object interface {
Stat() (os.FileInfo, error)
}
// ServeDirectOptions customizes HTTP headers for a generated signed URL.
type ServeDirectOptions struct {
// Overrides the automatically detected MIME type.
ContentType string
}
// Safe defaults are applied only when not explicitly overridden by the caller.
func prepareServeDirectOptions(optsOptional *ServeDirectOptions, name string) (ret struct {
ContentType string
ContentDisposition string
},
) {
// Here we might not know the real filename, and it's quite inefficient to detect the MIME type by pre-fetching the object head.
// So we just do a quick detection by extension name, at least it works for the "View Raw File" for an LFS file on the Web UI.
// TODO: OBJECT-STORAGE-CONTENT-TYPE: need a complete solution and refactor for Azure in the future
if optsOptional != nil {
ret.ContentType = optsOptional.ContentType
}
name = path.Base(name)
if ret.ContentType == "" {
ext := path.Ext(name)
ret.ContentType = public.DetectWellKnownMimeType(ext)
}
// When using ServeDirect, the URL is from the object storage's web server,
// it is not the same origin as Gitea server, so it should be safe enough to use "inline" to render the content directly.
// If a browser doesn't support the content type to be displayed inline, browser will download with the filename.
ret.ContentDisposition = httplib.EncodeContentDispositionInline(name)
return ret
}
// ObjectStorage represents an object storage to handle a bucket and files
type ObjectStorage interface {
Open(path string) (Object, error)
@@ -67,8 +101,21 @@ type ObjectStorage interface {
Stat(path string) (os.FileInfo, error)
Delete(path string) error
URL(path, name, method string, reqParams url.Values) (*url.URL, error)
IterateObjects(path string, iterator func(path string, obj Object) error) error
// ServeDirectURL generates a "serve-direct" URL for the specified blob storage file,
// end user (browser) will use this URL to access the file directly from the object storage, bypassing Gitea server.
// Usually the link is time-limited (a few minutes) and contains a signature to ensure security.
// The generated URL must NOT use the same origin as Gitea server, otherwise it will cause security issues.
// * method defines which HTTP method is permitted for certain storage providers (e.g., MinIO).
// * opt allows customizing the Content-Type and Content-Disposition headers.
// TODO: need to merge "ServeDirect()" check into this function, avoid duplicate code and potential inconsistency.
ServeDirectURL(path, name, method string, opt *ServeDirectOptions) (*url.URL, error)
// IterateObjects calls the iterator function for each object in the storage with the given path as prefix
// The "fullPath" argument in callback is the full path in this storage.
// * IterateObjects("", ...): iterate all objects in this storage
// * IterateObjects("sub-path", ...): iterate all objects with "sub-path" as prefix in this storage, the "fullPath" will be like "sub-path/xxx"
IterateObjects(basePath string, iterator func(fullPath string, obj Object) error) error
}
// Copy copies a file from source ObjectStorage to dest ObjectStorage
@@ -131,7 +178,7 @@ var (
// Actions represents actions storage
Actions ObjectStorage = uninitializedStorage
// Actions Artifacts represents actions artifacts storage
// ActionsArtifacts Artifacts represents actions artifacts storage
ActionsArtifacts ObjectStorage = uninitializedStorage
)