c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package common
|
|
|
|
import (
|
|
"path"
|
|
"time"
|
|
|
|
repo_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/repo"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/git"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/httpcache"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/httplib"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/structs"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/services/context"
|
|
)
|
|
|
|
// ServeBlob download a git.Blob
|
|
func ServeBlob(ctx *context.Base, repo *repo_model.Repository, filePath string, blob *git.Blob, lastModified *time.Time) error {
|
|
if httpcache.HandleGenericETagPrivateCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
|
|
return nil
|
|
}
|
|
|
|
if err := repo.LoadOwner(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
dataRc, err := blob.DataAsync()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer dataRc.Close()
|
|
|
|
if lastModified == nil {
|
|
lastModified = new(time.Time)
|
|
}
|
|
httplib.ServeUserContentByReader(ctx.Req, ctx.Resp, blob.Size(), dataRc, httplib.ServeHeaderOptions{
|
|
Filename: path.Base(filePath),
|
|
CacheIsPublic: !repo.IsPrivate && repo.Owner.Visibility == structs.VisibleTypePublic,
|
|
CacheDuration: setting.StaticCacheTime,
|
|
LastModified: *lastModified,
|
|
})
|
|
return nil
|
|
}
|