+11
-11
internal/media/downloader.go
+11
-11
internal/media/downloader.go
···
24
24
}
25
25
26
26
func (d *Downloader) DownloadBlob(ctx context.Context, did string, cid string) (string, error) {
27
-
// Construct blob URL
28
27
// https://bsky.social/xrpc/com.atproto.sync.getBlob?did=did:plc:xxx&cid=bafyxxx
29
28
url := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", d.PDSHost, did, cid)
30
29
···
32
31
return "", err
33
32
}
34
33
35
-
ext := ".bin" // Default, should ideally check MIME
36
-
fileName := cid + ext
37
-
filePath := filepath.Join(d.ImagesDir, fileName)
38
-
39
-
// Check if already exists
40
-
if _, err := os.Stat(filePath); err == nil {
41
-
return filepath.Join(d.ImagePathPrefix, fileName), nil
34
+
// Check if file already exists (try common extensions)
35
+
for _, ext := range []string{".jpg", ".png", ".webp", ".gif", ".bin"} {
36
+
fileName := cid + ext
37
+
filePath := filepath.Join(d.ImagesDir, fileName)
38
+
if _, err := os.Stat(filePath); err == nil {
39
+
return filepath.Join(d.ImagePathPrefix, fileName), nil
40
+
}
42
41
}
43
42
44
43
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
···
56
55
return "", fmt.Errorf("failed to download blob: %s", resp.Status)
57
56
}
58
57
59
-
// Try to guess extension from Content-Type
58
+
// Determine extension from Content-Type header
59
+
ext := ".bin"
60
60
contentType := resp.Header.Get("Content-Type")
61
61
switch contentType {
62
62
case "image/jpeg":
···
68
68
case "image/gif":
69
69
ext = ".gif"
70
70
}
71
-
fileName = cid + ext
72
-
filePath = filepath.Join(d.ImagesDir, fileName)
71
+
fileName := cid + ext
72
+
filePath := filepath.Join(d.ImagesDir, fileName)
73
73
74
74
out, err := os.Create(filePath)
75
75
if err != nil {