From 8f7afcf1f6baaaeb523c79e3beae44ce72497cd4 Mon Sep 17 00:00:00 2001 From: fatchan Date: Fri, 27 Dec 2019 12:53:26 +0100 Subject: [PATCH] make file duration strings handle over 24h and cleanup some file info addings in makepost --- helpers/files/formatsize.js | 2 +- helpers/timeutils.js | 10 ++++++++++ models/forms/makepost.js | 19 +++++++++---------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/helpers/files/formatsize.js b/helpers/files/formatsize.js index 3fd5c2dd..47d6ed05 100644 --- a/helpers/files/formatsize.js +++ b/helpers/files/formatsize.js @@ -1,6 +1,6 @@ 'use strict'; -const sizes = ['B', 'KB', 'MB'] +const sizes = ['B', 'KB', 'MB', 'GB', 'TB'] , k = 1024; module.exports = (bytes) => { diff --git a/helpers/timeutils.js b/helpers/timeutils.js index a940afc3..9fc45944 100644 --- a/helpers/timeutils.js +++ b/helpers/timeutils.js @@ -72,6 +72,16 @@ module.exports = { g = (Math.round(g*255*0.85).toString(16)).padStart(2, '0'); b = (Math.round(b*255).toString(16)).padStart(2, '0'); return `#${r}${g}${b}`; + }, + + 'durationString': (ms) => { + const durString = new Date(ms).toISOString(); + if (ms < DAY) { + return durString.substr(11,8).replace(/^00:/, ''); + } else { + const hours = Math.floor(ms/HOUR); + return `${hours}:${durString.substring(14,19)}`; + } } }; diff --git a/models/forms/makepost.js b/models/forms/makepost.js index 7d49efeb..f920b398 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -176,7 +176,7 @@ module.exports = async (req, res, next) => { } let imageData; if (type === 'image') { - ///detect images with opacity for PNG thumbnails, settumh thumbextension before increment + ///detect images with opacity for PNG thumbnails, set thumbextension before increment imageData = await imageIdentify(req.files.file[i].tempFilePath, null, true); if (imageData['Channel Statistics'] && imageData['Channel Statistics']['Opacity']) { //does this change depending on GM version or anything? const opacityMaximum = imageData['Channel Statistics']['Opacity']['Maximum']; @@ -191,12 +191,13 @@ module.exports = async (req, res, next) => { //check if already exists const existsFull = await pathExists(`${uploadDirectory}/img/${processedFile.filename}`); + + processedFile.sizeString = formatSize(processedFile.size) switch (type) { case 'image': { const existsThumb = await pathExists(`${uploadDirectory}/img/thumb-${processedFile.hash}${processedFile.thumbextension}`); - processedFile.geometry = imageData.size // object with width and height pixels - processedFile.sizeString = formatSize(processedFile.size) // 123 Ki string - processedFile.geometryString = imageData.Geometry // 123 x 123 string + processedFile.geometry = imageData.size ; + processedFile.geometryString = imageData.Geometry; processedFile.hasThumb = !(fileCheckMimeType(file.mimetype, {image: true}) && processedFile.geometry.height <= thumbSize && processedFile.geometry.width <= thumbSize); @@ -223,10 +224,9 @@ module.exports = async (req, res, next) => { }); } processedFile.duration = videoData.format.duration; - processedFile.durationString = new Date(videoData.format.duration*1000).toISOString().substr(11,8).replace(/^00:/, '');//breaks for over 24h video - processedFile.geometry = {width: videoData.streams[0].coded_width, height: videoData.streams[0].coded_height} // object with width and height pixels - processedFile.sizeString = formatSize(processedFile.size) // 123 Ki string - processedFile.geometryString = `${processedFile.geometry.width}x${processedFile.geometry.height}` // 123 x 123 string + processedFile.durationString = timeUtils.durationString(videoData.format.duration*1000); + processedFile.geometry = {width: videoData.streams[0].coded_width, height: videoData.streams[0].coded_height}; + processedFile.geometryString = `${processedFile.geometry.width}x${processedFile.geometry.height}` processedFile.hasThumb = true; if (!existsFull) { await moveUpload(file, processedFile.filename, 'img'); @@ -239,8 +239,7 @@ module.exports = async (req, res, next) => { case 'audio': { const audioData = await ffprobe(req.files.file[i].tempFilePath, null, true); processedFile.duration = audioData.format.duration; - processedFile.durationString = new Date(audioData.format.duration*1000).toISOString().substr(11,8).replace(/^00:/, '');//breaks for over 24h video - processedFile.sizeString = formatSize(processedFile.size) // 123 Ki string + processedFile.durationString = timeUtils.durationString(audioData.format.duration*1000); processedFile.hasThumb = false; if (!existsFull) { await moveUpload(file, processedFile.filename, 'img');