@@ -15,7 +15,9 @@ const fs = require('fs');
1515const { URLSearchParams, URL } = require ( 'url' ) ;
1616const multer = require ( 'multer' ) ;
1717const { DateTime } = require ( 'luxon' ) ;
18+ const textParser = require ( '../public/scripts/text-parser.js' ) ;
1819
20+ const spoilerMarker = "**spoiler**" ; ;
1921const app = express ( ) ;
2022const upload = multer ( ) ;
2123
@@ -58,6 +60,8 @@ const FIELD__THREADS_BIOGRAPHY = 'threads_biography';
5860const FIELD__THREADS_PROFILE_PICTURE_URL = 'threads_profile_picture_url' ;
5961const FIELD__USERNAME = 'username' ;
6062const FIELD__VIEWS = 'views' ;
63+ const FIELD_IS_SPOILER_MEDIA = 'is_spoiler_media' ;
64+ const FIELD_TEXT_ENTITES = 'text_entities' ;
6165
6266const MEDIA_TYPE__CAROUSEL = 'CAROUSEL' ;
6367const MEDIA_TYPE__IMAGE = 'IMAGE' ;
@@ -94,6 +98,8 @@ const PARAMS__SEARCH_TYPE = 'search_type';
9498const PARAMS__TEXT = 'text' ;
9599const PARAMS__TOPIC_TAG = 'topic_tag' ;
96100const PARAMS__USERNAME = 'username' ;
101+ const PARAMS_IS_SPOILER_MEDIA = 'is_spoiler_media' ;
102+ const PARAMS_TEXT_ENTITES = 'text_entities' ;
97103
98104// Read variables from environment
99105require ( 'dotenv' ) . config ( ) ;
@@ -442,15 +448,24 @@ app.post('/upload', upload.array(), async (req, res) => {
442448 pollOptionC,
443449 pollOptionD,
444450 quotePostId,
451+ spoilerMedia,
445452 } = req . body ;
446453
447454 const params = {
448- [ PARAMS__TEXT ] : text ,
449455 [ PARAMS__REPLY_CONTROL ] : replyControl ,
450456 [ PARAMS__REPLY_TO_ID ] : replyToId ,
451457 [ PARAMS__LINK_ATTACHMENT ] : linkAttachment ,
452458 } ;
453459
460+ if ( text . includes ( spoilerMarker ) ) {
461+ parsedInput = textParser . extractSpoilerInfo ( text ) ;
462+ processedText = parsedInput . text ;
463+ textEntites = parsedInput . textEntities ;
464+ params [ PARAMS__TEXT ] = processedText ;
465+ params [ PARAMS_TEXT_ENTITES ] = JSON . stringify ( textEntites ) ;
466+ } else {
467+ params [ PARAMS__TEXT ] = text ;
468+ }
454469 if (
455470 topicTag . length >= 1 &&
456471 topicTag . length <= 50 &&
@@ -460,6 +475,10 @@ app.post('/upload', upload.array(), async (req, res) => {
460475 params [ PARAMS__TOPIC_TAG ] = topicTag ;
461476 }
462477
478+ if ( spoilerMedia ) {
479+ params [ PARAMS_IS_SPOILER_MEDIA ] = true ;
480+ }
481+
463482 if ( pollOptionA && pollOptionB ) {
464483 const pollAttachment = JSON . stringify ( {
465484 option_a : pollOptionA ,
@@ -658,6 +677,8 @@ app.get('/threads/:threadId', loggedInUserChecker, async (req, res) => {
658677 FIELD__IS_QUOTE_POST ,
659678 FIELD__QUOTED_POST ,
660679 FIELD__REPOSTED_POST ,
680+ FIELD_IS_SPOILER_MEDIA ,
681+ FIELD_TEXT_ENTITES ,
661682 ] . join ( ',' ) ,
662683 } ,
663684 req . session . access_token
0 commit comments