@ -38,7 +38,7 @@ import { useDropzone } from "react-dropzone";
import AddIcon from "@mui/icons-material/Add" ;
import { setNotification } from "../../../state/features/notificationsSlice.ts" ;
import { objectToBase64 , uint8ArrayToBase64 } from "../../../utils/toBase64.ts" ;
import { objectToBase64 , objectToFile , uint8ArrayToBase64 } from "../../../utils/toBase64.ts" ;
import { RootState } from "../../../state/store.ts" ;
import {
upsertVideosBeginning ,
@ -65,7 +65,7 @@ import {
QTUBE_PLAYLIST_BASE ,
QTUBE_VIDEO_BASE ,
} from "../../../constants/Identifiers.ts" ;
import { titleFormatter } from "../../../constants/Misc.ts" ;
import { maxSize , titleFormatter , videoMaxSize } from "../../../constants/Misc.ts" ;
import { getFileName } from "../../../utils/stringFunctions.ts" ;
export const toBase64 = ( file : File ) : Promise < string | ArrayBuffer | null > = >
@ -137,13 +137,16 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
const [ isCheckDescriptionIsTitle , setIsCheckDescriptionIsTitle ] =
useState ( false ) ;
const [ imageExtracts , setImageExtracts ] = useState < any > ( { } ) ;
const { getRootProps , getInputProps } = useDropzone ( {
accept : {
"video/*" : [ ] ,
} ,
maxSize : 419430400 , // 400 MB in bytes
maxSize ,
onDrop : ( acceptedFiles , rejectedFiles ) = > {
const formatArray = acceptedFiles . map ( item = > {
console . log ( 'file: ' , item )
let filteredTitle = "" ;
if ( isCheckTitleByFile ) {
@ -164,7 +167,7 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
rejectedFiles . forEach ( ( { file , errors } ) = > {
errors . forEach ( error = > {
if ( error . code === "file-too-large" ) {
errorString = "File must be under 400mb" ;
errorString = ` File must be under ${ videoMaxSize } MB ` ;
}
console . log ( ` Error with file ${ file . name } : ${ error . message } ` ) ;
} ) ;
@ -180,10 +183,10 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
} ,
} ) ;
useEffect ( ( ) = > {
if ( editContent ) {
}
} , [ editContent ] ) ;
// useEffect(() => {
// if (editContent) {
// }
// }, [editContent]);
const onClose = ( ) = > {
setIsOpen ( false ) ;
@ -238,7 +241,7 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
return ;
}
le t listOfPublishes = [ ] ;
cons t listOfPublishes = [ ] ;
for ( let i = 0 ; i < files . length ; i ++ ) {
const publish = files [ i ] ;
@ -274,18 +277,18 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
fileExtension = fileExtensionSplit ? . pop ( ) || "mp4" ;
}
le t filename = title . slice ( 0 , 15 ) ;
cons t filename = title . slice ( 0 , 15 ) ;
// Step 1: Replace all white spaces with underscores
// Replace all forms of whitespace (including non-standard ones) with underscores
le t stringWithUnderscores = filename . replace ( /[\s\uFEFF\xA0]+/g , "_" ) ;
cons t stringWithUnderscores = filename . replace ( /[\s\uFEFF\xA0]+/g , "_" ) ;
// Remove all non-alphanumeric characters (except underscores)
le t alphanumericString = stringWithUnderscores . replace (
cons t alphanumericString = stringWithUnderscores . replace (
/[^a-zA-Z0-9_]/g ,
""
) ;
console . log ( 'file size: ' , file . size )
const videoObject : any = {
title ,
version : 1 ,
@ -306,17 +309,16 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
filename : ` ${ alphanumericString . trim ( ) } . ${ fileExtension } ` ,
} ;
le t metadescription =
cons t metadescription =
` **category: ${ category } ;subcategory: ${ subcategory } ;code: ${ code } ** ` +
fullDescription . slice ( 0 , 150 ) ;
const crowdfundObjectToBase64 = await objectToBase64 ( videoObject ) ;
// Description is obtained from raw data
const requestBodyJson : any = {
action : "PUBLISH_QDN_RESOURCE" ,
name : name ,
service : "DOCUMENT" ,
data64 : crowdfundObjectToBase64 ,
file : objectToFile ( videoObject ) ,
title : title.slice ( 0 , 50 ) ,
description : metadescription ,
identifier : identifier + "_metadata" ,
@ -392,17 +394,17 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
. slice ( 0 , 10 )
. join ( "" ) ;
le t metadescription =
cons t metadescription =
` **category: ${ category } ;subcategory: ${ subcategory } ; ${ codes } ** ` +
stringDescription . slice ( 0 , 120 ) ;
const crowdfundObjectToBase64 = await objectToBase64 ( playlistObject ) ;
// Description is obtained from raw data
const requestBodyJson : any = {
action : "PUBLISH_QDN_RESOURCE" ,
name : name ,
service : "PLAYLIST" ,
data64 : crowdfundObjectToBase64 ,
file : objectToFile ( playlistObject ) ,
title : title.slice ( 0 , 50 ) ,
description : metadescription ,
identifier : identifier + "_metadata" ,
@ -447,17 +449,17 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
. slice ( 0 , 10 )
. join ( "" ) ;
le t metadescription =
cons t metadescription =
` **category: ${ playlistObject . category } ;subcategory: ${ playlistObject . subcategory } ; ${ codes } ** ` +
playlistObject . description . slice ( 0 , 120 ) ;
const crowdfundObjectToBase64 = await objectToBase64 ( playlistObject ) ;
// Description is obtained from raw data
const requestBodyJson : any = {
action : "PUBLISH_QDN_RESOURCE" ,
name : name ,
service : "PLAYLIST" ,
data64 : crowdfundObjectToBase64 ,
file : objectToFile ( playlistObject ) ,
title : playlistObject.title.slice ( 0 , 50 ) ,
description : metadescription ,
identifier : selectExistingPlaylist.identifier ,
@ -480,24 +482,24 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
let notificationObj : any = null ;
if ( typeof error === "string" ) {
notificationObj = {
msg : error || "Failed to publish crowdfund " ,
msg : error || "Failed to publish video " ,
alertType : "error" ,
} ;
} else if ( typeof error ? . error === "string" ) {
notificationObj = {
msg : error?.error || "Failed to publish crowdfund " ,
msg : error?.error || "Failed to publish video " ,
alertType : "error" ,
} ;
} else {
notificationObj = {
msg : error?.message || "Failed to publish crowdfund " ,
msg : error?.message || "Failed to publish video " ,
alertType : "error" ,
} ;
}
if ( ! notificationObj ) return ;
dispatch ( setNotification ( notificationObj ) ) ;
throw new Error ( "Failed to publish crowdfund " ) ;
throw new Error ( "Failed to publish video " ) ;
}
}
@ -578,7 +580,7 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
const onFramesExtracted = async ( imgs , index ) = > {
try {
le t imagesExtracts = [ ] ;
cons t imagesExtracts = [ ] ;
for ( const img of imgs ) {
try {
@ -596,7 +598,7 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
compressedFile = file ;
resolve ( ) ;
} ,
error ( err ) { } ,
error ( error ) { console . log ( error ) } ,
} ) ;
} ) ;
if ( ! compressedFile ) continue ;
@ -613,7 +615,7 @@ export const PublishVideo = ({ editId, editContent }: NewCrowdfundProps) => {
[ index ] : imagesExtracts ,
} ;
} ) ;
} catch ( error ) { }
} catch ( error ) { console . log ( error ) }
} ;
return (