@@ -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+
3438export 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