1
1
import { fileURLToPath } from 'url' ;
2
- import path , { dirname , join } from 'path' ;
3
- import fs from 'fs' ;
4
-
5
- import { rm } from 'fs/promises' ;
2
+ import { dirname , join } from 'path' ;
3
+ import { readFileSync , writeFileSync } from 'fs' ;
6
4
7
5
import { config } from './config.js' ;
8
6
import { ensureDirectory } from '../utils/fileManagement.js' ;
@@ -17,18 +15,18 @@ import { ensureDirectory } from '../utils/fileManagement.js';
17
15
export function getAppDataPath ( ) : string {
18
16
// handle docker
19
17
if ( process . env . ONTIME_DATA ) {
20
- return path . join ( process . env . ONTIME_DATA ) ;
18
+ return join ( process . env . ONTIME_DATA ) ;
21
19
}
22
20
23
21
switch ( process . platform ) {
24
22
case 'darwin' : {
25
- return path . join ( process . env . HOME ! , 'Library' , 'Application Support' , 'Ontime' ) ;
23
+ return join ( process . env . HOME ! , 'Library' , 'Application Support' , 'Ontime' ) ;
26
24
}
27
25
case 'win32' : {
28
- return path . join ( process . env . APPDATA ! , 'Ontime' ) ;
26
+ return join ( process . env . APPDATA ! , 'Ontime' ) ;
29
27
}
30
28
case 'linux' : {
31
- return path . join ( process . env . HOME ! , '.Ontime' ) ;
29
+ return join ( process . env . HOME ! , '.Ontime' ) ;
32
30
}
33
31
default : {
34
32
throw new Error ( 'Could not resolve public folder for platform' ) ;
@@ -56,11 +54,11 @@ if (import.meta.url) {
56
54
// path to server src folder
57
55
const currentDir = dirname ( __dirname ) ;
58
56
// locally we are in src/setup, in the production build, this is a single file at src
59
- export const srcDirectory = isProduction ? currentDir : path . join ( currentDir , '../' ) ;
57
+ export const srcDirectory = isProduction ? currentDir : join ( currentDir , '../' ) ;
60
58
61
59
// resolve path to external
62
- const productionPath = path . join ( srcDirectory , 'client/' ) ;
63
- const devPath = path . join ( srcDirectory , '../../client/build/' ) ;
60
+ const productionPath = join ( srcDirectory , 'client/' ) ;
61
+ const devPath = join ( srcDirectory , '../../client/build/' ) ;
64
62
65
63
export const resolvedPath = ( ) : string => {
66
64
if ( isTest ) {
@@ -83,12 +81,12 @@ export const uploadsFolderPath = join(getAppDataPath(), config.uploads);
83
81
84
82
const ensureAppState = ( ) => {
85
83
ensureDirectory ( getAppDataPath ( ) ) ;
86
- fs . writeFileSync ( appStatePath , JSON . stringify ( { lastLoadedProject : 'db.json' } ) ) ;
84
+ writeFileSync ( appStatePath , JSON . stringify ( { lastLoadedProject : 'db.json' } ) ) ;
87
85
} ;
88
86
89
87
const getLastLoadedProject = ( ) => {
90
88
try {
91
- const appState = JSON . parse ( fs . readFileSync ( appStatePath , 'utf8' ) ) ;
89
+ const appState = JSON . parse ( readFileSync ( appStatePath , 'utf8' ) ) ;
92
90
if ( ! appState . lastLoadedProject ) {
93
91
ensureAppState ( ) ;
94
92
}
@@ -142,11 +140,3 @@ export const resolveCrashReportDirectory = getAppDataPath();
142
140
143
141
// path to projects
144
142
export const resolveProjectsDirectory = join ( getAppDataPath ( ) , config . projects ) ;
145
-
146
- export async function clearUploadfolder ( ) {
147
- try {
148
- await rm ( uploadsFolderPath , { recursive : true } ) ;
149
- } catch ( _ ) {
150
- //we dont care that there was no folder
151
- }
152
- }
0 commit comments