mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 15:39:11 +00:00
fix: project created without extension
This commit is contained in:
committed by
Carlos Valente
parent
af177060ff
commit
31799f8fab
@@ -49,7 +49,7 @@ export async function patchPartialProjectFile(req: Request, res: Response<Databa
|
|||||||
*/
|
*/
|
||||||
export async function createProjectFile(req: Request, res: Response<{ filename: string } | ErrorResponse>) {
|
export async function createProjectFile(req: Request, res: Response<{ filename: string } | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
const newFileName = await projectService.createProject(req.body.filename, {
|
const newFileName = await projectService.createProject(req.body.filename || 'untitled', {
|
||||||
project: {
|
project: {
|
||||||
title: req.body?.title ?? '',
|
title: req.body?.title ?? '',
|
||||||
description: req.body?.description ?? '',
|
description: req.body?.description ?? '',
|
||||||
@@ -75,7 +75,7 @@ export async function createProjectFile(req: Request, res: Response<{ filename:
|
|||||||
*/
|
*/
|
||||||
export async function quickProjectFile(req: Request, res: Response<{ filename: string } | ErrorResponse>) {
|
export async function quickProjectFile(req: Request, res: Response<{ filename: string } | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
const filename = await projectService.createProject(req.body.project.title, req.body);
|
const filename = await projectService.createProject(req.body.project.title || 'untitled', req.body);
|
||||||
res.status(200).send({
|
res.status(200).send({
|
||||||
filename,
|
filename,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { ensureJsonExtension } from '../../utils/fileManagement.js';
|
|||||||
* @description Validates request for a new project.
|
* @description Validates request for a new project.
|
||||||
*/
|
*/
|
||||||
export const validateNewProject = [
|
export const validateNewProject = [
|
||||||
|
body('filename').optional().isString().trim(),
|
||||||
body('title').optional().isString().trim(),
|
body('title').optional().isString().trim(),
|
||||||
body('description').optional().isString().trim(),
|
body('description').optional().isString().trim(),
|
||||||
body('publicUrl').optional().isString().trim(),
|
body('publicUrl').optional().isString().trim(),
|
||||||
@@ -132,8 +133,7 @@ export const validateFilenameParam = [
|
|||||||
.customSanitizer((input: string) => sanitize(input))
|
.customSanitizer((input: string) => sanitize(input))
|
||||||
.withMessage('Failed to sanitize the filename')
|
.withMessage('Failed to sanitize the filename')
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
.withMessage('Filename was empty or contained only invalid characters')
|
.withMessage('Filename was empty or contained only invalid characters'),
|
||||||
.customSanitizer((input: string) => ensureJsonExtension(input)),
|
|
||||||
|
|
||||||
(req: Request, res: Response, next: NextFunction) => {
|
(req: Request, res: Response, next: NextFunction) => {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
appendToName,
|
appendToName,
|
||||||
dockerSafeRename,
|
dockerSafeRename,
|
||||||
ensureDirectory,
|
ensureDirectory,
|
||||||
|
ensureJsonExtension,
|
||||||
generateUniqueFileName,
|
generateUniqueFileName,
|
||||||
getFileNameFromPath,
|
getFileNameFromPath,
|
||||||
removeFileExtension,
|
removeFileExtension,
|
||||||
@@ -20,6 +21,7 @@ import { parseRundown } from '../../utils/parserFunctions.js';
|
|||||||
import { demoDb } from '../../models/demoProject.js';
|
import { demoDb } from '../../models/demoProject.js';
|
||||||
import { config } from '../../setup/config.js';
|
import { config } from '../../setup/config.js';
|
||||||
import { getDataProvider, initPersistence } from '../../classes/data-provider/DataProvider.js';
|
import { getDataProvider, initPersistence } from '../../classes/data-provider/DataProvider.js';
|
||||||
|
import { safeMerge } from '../../classes/data-provider/DataProvider.utils.js';
|
||||||
|
|
||||||
import { initRundown } from '../rundown-service/RundownService.js';
|
import { initRundown } from '../rundown-service/RundownService.js';
|
||||||
import {
|
import {
|
||||||
@@ -37,7 +39,6 @@ import {
|
|||||||
moveCorruptFile,
|
moveCorruptFile,
|
||||||
parseJsonFile,
|
parseJsonFile,
|
||||||
} from './projectServiceUtils.js';
|
} from './projectServiceUtils.js';
|
||||||
import { safeMerge } from '../../classes/data-provider/DataProvider.utils.js';
|
|
||||||
|
|
||||||
// init dependencies
|
// init dependencies
|
||||||
init();
|
init();
|
||||||
@@ -257,7 +258,8 @@ export async function renameProjectFile(originalFile: string, newFilename: strin
|
|||||||
export async function createProject(filename: string, initialData: Partial<DatabaseModel>) {
|
export async function createProject(filename: string, initialData: Partial<DatabaseModel>) {
|
||||||
const data = safeMerge(dbModel, initialData);
|
const data = safeMerge(dbModel, initialData);
|
||||||
|
|
||||||
const uniqueFileName = generateUniqueFileName(publicDir.projectsDir, filename);
|
const fileNameWithExtension = ensureJsonExtension(filename);
|
||||||
|
const uniqueFileName = generateUniqueFileName(publicDir.projectsDir, fileNameWithExtension);
|
||||||
const newFile = getPathToProject(uniqueFileName);
|
const newFile = getPathToProject(uniqueFileName);
|
||||||
|
|
||||||
// change LowDB to point to new file
|
// change LowDB to point to new file
|
||||||
|
|||||||
Reference in New Issue
Block a user