@@ -29,6 +29,7 @@ const sendMessageToDiscord = require('../../lib/moderation/discordWebhooks');
2929const { saveAndServeFilesDirectory } = require ( '../../lib/helpers/settings' ) ;
3030const getMediaType = require ( '../../lib/uploading/media' ) ;
3131const { b2, bucket, hostUrl } = require ( '../../lib/uploading/backblaze' ) ;
32+ const createSpriteImageAndVtt = require ( '../../lib/uploading/createSpriteImages' ) ;
3233
3334const ffmpegHelper = require ( '../../lib/uploading/ffmpeg' ) ;
3435const {
@@ -424,6 +425,7 @@ exports.postFileUpload = async(req, res) => {
424425
425426 let bitrate , codecName , codecProfile ;
426427
428+ // if not an image, requires ffprobe data collection
427429 if ( upload . fileType !== 'image' ) {
428430
429431 // load the ffprobe data in response
@@ -499,12 +501,16 @@ exports.postFileUpload = async(req, res) => {
499501
500502 console . log ( 'done moving file' ) ;
501503
504+
505+ /** BASIC VIDEO PROCESSING COMPLETED, CHECKING IF NEEDS CONVERSION **/
506+
502507 const specificMatches = ( codecName == 'hevc' || codecProfile == 'High 4:4:4 Predictive' ) ;
503508
504509 if ( specificMatches || bitrate > maxBitrate ) {
505510 upload . fileType = 'convert' ;
506511 }
507512
513+ // TODO: a bit ugly, wish we could pull out 'only video' stuff and then do convert in its own conditional
508514 /** TELL THE USER WE ARE CONVERTING / COMPRESSING THEIR VIDEO **/
509515 if ( upload . fileType == 'convert' || bitrate > maxBitrate || upload . fileType == 'video' ) {
510516
@@ -516,6 +522,7 @@ exports.postFileUpload = async(req, res) => {
516522 // set upload progress as 1 so it has something to show on the frontend
517523 redisClient . setAsync ( `${ uniqueTag } uploadProgress` , 'Your upload is beginning processing...' ) ;
518524
525+ // video is marked as processing, end the request and send user to upload page
519526 if ( ! responseSent ) {
520527 responseSent = true ;
521528 aboutToProcess ( res , channelUrl , uniqueTag ) ;
@@ -532,13 +539,14 @@ exports.postFileUpload = async(req, res) => {
532539
533540 // TODO: savePath and fileInDirectory are the same thing, need to clean this code up
534541
542+ // if we need to convert, move it to this 'old' location so we can write to the new location
535543 if ( fileExtension == '.mp4' && bitrate > maxBitrate || specificMatches ) {
536544 await fs . move ( savePath , `${ saveAndServeFilesDirectory } /${ channelUrl } /${ uniqueTag } -old.mp4` ) ;
537545
538546 fileInDirectory = `${ saveAndServeFilesDirectory } /${ channelUrl } /${ uniqueTag } -old.mp4` ;
539547 }
540548
541- // if the file type is convert or it's over max bitrate
549+ // if the file type is convert or it's over max bitrate, convert it with ffmpeg
542550 if ( upload . fileType == 'convert' || ( bitrate > maxBitrate && fileExtension == '.mp4' ) ) {
543551
544552 console . log ( fileInDirectory ) ;
@@ -553,7 +561,8 @@ exports.postFileUpload = async(req, res) => {
553561
554562 uploadLogger . info ( 'Finished converting file' , logObject ) ;
555563
556- // assuming an mp4 is created at this point so we delete the old uncoverted video
564+ // assuming an mp4 is created at this point so we delete the old unconverted video
565+ // note, $fileInDirectory is changed
557566 await fs . remove ( `${ fileInDirectory } ` ) ;
558567
559568 uploadLogger . info ( 'Deleted unconverted file' , logObject ) ;
@@ -625,6 +634,19 @@ exports.postFileUpload = async(req, res) => {
625634 responseSent = true ;
626635 aboutToProcess ( res , channelUrl , uniqueTag ) ;
627636 }
637+
638+ // once everything is done, generate thumbnail previews
639+ if ( upload . fileType === 'video' ) {
640+ // will automatically stick it at /uploads/$channelUrl/$uniqueTag_sprite.png and /$uniqueTag_sprite.vtt
641+ ( async function ( ) {
642+ if ( user . plan === 'plus' ) {
643+ await createSpriteImageAndVtt ( channelUrl , uniqueTag , fileInDirectory )
644+
645+ upload . hasPreviewSpriteThumbnail = true ;
646+ await upload . save ( ) ;
647+ }
648+ } ) ( )
649+ }
628650 } ) ;
629651
630652 // });
0 commit comments