+11
-52
src/blobs/processor.ts
+11
-52
src/blobs/processor.ts
···
112
112
return { did, type: 'post' };
113
113
}
114
114
115
-
private getBlobUrls(did: string, cid: string, type: 'post' | 'avatar' | 'banner'): { thumbnail: string; fullsize: string } {
116
-
if (type === 'avatar') {
117
-
return {
118
-
thumbnail: `https://cdn.bsky.app/img/avatar/plain/${did}/${cid}@jpeg`,
119
-
fullsize: `https://cdn.bsky.app/img/avatar/plain/${did}/${cid}@jpeg`,
120
-
};
121
-
} else if (type === 'banner') {
122
-
return {
123
-
thumbnail: `https://cdn.bsky.app/img/banner/plain/${did}/${cid}@jpeg`,
124
-
fullsize: `https://cdn.bsky.app/img/banner/plain/${did}/${cid}@jpeg`,
125
-
};
126
-
} else {
127
-
return {
128
-
thumbnail: `https://cdn.bsky.app/img/feed_thumbnail/plain/${did}/${cid}@jpeg`,
129
-
fullsize: `https://cdn.bsky.app/img/feed_fullsize/plain/${did}/${cid}@jpeg`,
130
-
};
131
-
}
132
-
}
133
-
134
115
private async processBlob(
135
116
postUri: string,
136
117
ref: BlobReference
···
145
126
}
146
127
147
128
const { did, type } = this.parseBlobUri(postUri);
148
-
const urls = this.getBlobUrls(did, ref.cid, type);
129
+
const pds = `https://${config.bsky.pds}`;
130
+
const blobUrl = `${pds}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${ref.cid}`;
149
131
150
132
try {
151
-
const response = await fetch(urls.thumbnail, { method: "HEAD" });
133
+
const response = await fetch(blobUrl);
152
134
153
135
if (!response.ok) {
154
136
logger.warn(
155
-
{ postUri, cid: ref.cid, status: response.status },
156
-
"Failed to fetch blob metadata"
137
+
{ postUri, cid: ref.cid, status: response.status, did },
138
+
"Failed to fetch blob"
157
139
);
158
140
return;
159
141
}
160
142
161
-
let blobData: Buffer | null = null;
162
-
let storagePath: string | undefined;
143
+
const blobData = Buffer.from(await response.arrayBuffer());
163
144
145
+
let storagePath: string | undefined;
164
146
if (this.storage && config.blobs.hydrateBlobs) {
165
-
const fullResponse = await fetch(urls.fullsize);
166
-
167
-
if (fullResponse.ok) {
168
-
blobData = Buffer.from(
169
-
await fullResponse.arrayBuffer()
170
-
);
171
-
storagePath = await this.storage.store(
172
-
ref.cid,
173
-
blobData,
174
-
ref.mimeType
175
-
);
176
-
}
177
-
} else {
178
-
const thumbResponse = await fetch(urls.thumbnail);
179
-
180
-
if (thumbResponse.ok) {
181
-
blobData = Buffer.from(
182
-
await thumbResponse.arrayBuffer()
183
-
);
184
-
}
185
-
}
186
-
187
-
if (!blobData) {
188
-
logger.warn(
189
-
{ postUri, cid: ref.cid },
190
-
"Could not fetch blob data"
147
+
storagePath = await this.storage.store(
148
+
ref.cid,
149
+
blobData,
150
+
ref.mimeType
191
151
);
192
-
return;
193
152
}
194
153
195
154
const hashes = await computeBlobHashes(