重构部分 block 逻辑,调整 js 执行器的 kv 流程
This commit is contained in:
@@ -12,17 +12,15 @@ import (
|
||||
type PageDomain struct {
|
||||
*ServerMeta
|
||||
|
||||
alias *DomainAlias
|
||||
baseDomain string
|
||||
defaultBranch string
|
||||
}
|
||||
|
||||
func NewPageDomain(meta *ServerMeta, alias *DomainAlias, baseDomain, defaultBranch string) *PageDomain {
|
||||
func NewPageDomain(meta *ServerMeta, baseDomain, defaultBranch string) *PageDomain {
|
||||
return &PageDomain{
|
||||
baseDomain: baseDomain,
|
||||
defaultBranch: defaultBranch,
|
||||
ServerMeta: meta,
|
||||
alias: alias,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +38,7 @@ func (p *PageDomain) ParseDomainMeta(ctx context.Context, domain, path, branch s
|
||||
}
|
||||
pathArr := strings.Split(strings.TrimPrefix(path, "/"), "/")
|
||||
if !strings.HasSuffix(domain, "."+p.baseDomain) {
|
||||
alias, err := p.alias.Query(ctx, domain) // 确定 alias 是否存在内容
|
||||
alias, err := p.Alias.Query(ctx, domain) // 确定 alias 是否存在内容
|
||||
if err != nil {
|
||||
zap.L().Warn("unknown domain", zap.String("base", p.baseDomain), zap.String("domain", domain), zap.Error(err))
|
||||
return nil, os.ErrNotExist
|
||||
@@ -83,10 +81,6 @@ func (p *PageDomain) returnMeta(ctx context.Context, owner, repo, branch string,
|
||||
result.Owner = owner
|
||||
result.Repo = repo
|
||||
result.Path = strings.Join(path, "/")
|
||||
// todo: 优化保存逻辑 ,减少写入
|
||||
if err = p.alias.Bind(ctx, meta.Alias, result.Owner, result.Repo, branch); err != nil {
|
||||
zap.L().Warn("alias binding error.", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
type ServerMeta struct {
|
||||
Backend
|
||||
Domain string
|
||||
Alias *DomainAlias
|
||||
|
||||
client *http.Client
|
||||
cache *tools.KVCache[PageMetaContent]
|
||||
@@ -70,10 +71,11 @@ func (m *PageMetaContent) String() string {
|
||||
return string(marshal)
|
||||
}
|
||||
|
||||
func NewServerMeta(client *http.Client, backend Backend, domain string, cache kv.KV, ttl time.Duration) *ServerMeta {
|
||||
func NewServerMeta(client *http.Client, backend Backend, domain string, alias *DomainAlias, cache kv.KV, ttl time.Duration) *ServerMeta {
|
||||
return &ServerMeta{
|
||||
Backend: backend,
|
||||
Domain: domain,
|
||||
Alias: alias,
|
||||
client: client,
|
||||
cache: tools.NewCache[PageMetaContent](cache, "meta", ttl),
|
||||
locker: utils.NewLocker(),
|
||||
@@ -144,7 +146,11 @@ func (s *ServerMeta) GetMeta(ctx context.Context, owner, repo, branch string) (*
|
||||
_ = s.cache.Store(ctx, key, *rel)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// todo: 优化保存逻辑 ,减少写入
|
||||
if err = s.Alias.Bind(ctx, rel.Alias, owner, repo, branch); err != nil {
|
||||
zap.L().Warn("alias binding error.", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
_ = s.cache.Store(ctx, key, *rel)
|
||||
return rel, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user