// @flow import * as ICONS from 'constants/icons'; import React, { useState, useEffect } from 'react'; import { regexInvalidURI } from 'lbry-redux'; import FileSelector from 'component/common/file-selector'; import Button from 'component/button'; import Card from 'component/common/card'; import { FormField } from 'component/common/form'; import Spinner from 'component/spinner'; import I18nMessage from '../i18nMessage'; type Props = { name: ?string, filePath: string | WebFile, isStillEditing: boolean, balance: number, updatePublishForm: ({}) => void, disabled: boolean, publishing: boolean, showToast: string => void, inProgress: boolean, clearPublish: () => void, ffmpegStatus: any, optimize: boolean, size: number, duration: number, isVid: boolean, }; function PublishFile(props: Props) { const { name, balance, filePath, isStillEditing, updatePublishForm, disabled, publishing, inProgress, clearPublish, optimize, ffmpegStatus = {}, size, duration, isVid, } = props; const { available } = ffmpegStatus; const [oversized, setOversized] = useState(false); const [currentFile, setCurrentFile] = useState(null); const RECOMMENDED_BITRATE = 6000000; const TV_PUBLISH_SIZE_LIMIT: number = 1073741824; const UPLOAD_SIZE_MESSAGE = 'Lbry.tv uploads are limited to 1 GB. Download the app for unrestricted publishing.'; const PROCESSING_MB_PER_SECOND = 0.5; const MINUTES_THRESHOLD = 30; const HOURS_THRESHOLD = MINUTES_THRESHOLD * 60; const sizeInMB = Number(size) / 1000000; const secondsToProcess = sizeInMB / PROCESSING_MB_PER_SECOND; // clear warnings useEffect(() => { if (!filePath || filePath === '') { setCurrentFile(''); setOversized(false); updateOptimizeState(0, 0, false); } else if (typeof filePath !== 'string') { // Update currentFile file if (filePath.name !== currentFile && filePath.path !== currentFile) { handleFileChange(filePath); } } }, [filePath, currentFile, handleFileChange, updateOptimizeState]); function updateOptimizeState(duration, size, isvid) { updatePublishForm({ fileDur: duration, fileSize: size, fileVid: isvid }); } function getBitrate(size, duration) { const s = Number(size); const d = Number(duration); if (s && d) { return (s * 8) / d; } else { return 0; } } function getTimeForMB(s) { if (s < MINUTES_THRESHOLD) { return Math.floor(secondsToProcess); } else if (s >= MINUTES_THRESHOLD && s < HOURS_THRESHOLD) { return Math.floor(secondsToProcess / 60); } else { return Math.floor(secondsToProcess / 60 / 60); } } function getUnitsForMB(s) { if (s < MINUTES_THRESHOLD) { if (secondsToProcess > 1) return 'seconds'; return 'second'; } else if (s >= MINUTES_THRESHOLD && s < HOURS_THRESHOLD) { if (Math.floor(secondsToProcess / 60) > 1) return 'minutes'; return 'minute'; } else { if (Math.floor(secondsToProcess / 3600) > 1) return 'hours'; return 'hour'; } } function getMessage() { // @if TARGET='web' if (oversized) { return (

{__(UPLOAD_SIZE_MESSAGE)}{' '}