mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
Implement external assets
This commit is contained in:
parent
2e234300a2
commit
a61e7c7a39
22 changed files with 826 additions and 119 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
"code.gitea.io/gitea/services/context/upload"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
@ -43,6 +44,28 @@ func NewAttachment(ctx context.Context, attach *repo_model.Attachment, file io.R
|
|||
return attach, err
|
||||
}
|
||||
|
||||
func NewExternalAttachment(ctx context.Context, attach *repo_model.Attachment) (*repo_model.Attachment, error) {
|
||||
if attach.RepoID == 0 {
|
||||
return nil, fmt.Errorf("attachment %s should belong to a repository", attach.Name)
|
||||
}
|
||||
if attach.ExternalURL == "" {
|
||||
return nil, fmt.Errorf("attachment %s should have a external url", attach.Name)
|
||||
}
|
||||
if !validation.IsValidExternalURL(attach.ExternalURL) {
|
||||
return nil, repo_model.ErrInvalidExternalURL{ExternalURL: attach.ExternalURL}
|
||||
}
|
||||
|
||||
attach.UUID = uuid.New().String()
|
||||
|
||||
eng := db.GetEngine(ctx)
|
||||
if attach.NoAutoTime {
|
||||
eng.NoAutoTime()
|
||||
}
|
||||
_, err := eng.Insert(attach)
|
||||
|
||||
return attach, err
|
||||
}
|
||||
|
||||
// UploadAttachment upload new attachment into storage and update database
|
||||
func UploadAttachment(ctx context.Context, file io.Reader, allowedTypes string, fileSize int64, attach *repo_model.Attachment) (*repo_model.Attachment, error) {
|
||||
buf := make([]byte, 1024)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue