推进活动系统最小成品闭环与游客体验
This commit is contained in:
@@ -78,6 +78,38 @@ func (p *OSSUtilPublisher) UploadJSON(ctx context.Context, publicURL string, pay
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *OSSUtilPublisher) UploadFile(ctx context.Context, publicURL string, localPath string) error {
|
||||
if !p.Enabled() {
|
||||
return fmt.Errorf("asset publisher is not configured")
|
||||
}
|
||||
if strings.TrimSpace(localPath) == "" {
|
||||
return fmt.Errorf("local path is required")
|
||||
}
|
||||
|
||||
objectKey, err := p.objectKeyFromPublicURL(publicURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(p.ossutilPath); err != nil {
|
||||
return fmt.Errorf("ossutil not found: %w", err)
|
||||
}
|
||||
if _, err := os.Stat(p.configFile); err != nil {
|
||||
return fmt.Errorf("ossutil config not found: %w", err)
|
||||
}
|
||||
if _, err := os.Stat(localPath); err != nil {
|
||||
return fmt.Errorf("upload file not found: %w", err)
|
||||
}
|
||||
|
||||
target := p.bucketRoot + "/" + objectKey
|
||||
cmd := exec.CommandContext(ctx, p.ossutilPath, "cp", "-f", localPath, target, "--config-file", p.configFile)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("upload object %s failed: %w: %s", objectKey, err, strings.TrimSpace(string(output)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *OSSUtilPublisher) objectKeyFromPublicURL(publicURL string) (string, error) {
|
||||
publicURL = strings.TrimSpace(publicURL)
|
||||
if publicURL == "" {
|
||||
|
||||
Reference in New Issue
Block a user