mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package convert
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/git/models/packages"
|
|
access_model "github.com/hanzoai/git/models/perm/access"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
api "github.com/hanzoai/git/modules/structs"
|
|
)
|
|
|
|
// ToPackage convert a packages.PackageDescriptor to api.Package
|
|
func ToPackage(ctx context.Context, pd *packages.PackageDescriptor, doer *user_model.User) (*api.Package, error) {
|
|
var repo *api.Repository
|
|
if pd.Repository != nil {
|
|
permission, err := access_model.GetDoerRepoPermission(ctx, pd.Repository, doer)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if permission.HasAnyUnitAccess() {
|
|
repo = ToRepo(ctx, pd.Repository, permission)
|
|
}
|
|
}
|
|
|
|
return &api.Package{
|
|
ID: pd.Version.ID,
|
|
Owner: ToUser(ctx, pd.Owner, doer),
|
|
Repository: repo,
|
|
Creator: ToUser(ctx, pd.Creator, doer),
|
|
Type: string(pd.Package.Type),
|
|
Name: pd.Package.Name,
|
|
Version: pd.Version.Version,
|
|
CreatedAt: pd.Version.CreatedUnix.AsTime(),
|
|
HTMLURL: pd.VersionHTMLURL(ctx),
|
|
}, nil
|
|
}
|
|
|
|
// ToPackageFile converts packages.PackageFileDescriptor to api.PackageFile
|
|
func ToPackageFile(pfd *packages.PackageFileDescriptor) *api.PackageFile {
|
|
return &api.PackageFile{
|
|
ID: pfd.File.ID,
|
|
Size: pfd.Blob.Size,
|
|
Name: pfd.File.Name,
|
|
HashMD5: pfd.Blob.HashMD5,
|
|
HashSHA1: pfd.Blob.HashSHA1,
|
|
HashSHA256: pfd.Blob.HashSHA256,
|
|
HashSHA512: pfd.Blob.HashSHA512,
|
|
}
|
|
}
|