* chore: upgrade dependencies
* feat/mac: draft pipeline
* feat/mac: use public folder for transient files
* feat/mac: set app fullscreen
* feat/mac: cmd + , toggles menu
* feat/mac: update readme
* refact: easier login process
* refact prevent style issues with safari
* refact reduce css download
* style: cleanup paginator design
* style: studio clock is responsive
* style: fix spacing style issues with safari
This commit is contained in:
Carlos Valente
2022-04-17 20:30:39 +02:00
committed by GitHub
parent 20d3ddbc18
commit db0eee3b9c
140 changed files with 10160 additions and 2139 deletions
+38 -12
View File
@@ -1,26 +1,52 @@
import multer from 'multer';
import { statSync, mkdirSync } from 'fs';
import { existsSync, mkdirSync } from 'fs';
import * as path from 'path';
import { EXCEL_MIME, JSON_MIME } from './parser.js';
/**
* @description Returns public path depending on os
* @return {string|*}
*/
function getAppDataPath() {
switch (process.platform) {
case 'darwin': {
return path.join(process.env.HOME, 'Library', 'Application Support', 'Ontime');
}
case 'win32': {
return path.join(process.env.APPDATA, 'Ontime');
}
case 'linux': {
return path.join(process.env.HOME, '.Ontime');
}
default: {
return '';
}
}
}
// Define multer storage object
const storage = multer.diskStorage({
destination: function (req, file, cb) {
let newDestination = 'uploads/';
let stat = null;
try {
stat = statSync(newDestination);
} catch (err) {
mkdirSync(newDestination);
// get platform path
const appDataPath = getAppDataPath();
if (appDataPath === '') {
throw new Error('Could not resolve public folder for platform');
}
if (stat && !stat.isDirectory()) {
throw new Error(
`Directory cannot be created because an inode of a different type exists at ${newDestination}`
);
// append uploads folder
const newDestination = path.join(appDataPath, 'uploads');
// Create directory if not exist
if (!existsSync(newDestination)) {
try {
mkdirSync(newDestination);
} catch (err) {
throw new Error('Could not create directory');
}
}
cb(null, newDestination);
},
filename: function (req, file, cb) {
cb(null, Date.now() + '--' + file.originalname);
cb(null, `${Date.now()}--${file.originalname}`);
},
});