Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyBazaarPackageRating(packageName string, rating *PackageRating) bool
- func ApplyBazaarPackageRatingDistribution(region int, packageName string, distribution [5]int64) bool
- func ClearBazaarPackageRating(packageName string) bool
- func GetBazaarPackageREADME(ctx context.Context, repoURL, repoHash, pkgType string) (ret string)
- func GetBazaarPackageRatings(ctx context.Context, packageNames []string) (ret map[string]*PackageRating, available bool)
- func GetBazaarPackagesMap(pkgType, frontend string) (packagesMap map[string]*Package, err error)
- func GetCurrentBackend() string
- func GetExistingBazaarPackageNames(ctx context.Context, pkgType string, packageNames []string) ([]string, error)
- func GetInstalledPackageSize(pkgType, packageName, installPath string) (size int64, hSize string, err error)
- func GetPreferredLocaleString(m LocaleStrings, fallback string) string
- func HasBazaarPackage(ctx context.Context, pkgType, packageName string) (bool, error)
- func InitGitHubClient(token string)
- func InstallLocalPackage(sourcePath, installPath, pkgType, packageName string, update bool) error
- func InstalledPackageRevision(installPath string) (string, error)
- func IsBelowRequiredAppVersion(pkg *Package) bool
- func IsIncompatibleKernelPlugin(plugin *Package) bool
- func IsIncompatiblePlugin(plugin *Package, frontend string) bool
- func IsIncompatibleTheme(theme *Package, frontend string) bool
- func IsPluginProjectDeliveryPath(abs string) bool
- func IsTargetSupported(platforms []string, target string) bool
- func IsValidInstalledPackage(pkg *Package, dirName string) bool
- func IsValidPackageName(packageName string) bool
- func IsValidPackageType(pkgType string) bool
- func PackageDirContainsFile(dirPath string) (bool, error)
- func PackagePluginProject(ctx context.Context, taskID, expectedRevision string) (ret *util.PluginProjectArtifact, err error)
- func ParseInstalledPlugin(name, frontend string) (found bool, version, displayName string, ...)
- func ReadInstalledPackageDirs(basePath string) ([]os.DirEntry, error)
- func RefreshInstalledPackageREADME(pkg *Package, installPath, baseURLPath, repoURL, repoRef string)
- func RemoveInstalledPackageSizeCache(pkgType, packageName string)
- func RemovePackageInfo(pkgType, pkgName string)
- func ResolvePluginProjectArtifact(ctx context.Context, taskID, archivePath, expectedHash string) (ret string, err error)
- func SetInstalledPackageMetadata(pkg *Package, installPath, baseURLPath, pkgType string) bool
- func UninstallPackage(installPath string) (err error)
- type BazaarInfo
- type Funding
- type FundingLink
- type LocaleStrings
- type Package
- func ExtractLocalPackage(archivePath string) (pkgType string, pkg *Package, packagePath string, cleanup func(), err error)
- func ExtractLocalPackageWithHash(archivePath, expectedHash string) (pkgType string, pkg *Package, packagePath, packageHash string, cleanup func(), ...)
- func ExtractLocalPackageWithHashContext(ctx context.Context, archivePath, expectedHash string) (pkgType string, pkg *Package, packagePath, packageHash string, cleanup func(), ...)
- func FilterPackages(packages []*Package, keyword string) []*Package
- func GetBazaarPackages(pkgType string, frontend string) (packages []*Package)
- func InspectLocalPackageWithHash(archivePath, expectedHash string) (pkgType string, pkg *Package, packageHash string, err error)
- func ParsePackageJSON(filePath string) (ret *Package, err error)
- type PackageChoice
- type PackageInfo
- type PackageInstallOptions
- type PackageInstallResult
- type PackageLayout
- type PackageRating
- func GetBazaarPackageRating(ctx context.Context, packageName string) (rating *PackageRating, available bool)
- func GetBazaarPackageRatingAfterUpdate(ctx context.Context, region int, packageName string, distribution [5]int64) (rating *PackageRating, available bool)
- func GetCachedBazaarPackageRating(packageName string) (rating *PackageRating, available bool)
- type StageBazaarResult
- type StageIndex
- type StageRepo
Constants ¶
const ( PackageInvalidReasonMissingManifest = "missing-manifest" PackageInvalidReasonInvalidManifest = "invalid-manifest" PackageInvalidReasonNameMismatch = "name-mismatch" )
const ( // MaxLocalPackageArchiveSize 限制上传的本地集市包压缩文件大小。 MaxLocalPackageArchiveSize int64 = 128 * 1024 * 1024 )
const MissingInstalledRevision = "missing"
Variables ¶
var ( ErrInstalledRevisionConflict = util.NewTextFileError(util.TextFileRevisionConflict, errors.New("installed package changed")) ErrPackageHashConflict = errors.New("package_hash_conflict: package archive changed") )
Functions ¶
func ApplyBazaarPackageRating ¶
func ApplyBazaarPackageRating(packageName string, rating *PackageRating) bool
ApplyBazaarPackageRating 使用评分提交响应临时覆盖统一索引中的公开评分。
func ApplyBazaarPackageRatingDistribution ¶
func ApplyBazaarPackageRatingDistribution(region int, packageName string, distribution [5]int64) bool
ApplyBazaarPackageRatingDistribution 使用评分提交响应覆盖当前区域中单个包的分布。
func ClearBazaarPackageRating ¶
ClearBazaarPackageRating 使用评分取消响应临时隐藏统一索引中的旧公开评分。
func GetBazaarPackageREADME ¶
GetBazaarPackageREADME 获取集市包的在线 README。
func GetBazaarPackageRatings ¶
func GetBazaarPackageRatings(ctx context.Context, packageNames []string) (ret map[string]*PackageRating, available bool)
GetBazaarPackageRatings 获取指定包的全球公开评分。 第二个返回值表示公开评分索引是否可用。
func GetBazaarPackagesMap ¶
GetBazaarPackagesMap 返回按包名索引的在线集市包映射(plugins 和 themes 类型需要传递 frontend 参数)。
func GetCurrentBackend ¶
func GetCurrentBackend() string
func GetExistingBazaarPackageNames ¶
func GetExistingBazaarPackageNames(ctx context.Context, pkgType string, packageNames []string) ([]string, error)
GetExistingBazaarPackageNames 筛选存在于官方集市 Stage 索引中的包名。
func GetInstalledPackageSize ¶
func GetInstalledPackageSize(pkgType, packageName, installPath string) (size int64, hSize string, err error)
GetInstalledPackageSize 获取本地集市包的安装大小,结果缓存一分钟
func GetPreferredLocaleString ¶
func GetPreferredLocaleString(m LocaleStrings, fallback string) string
GetPreferredLocaleString 从 LocaleStrings 中按当前语种取值,无则回退 default、en、en_US(历史命名兼容),再回退 fallback。
func HasBazaarPackage ¶
HasBazaarPackage 判断指定名称是否存在于官方集市 Stage 索引中。
func InitGitHubClient ¶
func InitGitHubClient(token string)
func InstallLocalPackage ¶
InstallLocalPackage 从已解压并验证的目录安装本地集市包。
func InstalledPackageRevision ¶
InstalledPackageRevision 在与安装、卸载相同的锁内读取完整代码目录摘要。
func IsBelowRequiredAppVersion ¶
IsBelowRequiredAppVersion 判断集市包要求的最低应用版本是否高于当前版本。
func IsIncompatibleKernelPlugin ¶
IsIncompatibleKernelPlugin 判断内核插件是否与当前环境不兼容
func IsIncompatiblePlugin ¶
IsIncompatiblePlugin 判断插件是否与当前环境不兼容
func IsIncompatibleTheme ¶
IsIncompatibleTheme 判断主题是否与当前前端不兼容
func IsPluginProjectDeliveryPath ¶
IsPluginProjectDeliveryPath 识别宿主固定命名的导出副本;安装仍解析到受保护的权威制品。
func IsTargetSupported ¶
IsTargetSupported 检查 platforms 中是否包含 target 或 "all"
func IsValidInstalledPackage ¶
IsValidInstalledPackage 判断本地集市包的清单名是否与安装目录完全一致。
func IsValidPackageName ¶
IsValidPackageName 判断包名是否可以安全地用作跨平台目录名。
func IsValidPackageType ¶
IsValidPackageType 判断 pkgType 是否为集市支持的包类型(复数形式),以本地包清单映射为准。
func PackageDirContainsFile ¶
PackageDirContainsFile 判断集市包目录中是否递归包含实际文件。 忽略 macOS 自动生成的 .DS_Store,它不代表包内存在有效文件。
func PackagePluginProject ¶
func PackagePluginProject(ctx context.Context, taskID, expectedRevision string) (ret *util.PluginProjectArtifact, err error)
PackagePluginProject 在全部校验通过后发布内容寻址归档。 仅单个 ZIP 发布是原子的;清单另行保存,失败时不将其标记为可安装。
func ParseInstalledPlugin ¶
func ReadInstalledPackageDirs ¶
ReadInstalledPackageDirs 读取本地集市包的目录列表
func RefreshInstalledPackageREADME ¶
RefreshInstalledPackageREADME 使用已确认的在线版本来源重新渲染本地 README。
func RemoveInstalledPackageSizeCache ¶
func RemoveInstalledPackageSizeCache(pkgType, packageName string)
RemoveInstalledPackageSizeCache 删除本地集市包的安装大小缓存
func RemovePackageInfo ¶
func RemovePackageInfo(pkgType, pkgName string)
RemovePackageInfo 删除集市包的持久化信息
func ResolvePluginProjectArtifact ¶
func ResolvePluginProjectArtifact(ctx context.Context, taskID, archivePath, expectedHash string) (ret string, err error)
ResolvePluginProjectArtifact 仅解析当前有效的宿主归档,不开放任意受管文件。 安装仍须经过独立的原生工具权限确认。
func SetInstalledPackageMetadata ¶
SetInstalledPackageMetadata 设置本地集市包的通用元数据
func UninstallPackage ¶
UninstallPackage 卸载集市包
Types ¶
type BazaarInfo ¶
type BazaarInfo struct {
Packages map[string]map[string]*PackageInfo `json:"packages"`
}
BazaarInfo 集市的持久化信息
type Funding ¶
type Funding struct {
OpenCollective string `json:"openCollective"`
Patreon string `json:"patreon"`
GitHub string `json:"github"`
Custom []string `json:"custom"`
Links []FundingLink `json:"links,omitempty"`
}
type FundingLink ¶
type LocaleStrings ¶
LocaleStrings 表示按语种 key 的字符串表,key 为语种如 "default"、"en_US"、"zh_CN" 等
type Package ¶
type Package struct {
Author string `json:"author"`
URL string `json:"url"`
Version string `json:"version"`
MinAppVersion string `json:"minAppVersion"`
DisabledInPublish bool `json:"disabledInPublish"`
Kernels []string `json:"kernels"`
Backends []string `json:"backends"`
Frontends []string `json:"frontends"`
SettingsWindow bool `json:"settingsWindow,omitempty"` // 声明支持在独立设置窗口运行
BootAppearances []string `json:"bootAppearances,omitempty"`
DisplayName LocaleStrings `json:"displayName"`
Description LocaleStrings `json:"description"`
Readme LocaleStrings `json:"readme"`
Icon *string `json:"icon,omitempty"`
Preview *string `json:"preview,omitempty"`
Funding *Funding `json:"funding"`
Keywords []string `json:"keywords"`
Deprecated bool `json:"deprecated,omitempty"`
DeprecatedReason LocaleStrings `json:"deprecatedReason,omitempty"`
Choices []PackageChoice `json:"choices,omitempty"` // 替代包及其类型,可跨类型
PreferredFunding string `json:"preferredFunding"`
PreferredName string `json:"preferredName"`
PreferredDesc string `json:"preferredDesc"`
PreferredReadme string `json:"preferredReadme"`
PreferredDeprecatedReason string `json:"preferredDeprecatedReason,omitempty"`
Name string `json:"name"` // 包名,不一定是仓库名
RepoURL string `json:"repoURL"` // 形式为 https://github.com/owner/repo
RepoHash string `json:"repoHash"`
RepoRef string `json:"repoRef,omitempty"`
PreviewURL string `json:"previewURL"`
IconURL string `json:"iconURL"`
Installed bool `json:"installed"`
HasStorageData bool `json:"hasStorageData,omitempty"`
Outdated bool `json:"outdated"`
Current bool `json:"current"`
Created string `json:"created,omitempty"` // 首次上架时间,来自在线集市索引;缺失时未知
Updated string `json:"updated"`
Stars int `json:"stars"`
OpenIssues int `json:"openIssues"`
Size int64 `json:"size"`
HSize string `json:"hSize"`
InstallSize int64 `json:"installSize"`
HInstallSize string `json:"hInstallSize"`
InstallTime int64 `json:"installTime"`
UpdateTime int64 `json:"updateTime"`
HInstallDate string `json:"hInstallDate"`
HUpdated string `json:"hUpdated"`
Downloads int `json:"downloads"`
DisallowInstall bool `json:"disallowInstall"`
DisallowUpdate bool `json:"disallowUpdate"`
BazaarVersionUnsupported bool `json:"bazaarVersionUnsupported,omitempty"` // 在线版本要求的最低应用版本高于当前版本
UpdateRequiredMinAppVer string `json:"updateRequiredMinAppVer,omitempty"` // 升级目标要求的最小应用版本
InvalidReason string `json:"invalidReason,omitempty"` // 本地安装包异常原因
RatingAvailable bool `json:"ratingAvailable"` // 在线集市公开评分是否可用
Rating *PackageRating `json:"rating,omitempty"` // 在线集市公开评分
// 专用字段,nil 时不序列化
InstalledIncompatible *bool `json:"installedIncompatible,omitempty"` // 插件/主题:本地已安装版本是否不兼容
BazaarIncompatible *bool `json:"bazaarIncompatible,omitempty"` // 插件/主题:在线集市版本是否不兼容
Enabled *bool `json:"enabled,omitempty"` // Plugin:是否启用
UserDisabledInPublish *bool `json:"userDisabledInPublish,omitempty"` // Plugin:是否由用户在发布服务中禁用
Modes *[]string `json:"modes,omitempty"` // Theme:支持的模式列表
}
Package 描述了集市包元数据和传递给前端的其他信息。
- 集市包新增元数据字段需要同步修改 bazaar 的工作流,参考 https://github.com/siyuan-note/bazaar/commit/aa36d0003139c52d8e767c6e18a635be006323e2
func ExtractLocalPackage ¶
func ExtractLocalPackage(archivePath string) (pkgType string, pkg *Package, packagePath string, cleanup func(), err error)
ExtractLocalPackage 将本地集市包解压到临时目录并识别包类型。
func ExtractLocalPackageWithHash ¶
func ExtractLocalPackageWithHash(archivePath, expectedHash string) (pkgType string, pkg *Package, packagePath, packageHash string, cleanup func(), err error)
ExtractLocalPackageWithHash 从同一份已核验字节解压,不会在摘要验证后重新打开原始路径。
func ExtractLocalPackageWithHashContext ¶
func ExtractLocalPackageWithHashContext(ctx context.Context, archivePath, expectedHash string) (pkgType string, pkg *Package, packagePath, packageHash string, cleanup func(), err error)
ExtractLocalPackageWithHashContext 在核验与解压期间响应取消,未提交的临时内容会清理。 解压始终落在 temp,校验通过后才由安装流程拷入 data。
func FilterPackages ¶
FilterPackages 按关键词过滤集市包列表
func GetBazaarPackages ¶
GetBazaarPackages 返回指定类型的在线集市包列表(plugins 和 themes 类型需要传递 frontend 参数)。
func InspectLocalPackageWithHash ¶
func InspectLocalPackageWithHash(archivePath, expectedHash string) (pkgType string, pkg *Package, packageHash string, err error)
InspectLocalPackageWithHash 只在内存中查看同一份归档字节,不创建解压目录或修改安装目标。
func ParsePackageJSON ¶
ParsePackageJSON 解析集市包 JSON 文件
type PackageChoice ¶
PackageChoice 描述弃用包的一个替代包及其类型,由在线集市索引生成,供客户端跨类型跳转。
type PackageInfo ¶
type PackageInfo struct {
InstallTime int64 `json:"installTime"` // 安装时间戳(毫秒)
UpdateTime int64 `json:"updateTime"` // 更新时间戳(毫秒)
RepoURL string `json:"repoURL,omitempty"`
RepoRef string `json:"repoRef,omitempty"`
}
PackageInfo 集市包的持久化信息
type PackageInstallOptions ¶
type PackageInstallOptions struct {
ExpectedInstalledRevision string
BeforeReplace func() error
Context context.Context
Recheck func() error
}
PackageInstallOptions 只由宿主安装服务构造,回调在共用安装锁内执行。
type PackageInstallResult ¶
func InstallLocalPackageWithOptions ¶
func InstallLocalPackageWithOptions(sourcePath, installPath, pkgType, packageName string, update bool, options PackageInstallOptions) (result *PackageInstallResult, err error)
func InstallPackageWithOptions ¶
func InstallPackageWithOptions(repoURL, repoHash, repoRef, installPath, systemID, pkgType, packageName string, update bool, options PackageInstallOptions) (*PackageInstallResult, error)
InstallPackageWithOptions 将在线包替换也纳入目标版本校验。
type PackageLayout ¶
type PackageLayout struct {
BasePath string // 安装目录的父目录
Manifest string // 清单文件名
URLPath string // 前端访问该包目录的路径前缀
}
PackageLayout 描述一类集市包在文件系统中的安装布局。
func GetPackageLayout ¶
func GetPackageLayout(pkgType string) (layout PackageLayout, ok bool)
GetPackageLayout 集中维护包类型到安装目录、清单文件名和访问路径的映射。 清单文件名始终由 localPackageManifests 反查,避免同一映射散落在多处。
type PackageRating ¶
type PackageRating struct {
Average float64 `json:"average"`
Count int64 `json:"count"`
Distribution [5]int64 `json:"distribution"`
}
PackageRating 描述集市包的公开评分汇总。
func GetBazaarPackageRating ¶
func GetBazaarPackageRating(ctx context.Context, packageName string) (rating *PackageRating, available bool)
GetBazaarPackageRating 获取单个包的全球公开评分。
func GetBazaarPackageRatingAfterUpdate ¶
func GetBazaarPackageRatingAfterUpdate(ctx context.Context, region int, packageName string, distribution [5]int64) (rating *PackageRating, available bool)
GetBazaarPackageRatingAfterUpdate 将当前区域的评分响应与另一区域最后一次成功的数据合并。
func GetCachedBazaarPackageRating ¶
func GetCachedBazaarPackageRating(packageName string) (rating *PackageRating, available bool)
GetCachedBazaarPackageRating 仅使用最后一次成功的公开索引获取单个包评分。
type StageBazaarResult ¶
type StageBazaarResult struct {
StageIndex *StageIndex // stage 索引
BazaarStats map[string]*bazaarStats // 下载统计信息
BazaarRatings map[string]*PackageRating // 评分统计信息
RatingAvailable bool // 评分统计信息是否可用
Online bool // online 状态
StageErr error // stage 错误
}
type StageIndex ¶
type StageIndex struct {
Repos []*StageRepo `json:"repos"`
// contains filtered or unexported fields
}
type StageRepo ¶
type StageRepo struct {
URL string `json:"url"` // owner/repo@hash 形式
RepoRef string `json:"repoRef,omitempty"`
Created string `json:"created,omitempty"`
Updated string `json:"updated"`
Stars int `json:"stars"`
OpenIssues int `json:"openIssues"`
Size int64 `json:"size"`
InstallSize int64 `json:"installSize"`
// Package 与 stage/*.json 内嵌的完整 package 一致,可直接用于构建列表
Package *Package `json:"package"`
}