bab29a83fa
Sweep all .go imports + go.mod, plus module-path refs in .golangci.yml, Dockerfile, swagger templates, locale example, and repo/wiki URLs (MokoGitea-Fork -> MokoGIT). Part of the MokoGIT rebrand. Claude-Session: https://claude.ai/code/session_01Bqe7fAuHQeiLueYfeHFrHw
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 "code.mokoconsulting.tech/MokoConsulting/MokoGIT/models/repo"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/git"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/httpcache"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/httplib"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/setting"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/structs"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/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
|
|
}
|