GetPublicURL generates public URL for S3 object
(userID, key string)
| 298 | |
| 299 | // GetPublicURL generates public URL for S3 object |
| 300 | func (m *S3Manager) GetPublicURL(userID, key string) string { |
| 301 | _, config, ok := m.GetClient(userID) |
| 302 | if !ok { |
| 303 | return "" |
| 304 | } |
| 305 | |
| 306 | // Use custom public URL if configured |
| 307 | if config.PublicURL != "" { |
| 308 | return fmt.Sprintf("%s/%s/%s", strings.TrimRight(config.PublicURL, "/"), config.Bucket, key) |
| 309 | } |
| 310 | |
| 311 | // Generate standard S3 URL |
| 312 | if config.PathStyle { |
| 313 | return fmt.Sprintf("%s/%s/%s", |
| 314 | strings.TrimRight(config.Endpoint, "/"), |
| 315 | config.Bucket, |
| 316 | key) |
| 317 | } |
| 318 | |
| 319 | // Virtual hosted-style URL |
| 320 | if strings.Contains(config.Endpoint, "amazonaws.com") { |
| 321 | return fmt.Sprintf("https://%s.s3.%s.amazonaws.com/%s", |
| 322 | config.Bucket, |
| 323 | config.Region, |
| 324 | key) |
| 325 | } |
| 326 | |
| 327 | // For other S3-compatible services |
| 328 | endpoint := strings.TrimPrefix(config.Endpoint, "https://") |
| 329 | endpoint = strings.TrimPrefix(endpoint, "http://") |
| 330 | return fmt.Sprintf("https://%s.%s/%s", config.Bucket, endpoint, key) |
| 331 | } |
| 332 | |
| 333 | // TestConnection tests S3 connection |
| 334 | func (m *S3Manager) TestConnection(ctx context.Context, userID string) error { |
no test coverage detected