@@ -31,6 +31,10 @@ const NETWORK_METADATA = {
31
31
}
32
32
} ;
33
33
34
+ function shouldPinIpfs ( type : string , message : any ) {
35
+ return ! ( type === 'subscription' && message . type === 'email' && message . value !== '' ) ;
36
+ }
37
+
34
38
export default async function ingestor ( req ) {
35
39
if ( flaggedIps . includes ( sha256 ( getIp ( req ) ) ) ) {
36
40
return Promise . reject ( 'unauthorized' ) ;
@@ -92,7 +96,7 @@ export default async function ingestor(req) {
92
96
}
93
97
94
98
let aliased = false ;
95
- if ( ! [ 'settings' , 'alias' , 'profile' ] . includes ( type ) ) {
99
+ if ( ! [ 'settings' , 'alias' , 'profile' , 'subscription' , 'delete-subscription' ] . includes ( type ) ) {
96
100
if ( ! message . space ) return Promise . reject ( 'unknown space' ) ;
97
101
98
102
try {
@@ -216,6 +220,18 @@ export default async function ingestor(req) {
216
220
type = 'vote' ;
217
221
}
218
222
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
+
219
235
let legacyBody : any = {
220
236
address : message . from ,
221
237
msg : JSON . stringify ( {
@@ -255,7 +271,7 @@ export default async function ingestor(req) {
255
271
...restBody
256
272
} ;
257
273
[ pinned , receipt ] = await Promise . all ( [
258
- pin ( ipfsBody , process . env . PINEAPPLE_URL ) ,
274
+ shouldPinIpfs ( type , message ) ? pin ( ipfsBody , process . env . PINEAPPLE_URL ) : { cid : '' } ,
259
275
issueReceipt ( formattedSignature )
260
276
] ) ;
261
277
} catch ( e ) {
0 commit comments