Skip to content

Commit

Permalink
fix: add subscription support to ingestor
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Nov 16, 2024
1 parent 681ace1 commit 2967361
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/ingestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const NETWORK_METADATA = {
}
};

function shouldPinIpfs(type: string, message: any) {
return !(type === 'subscription' && message.type === 'email' && message.value !== '');
}

export default async function ingestor(req) {
if (flaggedIps.includes(sha256(getIp(req)))) {
return Promise.reject('unauthorized');
Expand Down Expand Up @@ -92,7 +96,7 @@ export default async function ingestor(req) {
}

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

try {
Expand Down Expand Up @@ -216,6 +220,18 @@ export default async function ingestor(req) {
type = 'vote';
}

if (type === 'subscription' || type === 'delete-subscription') {
if (message.type === 'email' && message.value === '') {
type = 'update-subscription';
}

payload = {
type: message.type,
value: message.value,
metadata: message.metadata
};
}

let legacyBody: any = {
address: message.from,
msg: JSON.stringify({
Expand Down Expand Up @@ -255,7 +271,7 @@ export default async function ingestor(req) {
...restBody
};
[pinned, receipt] = await Promise.all([
pin(ipfsBody, process.env.PINEAPPLE_URL),
shouldPinIpfs(type, message) ? pin(ipfsBody, process.env.PINEAPPLE_URL) : { cid: '' },
issueReceipt(formattedSignature)
]);
} catch (e) {
Expand Down

0 comments on commit 2967361

Please sign in to comment.