make file duration strings handle over 24h and cleanup some file info addings in makepost

merge-requests/208/head
fatchan 5 years ago
parent 497832ab12
commit 8f7afcf1f6
  1. 2
      helpers/files/formatsize.js
  2. 10
      helpers/timeutils.js
  3. 19
      models/forms/makepost.js

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const sizes = ['B', 'KB', 'MB'] const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
, k = 1024; , k = 1024;
module.exports = (bytes) => { module.exports = (bytes) => {

@ -72,6 +72,16 @@ module.exports = {
g = (Math.round(g*255*0.85).toString(16)).padStart(2, '0'); g = (Math.round(g*255*0.85).toString(16)).padStart(2, '0');
b = (Math.round(b*255).toString(16)).padStart(2, '0'); b = (Math.round(b*255).toString(16)).padStart(2, '0');
return `#${r}${g}${b}`; 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)}`;
}
} }
}; };

@ -176,7 +176,7 @@ module.exports = async (req, res, next) => {
} }
let imageData; let imageData;
if (type === 'image') { 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); 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? if (imageData['Channel Statistics'] && imageData['Channel Statistics']['Opacity']) { //does this change depending on GM version or anything?
const opacityMaximum = imageData['Channel Statistics']['Opacity']['Maximum']; const opacityMaximum = imageData['Channel Statistics']['Opacity']['Maximum'];
@ -191,12 +191,13 @@ module.exports = async (req, res, next) => {
//check if already exists //check if already exists
const existsFull = await pathExists(`${uploadDirectory}/img/${processedFile.filename}`); const existsFull = await pathExists(`${uploadDirectory}/img/${processedFile.filename}`);
processedFile.sizeString = formatSize(processedFile.size)
switch (type) { switch (type) {
case 'image': { case 'image': {
const existsThumb = await pathExists(`${uploadDirectory}/img/thumb-${processedFile.hash}${processedFile.thumbextension}`); const existsThumb = await pathExists(`${uploadDirectory}/img/thumb-${processedFile.hash}${processedFile.thumbextension}`);
processedFile.geometry = imageData.size // object with width and height pixels processedFile.geometry = imageData.size ;
processedFile.sizeString = formatSize(processedFile.size) // 123 Ki string processedFile.geometryString = imageData.Geometry;
processedFile.geometryString = imageData.Geometry // 123 x 123 string
processedFile.hasThumb = !(fileCheckMimeType(file.mimetype, {image: true}) processedFile.hasThumb = !(fileCheckMimeType(file.mimetype, {image: true})
&& processedFile.geometry.height <= thumbSize && processedFile.geometry.height <= thumbSize
&& processedFile.geometry.width <= thumbSize); && processedFile.geometry.width <= thumbSize);
@ -223,10 +224,9 @@ module.exports = async (req, res, next) => {
}); });
} }
processedFile.duration = videoData.format.duration; 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.durationString = timeUtils.durationString(videoData.format.duration*1000);
processedFile.geometry = {width: videoData.streams[0].coded_width, height: videoData.streams[0].coded_height} // object with width and height pixels processedFile.geometry = {width: videoData.streams[0].coded_width, height: videoData.streams[0].coded_height};
processedFile.sizeString = formatSize(processedFile.size) // 123 Ki string processedFile.geometryString = `${processedFile.geometry.width}x${processedFile.geometry.height}`
processedFile.geometryString = `${processedFile.geometry.width}x${processedFile.geometry.height}` // 123 x 123 string
processedFile.hasThumb = true; processedFile.hasThumb = true;
if (!existsFull) { if (!existsFull) {
await moveUpload(file, processedFile.filename, 'img'); await moveUpload(file, processedFile.filename, 'img');
@ -239,8 +239,7 @@ module.exports = async (req, res, next) => {
case 'audio': { case 'audio': {
const audioData = await ffprobe(req.files.file[i].tempFilePath, null, true); const audioData = await ffprobe(req.files.file[i].tempFilePath, null, true);
processedFile.duration = audioData.format.duration; 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.durationString = timeUtils.durationString(audioData.format.duration*1000);
processedFile.sizeString = formatSize(processedFile.size) // 123 Ki string
processedFile.hasThumb = false; processedFile.hasThumb = false;
if (!existsFull) { if (!existsFull) {
await moveUpload(file, processedFile.filename, 'img'); await moveUpload(file, processedFile.filename, 'img');

Loading…
Cancel
Save