Skip to content

Commit 6993a1a

Browse files
committed
fix: add subscription support to ingestor
1 parent 48c73f0 commit 6993a1a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/ingestor.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const NETWORK_METADATA = {
3131
}
3232
};
3333

34+
function shouldPinIpfs(type: string, message: any) {
35+
return !(type === 'subscription' && message.type === 'email' && message.value !== '');
36+
}
37+
3438
export default async function ingestor(req) {
3539
if (flaggedIps.includes(sha256(getIp(req)))) {
3640
return Promise.reject('unauthorized');
@@ -92,7 +96,7 @@ export default async function ingestor(req) {
9296
}
9397

9498
let aliased = false;
95-
if (!['settings', 'alias', 'profile'].includes(type)) {
99+
if (!['settings', 'alias', 'profile', 'subscription', 'delete-subscription'].includes(type)) {
96100
if (!message.space) return Promise.reject('unknown space');
97101

98102
try {
@@ -216,6 +220,18 @@ export default async function ingestor(req) {
216220
type = 'vote';
217221
}
218222

223+
if (type === 'subscription' || type === 'delete-subscription') {
224+
if (message.type === 'email' && message.value === '') {
225+
type = 'update-subscription';
226+
}
227+
228+
payload = {
229+
type: message.type,
230+
value: message.value,
231+
metadata: message.metadata
232+
};
233+
}
234+
219235
let legacyBody: any = {
220236
address: message.from,
221237
msg: JSON.stringify({
@@ -255,7 +271,7 @@ export default async function ingestor(req) {
255271
...restBody
256272
};
257273
[pinned, receipt] = await Promise.all([
258-
pin(ipfsBody, process.env.PINEAPPLE_URL),
274+
shouldPinIpfs(type, message) ? pin(ipfsBody, process.env.PINEAPPLE_URL) : { cid: '' },
259275
issueReceipt(formattedSignature)
260276
]);
261277
} catch (e) {

0 commit comments

Comments
 (0)