mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 23:49:15 +00:00
Fix/external path (#702)
* leave styles as is but move other external to `external` folder
This commit is contained in:
committed by
GitHub
parent
9611722a6d
commit
b1ba47a80f
+12
-2
@@ -8,7 +8,14 @@ import cors from 'cors';
|
|||||||
|
|
||||||
// import utils
|
// import utils
|
||||||
import { join, resolve } from 'path';
|
import { join, resolve } from 'path';
|
||||||
import { currentDirectory, environment, externalsStartDirectory, isProduction, resolvedPath } from './setup.js';
|
import {
|
||||||
|
currentDirectory,
|
||||||
|
environment,
|
||||||
|
isProduction,
|
||||||
|
resolveExternalsDirectory,
|
||||||
|
resolveStylesDirectory,
|
||||||
|
resolvedPath,
|
||||||
|
} from './setup.js';
|
||||||
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
||||||
|
|
||||||
// Import Routes
|
// Import Routes
|
||||||
@@ -35,6 +42,7 @@ import { eventStore, getInitialPayload } from './stores/EventStore.js';
|
|||||||
import { PlaybackService } from './services/PlaybackService.js';
|
import { PlaybackService } from './services/PlaybackService.js';
|
||||||
import { RestorePoint, restoreService } from './services/RestoreService.js';
|
import { RestorePoint, restoreService } from './services/RestoreService.js';
|
||||||
import { messageService } from './services/message-service/MessageService.js';
|
import { messageService } from './services/message-service/MessageService.js';
|
||||||
|
import { populateDemo } from './modules/loadDemo.js';
|
||||||
|
|
||||||
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
||||||
|
|
||||||
@@ -64,7 +72,8 @@ app.use('/ontime', ontimeRouter);
|
|||||||
app.use('/playback', playbackRouter);
|
app.use('/playback', playbackRouter);
|
||||||
|
|
||||||
// serve static - css
|
// serve static - css
|
||||||
app.use('/external', express.static(externalsStartDirectory));
|
app.use('/external/styles', express.static(resolveStylesDirectory));
|
||||||
|
app.use('/external/', express.static(resolveExternalsDirectory));
|
||||||
app.use('/external', (req, res) => {
|
app.use('/external', (req, res) => {
|
||||||
res.status(404).send(`${req.originalUrl} not found`);
|
res.status(404).send(`${req.originalUrl} not found`);
|
||||||
});
|
});
|
||||||
@@ -129,6 +138,7 @@ export const initAssets = async () => {
|
|||||||
checkStart(OntimeStartOrder.InitAssets);
|
checkStart(OntimeStartOrder.InitAssets);
|
||||||
await dbLoadingProcess;
|
await dbLoadingProcess;
|
||||||
populateStyles();
|
populateStyles();
|
||||||
|
populateDemo();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,5 +8,9 @@ export const config = {
|
|||||||
directory: 'styles',
|
directory: 'styles',
|
||||||
filename: 'override.css',
|
filename: 'override.css',
|
||||||
},
|
},
|
||||||
|
demo: {
|
||||||
|
directory: 'demo',
|
||||||
|
filename: ['app.js', 'index.html', 'styles.css'],
|
||||||
|
},
|
||||||
restoreFile: 'ontime.restore',
|
restoreFile: 'ontime.restore',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { copyFile } from 'fs/promises';
|
||||||
|
import { pathToStartDemo, resolveDemoDirectory, resolveDemoPath } from '../setup.js';
|
||||||
|
import { ensureDirectory } from '../utils/fileManagement.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description ensures directories exist and populates demo folder
|
||||||
|
*/
|
||||||
|
export const populateDemo = () => {
|
||||||
|
ensureDirectory(resolveDemoDirectory);
|
||||||
|
// even if demo exist we want to use startup demo
|
||||||
|
try {
|
||||||
|
Promise.all(
|
||||||
|
resolveDemoPath.map((to, index) => {
|
||||||
|
const from = pathToStartDemo[index];
|
||||||
|
copyFile(from, to);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
/* we do not handle this */
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,20 +4,15 @@ import { ensureDirectory } from '../utils/fileManagement.js';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description ensures directories exist and populates stylesheet
|
* @description ensures directories exist and populates stylesheet
|
||||||
* @return {string} - path to stylesheet file
|
|
||||||
*/
|
*/
|
||||||
export const populateStyles = () => {
|
export const populateStyles = () => {
|
||||||
const stylesInDisk = resolveStylesPath;
|
|
||||||
ensureDirectory(resolveStylesDirectory);
|
ensureDirectory(resolveStylesDirectory);
|
||||||
|
// if styles doesn't exist we want to use startup stylesheet
|
||||||
// if stylesInDisk doesn't exist we want to use startup stylesheet
|
if (!existsSync(resolveStylesPath)) {
|
||||||
if (!existsSync(stylesInDisk)) {
|
|
||||||
try {
|
try {
|
||||||
copyFileSync(pathToStartStyles, stylesInDisk);
|
copyFileSync(pathToStartStyles, resolveStylesPath);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
/* we do not handle this */
|
/* we do not handle this */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return stylesInDisk;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ export const currentDirectory = dirname(__dirname);
|
|||||||
|
|
||||||
const testDbStartDirectory = isTest ? '../' : getAppDataPath();
|
const testDbStartDirectory = isTest ? '../' : getAppDataPath();
|
||||||
export const externalsStartDirectory = isProduction ? getAppDataPath() : join(currentDirectory, 'external');
|
export const externalsStartDirectory = isProduction ? getAppDataPath() : join(currentDirectory, 'external');
|
||||||
|
//TODO: we only need one when they are all in the same folder
|
||||||
|
export const resolveExternalsDirectory = join(isProduction ? getAppDataPath() : currentDirectory, 'external');
|
||||||
// path to public db
|
// path to public db
|
||||||
export const resolveDbDirectory = join(
|
export const resolveDbDirectory = join(
|
||||||
testDbStartDirectory,
|
testDbStartDirectory,
|
||||||
@@ -80,11 +81,26 @@ export const pathToStartDb = isTest
|
|||||||
? join(currentDirectory, '../', config.database.testdb, config.database.filename)
|
? join(currentDirectory, '../', config.database.testdb, config.database.filename)
|
||||||
: join(currentDirectory, '/preloaded-db/', config.database.filename);
|
: join(currentDirectory, '/preloaded-db/', config.database.filename);
|
||||||
|
|
||||||
|
//TODO: move all static files to the external directory
|
||||||
// path to public styles
|
// path to public styles
|
||||||
export const resolveStylesDirectory = join(externalsStartDirectory, config.styles.directory);
|
export const resolveStylesDirectory = join(externalsStartDirectory, config.styles.directory);
|
||||||
export const resolveStylesPath = join(resolveStylesDirectory, config.styles.filename);
|
export const resolveStylesPath = join(resolveStylesDirectory, config.styles.filename);
|
||||||
|
|
||||||
export const pathToStartStyles = join(currentDirectory, '/external/styles/', config.styles.filename);
|
export const pathToStartStyles = join(currentDirectory, '/external/styles/', config.styles.filename);
|
||||||
|
|
||||||
|
// path to public demo
|
||||||
|
export const resolveDemoDirectory = join(
|
||||||
|
externalsStartDirectory,
|
||||||
|
isProduction ? '/external/' : '', //move to external folde in production
|
||||||
|
config.demo.directory,
|
||||||
|
);
|
||||||
|
export const resolveDemoPath = config.demo.filename.map((file) => {
|
||||||
|
return join(resolveDemoDirectory, file);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const pathToStartDemo = config.demo.filename.map((file) => {
|
||||||
|
return join(currentDirectory, '/external/demo/', file);
|
||||||
|
});
|
||||||
|
|
||||||
// path to restore file
|
// path to restore file
|
||||||
export const resolveRestoreFile = join(getAppDataPath(), config.restoreFile);
|
export const resolveRestoreFile = join(getAppDataPath(), config.restoreFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user