mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 20:03:52 +00:00
Preview Sheet
This commit is contained in:
@@ -397,13 +397,8 @@ export async function previewExcel(req, res) {
|
||||
* @returns parsed result
|
||||
*/
|
||||
export async function previewSheet(req, res) {
|
||||
if (!req.body.sheetid) {
|
||||
res.status(400).send({ message: 'missing sheet id' });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const options = JSON.parse(req.body.options);
|
||||
const data = await Sheet.parse(req.body.sheetid, req.body.worksheet, options);
|
||||
const data = await Sheet.parse(req.body.sheetid, req.body.worksheet);
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: error.toString() });
|
||||
@@ -421,13 +416,15 @@ export async function sheetClientFile(req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const client = JSON.parse( fs.readFileSync(req.file.path as string, 'utf-8'));
|
||||
const client = JSON.parse(fs.readFileSync(req.file.path as string, 'utf-8'));
|
||||
await Sheet.saveClientSecrets(client);
|
||||
res.status(200).send('OK');
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: error.toString() });
|
||||
}
|
||||
fs.unlink(req.file.path, (err) => {if(err) (logger.error(LogOrigin.Server, err.message))});
|
||||
fs.unlink(req.file.path, (err) => {
|
||||
if (err) logger.error(LogOrigin.Server, err.message);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -133,3 +133,15 @@ export const validatePatchProjectFile = [
|
||||
next();
|
||||
},
|
||||
];
|
||||
|
||||
//TODO: is thise correct
|
||||
export const validateSheetPreview = [
|
||||
body('sheetid').isString().optional({ nullable: false }),
|
||||
body('worksheet').isString().optional({ nullable: false }),
|
||||
body('options').isObject().optional({ nullable: true }),
|
||||
(req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
||||
next();
|
||||
},
|
||||
];
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
validateOscSubscription,
|
||||
validatePatchProjectFile,
|
||||
validateSettings,
|
||||
validateSheetPreview,
|
||||
validateUserFields,
|
||||
viewValidator,
|
||||
} from '../controllers/ontimeController.validate.js';
|
||||
@@ -101,7 +102,5 @@ router.get('/sheet-authstatus', sheetAuthState);
|
||||
// create route between controller and '/ontime/sheet-authstatus' endpoint
|
||||
router.get('/sheet-authurl', sheetAuthUrl);
|
||||
|
||||
router.get('/sheet-authurl', previewSheet);
|
||||
|
||||
// create route between controller and '/ontime/preview-sheet' endpoint
|
||||
router.get('/sheet-preview', previewSheet);
|
||||
router.post('/sheet-preview', validateSheetPreview, previewSheet);
|
||||
@@ -6,7 +6,7 @@ import { URL } from 'url';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
import { getAppDataPath } from '../setup.js';
|
||||
import { DatabaseModel, LogOrigin } from 'ontime-types';
|
||||
import { ExcelImportOptions, isExcelImportMap } from 'ontime-utils';
|
||||
import { ExcelImportOptions, isExcelImportMap, defaultExcelImportMap } from 'ontime-utils';
|
||||
import { parseExcel } from './parser.js';
|
||||
import { parseProject, parseRundown, parseUserFields } from './parserFunctions.js';
|
||||
import { ensureDirectory } from './fileManagement.js';
|
||||
@@ -45,7 +45,7 @@ class sheet {
|
||||
* @returns {Promise<Partial<ResponseOK>>}
|
||||
* @throws
|
||||
*/
|
||||
public async parse(sheetId: string, worksheet: string, options: ExcelImportOptions) {
|
||||
public async parse(sheetId: string, worksheet: string, options = defaultExcelImportMap) {
|
||||
if (!sheet.client) {
|
||||
if (!(await this.authorized())) {
|
||||
throw new Error(`Sheet not authorized`);
|
||||
|
||||
Reference in New Issue
Block a user