mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-09 01:13:55 +00:00
Feat/mac (#109)
* 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:
+38
-12
@@ -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}`);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user