Minor renaming for clarity. No functional change.

updateOptimizeState --> updateFileInfo
available --> ffmpegAvail
This commit is contained in:
infiinte-persistence 2020-07-01 22:17:07 +08:00 committed by Sean Yesmunt
parent 406ca3b998
commit 0fcf78a700

View file

@ -45,7 +45,7 @@ function PublishFile(props: Props) {
isVid, isVid,
} = props; } = props;
const { available } = ffmpegStatus; const ffmpegAvail = ffmpegStatus.available;
const [oversized, setOversized] = useState(false); const [oversized, setOversized] = useState(false);
const [currentFile, setCurrentFile] = useState(null); const [currentFile, setCurrentFile] = useState(null);
@ -64,16 +64,16 @@ function PublishFile(props: Props) {
if (!filePath || filePath === '') { if (!filePath || filePath === '') {
setCurrentFile(''); setCurrentFile('');
setOversized(false); setOversized(false);
updateOptimizeState(0, 0, false); updateFileInfo(0, 0, false);
} else if (typeof filePath !== 'string') { } else if (typeof filePath !== 'string') {
// Update currentFile file // Update currentFile file
if (filePath.name !== currentFile && filePath.path !== currentFile) { if (filePath.name !== currentFile && filePath.path !== currentFile) {
handleFileChange(filePath); handleFileChange(filePath);
} }
} }
}, [filePath, currentFile, handleFileChange, updateOptimizeState]); }, [filePath, currentFile, handleFileChange, updateFileInfo]);
function updateOptimizeState(duration, size, isvid) { function updateFileInfo(duration, size, isvid) {
updatePublishForm({ fileDur: duration, fileSize: size, fileVid: isvid }); updatePublishForm({ fileDur: duration, fileSize: size, fileVid: isvid });
} }
@ -195,15 +195,15 @@ function PublishFile(props: Props) {
const video = document.createElement('video'); const video = document.createElement('video');
video.preload = 'metadata'; video.preload = 'metadata';
video.onloadedmetadata = function() { video.onloadedmetadata = function() {
updateOptimizeState(video.duration, file.size, isVideo); updateFileInfo(video.duration, file.size, isVideo);
window.URL.revokeObjectURL(video.src); window.URL.revokeObjectURL(video.src);
}; };
video.onerror = function() { video.onerror = function() {
updateOptimizeState(0, file.size, isVideo); updateFileInfo(0, file.size, isVideo);
}; };
video.src = window.URL.createObjectURL(file); video.src = window.URL.createObjectURL(file);
} else { } else {
updateOptimizeState(0, file.size, isVideo); updateFileInfo(0, file.size, isVideo);
} }
} }
@ -266,13 +266,13 @@ function PublishFile(props: Props) {
{/* @if TARGET='app' */} {/* @if TARGET='app' */}
<FormField <FormField
type="checkbox" type="checkbox"
checked={isVid && available && optimize} checked={isVid && ffmpegAvail && optimize}
disabled={!isVid || !available} disabled={!isVid || !ffmpegAvail}
onChange={e => updatePublishForm({ optimize: e.target.checked })} onChange={e => updatePublishForm({ optimize: e.target.checked })}
label={__('Optimize and transcode video')} label={__('Optimize and transcode video')}
name="optimize" name="optimize"
/> />
{!available && ( {!ffmpegAvail && (
<p className="help"> <p className="help">
<I18nMessage <I18nMessage
tokens={{ tokens={{
@ -283,7 +283,7 @@ function PublishFile(props: Props) {
</I18nMessage> </I18nMessage>
</p> </p>
)} )}
{Boolean(size) && available && optimize && isVid && ( {Boolean(size) && ffmpegAvail && optimize && isVid && (
<p className="help"> <p className="help">
<I18nMessage <I18nMessage
tokens={{ tokens={{