feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,81 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sea-vhost/internal/hosting"
|
||||
"sea-vhost/internal/isolation"
|
||||
"sea-vhost/internal/scope"
|
||||
"sea-vhost/internal/store"
|
||||
)
|
||||
|
||||
func (s *Projects) WebsiteSettings(ctx context.Context, user store.User, projectID, siteID uint64) (hosting.WebsiteSettings, error) {
|
||||
p, e := s.authorizedProject(ctx, user, projectID)
|
||||
if e != nil {
|
||||
return hosting.WebsiteSettings{}, e
|
||||
}
|
||||
if _, e = s.store.Site(ctx, p.TenantID, p.ID, siteID); e != nil {
|
||||
return hosting.WebsiteSettings{}, e
|
||||
}
|
||||
return s.store.WebsiteSettings(ctx, siteID)
|
||||
}
|
||||
func (s *Projects) SetWebsiteSettings(ctx context.Context, user store.User, projectID, siteID uint64, v hosting.WebsiteSettings) error {
|
||||
if e := v.Validate(); e != nil {
|
||||
return e
|
||||
}
|
||||
p, e := s.authorizedProject(ctx, user, projectID)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
ctx = scope.WithProject(ctx, p.ID, p.NodeID)
|
||||
if e = s.ensureTenantWritable(ctx, p.TenantID); e != nil {
|
||||
return e
|
||||
}
|
||||
site, e := s.store.Site(ctx, p.TenantID, p.ID, siteID)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if v.ForceHTTPS && site.SSLStatus != "active" {
|
||||
return errors.New("请先安装有效 SSL 证书")
|
||||
}
|
||||
plan, _, e := s.store.PlanAndUsage(ctx, p.TenantID)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
manager, ok := s.isolation.(isolation.SiteOperations)
|
||||
if !ok {
|
||||
return errors.New("节点暂不支持网站设置")
|
||||
}
|
||||
old, e := s.store.WebsiteSettings(ctx, siteID)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
spec := isolation.WebsiteSpec{Project: isolation.ProjectSpec{TenantID: p.TenantID, HostName: p.HostName, RunPath: site.RunPath, StorageBytes: plan.StorageBytes, ProcessLimit: uint32(site.ProcessLimit)}, SiteName: lifecycleSiteName(p, site), Domain: site.Domain, Runtime: site.Runtime, Settings: v}
|
||||
if e = manager.ConfigureWebsite(ctx, spec); e != nil {
|
||||
return e
|
||||
}
|
||||
if e = s.store.SaveWebsiteSettings(ctx, siteID, v); e != nil {
|
||||
spec.Settings = old
|
||||
_ = manager.ConfigureWebsite(context.WithoutCancel(ctx), spec)
|
||||
}
|
||||
return e
|
||||
}
|
||||
func (s *Projects) SiteLog(ctx context.Context, user store.User, projectID, siteID uint64, kind, search string, lines int) (isolation.SiteLog, error) {
|
||||
p, e := s.authorizedProject(ctx, user, projectID)
|
||||
if e != nil {
|
||||
return isolation.SiteLog{}, e
|
||||
}
|
||||
site, e := s.store.Site(ctx, p.TenantID, p.ID, siteID)
|
||||
if e != nil {
|
||||
return isolation.SiteLog{}, e
|
||||
}
|
||||
plan, _, e := s.store.PlanAndUsage(ctx, p.TenantID)
|
||||
if e != nil {
|
||||
return isolation.SiteLog{}, e
|
||||
}
|
||||
manager, ok := s.isolation.(isolation.SiteOperations)
|
||||
if !ok {
|
||||
return isolation.SiteLog{}, errors.New("节点暂不支持日志查看")
|
||||
}
|
||||
return manager.ReadSiteLog(ctx, isolation.SiteLogSpec{Project: isolation.ProjectSpec{TenantID: p.TenantID, HostName: p.HostName, RunPath: site.RunPath, StorageBytes: plan.StorageBytes, ProcessLimit: uint32(site.ProcessLimit)}, SiteName: lifecycleSiteName(p, site), Domain: site.Domain, Kind: kind, Search: search, Lines: lines})
|
||||
}
|
||||
Reference in new issue
Block a user