mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 00:43:54 +00:00
feat: implement custom project data image
This commit is contained in:
@@ -1,10 +1,39 @@
|
||||
import { ProjectData } from 'ontime-types';
|
||||
import { ProjectData, RefetchKey } from 'ontime-types';
|
||||
|
||||
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||
import { join } from 'node:path';
|
||||
import { deleteFile } from '../../utils/fileManagement.js';
|
||||
import { publicDir } from '../../setup/index.js';
|
||||
import { sendRefetch } from '../../adapters/WebsocketAdapter.js';
|
||||
|
||||
/**
|
||||
* Gets a copy of the stored project data
|
||||
* Gets the stored project data
|
||||
*/
|
||||
export function getProjectData(): ProjectData {
|
||||
return structuredClone(getDataProvider().getProjectData());
|
||||
export function getProjectData(): Readonly<ProjectData> {
|
||||
return getDataProvider().getProjectData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches the current project data
|
||||
* Handles deleting the local logo if the logo has been removed
|
||||
*/
|
||||
export async function editCurrentProjectData(newData: Partial<ProjectData>) {
|
||||
const currentProjectData = getDataProvider().getProjectData();
|
||||
const updatedProjectData = await getDataProvider().setProjectData(newData);
|
||||
|
||||
// Delete the old logo if the logo has been removed
|
||||
if (!updatedProjectData.logo && currentProjectData.logo) {
|
||||
const filePath = join(publicDir.logoDir, currentProjectData.logo);
|
||||
|
||||
deleteFile(filePath).catch((_error) => {
|
||||
/** we do not handle this error */
|
||||
});
|
||||
}
|
||||
|
||||
// Notify the websocket clients to refetch the project data
|
||||
setImmediate(() => {
|
||||
sendRefetch(RefetchKey.ProjectData);
|
||||
});
|
||||
|
||||
return updatedProjectData;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { uploadImageFile } from '../db/db.middleware.js';
|
||||
import { postProjectLogo } from '../db/db.controller.js';
|
||||
import * as projectDao from './projectData.dao.js';
|
||||
import { removeUndefined } from '../../utils/parserUtils.js';
|
||||
import { editCurrentProjectData } from '../../services/project-service/ProjectService.js';
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
@@ -27,7 +26,7 @@ router.post('/', projectSanitiser, async (req: Request, res: Response<ProjectDat
|
||||
custom: req.body?.custom,
|
||||
});
|
||||
|
||||
const updatedData = await editCurrentProjectData(newData);
|
||||
const updatedData = await projectDao.editCurrentProjectData(newData);
|
||||
|
||||
res.status(200).send(updatedData);
|
||||
} catch (error) {
|
||||
|
||||
@@ -11,6 +11,7 @@ export const projectSanitiser = [
|
||||
body('custom').optional().isArray(),
|
||||
body('custom.*.title').optional().isString().trim().notEmpty(),
|
||||
body('custom.*.value').optional().isString().trim().notEmpty(),
|
||||
body('custom.*.url').optional().isString().trim().notEmpty(),
|
||||
|
||||
requestValidationFunction,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user