@@ -22,14 +22,12 @@ async function writeTaskOutput(path, message) {
2222async function processProtectedData ( {
2323 index,
2424 IEXEC_IN ,
25- IEXEC_OUT ,
2625 appDeveloperSecret,
2726 requesterSecret,
2827} ) {
2928 const datasetFilename =
3029 index > 0 ? process . env [ `IEXEC_DATASET_${ index } _FILENAME` ] : null ;
3130
32- // Parse the protected data
3331 let protectedData ;
3432 try {
3533 const deserializerConfig = datasetFilename
@@ -44,10 +42,8 @@ async function processProtectedData({
4442 throw Error ( `Failed to parse ProtectedData ${ index } : ${ e . message } ` ) ;
4543 }
4644
47- // Validate the protected data
4845 validateProtectedData ( protectedData ) ;
4946
50- // Download and decrypt content
5147 const encryptedTelegramContent = await downloadEncryptedContent (
5248 requesterSecret . telegramContentMultiAddr
5349 ) ;
@@ -57,22 +53,13 @@ async function processProtectedData({
5753 requesterSecret . telegramContentEncryptionKey
5854 ) ;
5955
60- // Send telegram message
6156 const response = await sendTelegram ( {
6257 chatId : protectedData . chatId ,
6358 message : telegramContent ,
6459 botToken : appDeveloperSecret . TELEGRAM_BOT_TOKEN ,
6560 senderName : requesterSecret . senderName ,
6661 } ) ;
6762
68- // Write individual result file only for single processing
69- if ( index === 0 ) {
70- await writeTaskOutput (
71- `${ IEXEC_OUT } /result.txt` ,
72- JSON . stringify ( response , null , 2 )
73- ) ;
74- }
75-
7663 return { index, response } ;
7764}
7865
@@ -85,10 +72,8 @@ async function start() {
8572 IEXEC_BULK_SLICE_SIZE ,
8673 } = process . env ;
8774
88- // Check worker env
8975 const workerEnv = validateWorkerEnv ( { IEXEC_OUT } ) ;
9076
91- // Parse the app developer secret environment variable
9277 let appDeveloperSecret ;
9378 try {
9479 appDeveloperSecret = JSON . parse ( IEXEC_APP_DEVELOPER_SECRET ) ;
@@ -97,7 +82,6 @@ async function start() {
9782 }
9883 appDeveloperSecret = validateAppSecret ( appDeveloperSecret ) ;
9984
100- // Parse the requester secret environment variable
10185 let requesterSecret ;
10286 try {
10387 requesterSecret = IEXEC_REQUESTER_SECRET_1
@@ -111,14 +95,13 @@ async function start() {
11195 const bulkSize = parseInt ( IEXEC_BULK_SLICE_SIZE , 10 ) || 0 ;
11296 const results = [ ] ;
11397
98+ // Process multiple protected data
11499 if ( bulkSize > 0 ) {
115- // Process multiple protected data
116100 const promises = [ ] ;
117101 for ( let index = 1 ; index <= bulkSize ; index += 1 ) {
118102 const promise = processProtectedData ( {
119103 index,
120104 IEXEC_IN ,
121- IEXEC_OUT : workerEnv . IEXEC_OUT ,
122105 appDeveloperSecret,
123106 requesterSecret,
124107 } )
@@ -143,23 +126,8 @@ async function start() {
143126
144127 const bulkResults = await Promise . all ( promises ) ;
145128 results . push ( ...bulkResults ) ;
146- } else {
147- // Process single protected data
148- const result = await processProtectedData ( {
149- index : 0 ,
150- IEXEC_IN ,
151- IEXEC_OUT : workerEnv . IEXEC_OUT ,
152- appDeveloperSecret,
153- requesterSecret,
154- } ) ;
155-
156- results . push ( result ) ;
157- }
158-
159- // Generate computed.json - same format for both single and bulk
160129
161- // Create result.txt for bulk processing (similar to single processing)
162- if ( bulkSize > 0 ) {
130+ // Write result.txt for bulk processing
163131 const successCount = results . filter (
164132 ( r ) => r . response . status === 200
165133 ) . length ;
@@ -184,8 +152,24 @@ async function start() {
184152 `${ workerEnv . IEXEC_OUT } /result.txt` ,
185153 JSON . stringify ( bulkResult , null , 2 )
186154 ) ;
155+ } else {
156+ // Process single protected data
157+ const result = await processProtectedData ( {
158+ index : 0 ,
159+ IEXEC_IN ,
160+ appDeveloperSecret,
161+ requesterSecret,
162+ } ) ;
163+
164+ results . push ( result ) ;
165+
166+ await writeTaskOutput (
167+ `${ workerEnv . IEXEC_OUT } /result.txt` ,
168+ JSON . stringify ( result . response , null , 2 )
169+ ) ;
187170 }
188171
172+ // Generate computed.json - same format for both single and bulk
189173 await writeTaskOutput (
190174 `${ workerEnv . IEXEC_OUT } /computed.json` ,
191175 JSON . stringify (
0 commit comments