mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 04:13:47 +00:00
change some naming
This commit is contained in:
@@ -3,14 +3,14 @@ import {
|
||||
Alias,
|
||||
DatabaseModel,
|
||||
GetInfo,
|
||||
GoogleSheet,
|
||||
GoogleSheetState,
|
||||
HttpSettings,
|
||||
OntimeRundown,
|
||||
OSCSettings,
|
||||
OscSubscription,
|
||||
ProjectData,
|
||||
Settings,
|
||||
Sheet,
|
||||
SheetState,
|
||||
UserFields,
|
||||
ViewSettings,
|
||||
} from 'ontime-types';
|
||||
@@ -281,28 +281,28 @@ export const postPushSheet = async () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @description HTTP request to retrieve google sheets settings
|
||||
* @description HTTP request to retrieve sheets settings
|
||||
* @return {Promise}
|
||||
*/
|
||||
export async function getSheetSettings(): Promise<GoogleSheet> {
|
||||
export async function getSheetSettings(): Promise<Sheet> {
|
||||
const res = await axios.get(`${ontimeURL}/sheet-settings`);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description HTTP request to mutate google sheets settings
|
||||
* @description HTTP request to mutate sheets settings
|
||||
* @return {Promise}
|
||||
*/
|
||||
export async function postSheetSettings(data: GoogleSheet): Promise<GoogleSheet> {
|
||||
export async function postSheetSettings(data: Sheet): Promise<Sheet> {
|
||||
const res = await axios.post(`${ontimeURL}/sheet-settings`, data);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description HTTP request to retrieve google sheets state
|
||||
* @description HTTP request to retrieve sheets state
|
||||
* @return {Promise}
|
||||
*/
|
||||
export async function getSheetState(): Promise<GoogleSheetState> {
|
||||
export async function getSheetState(): Promise<SheetState> {
|
||||
const res = await axios.get(`${ontimeURL}/sheet-state`);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
UserFields,
|
||||
Alias,
|
||||
Settings,
|
||||
GoogleSheet,
|
||||
Sheet,
|
||||
} from 'ontime-types';
|
||||
|
||||
import { data, db } from '../../modules/loadDb.js';
|
||||
@@ -59,12 +59,12 @@ export class DataProvider {
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
static getGoogleSheet() {
|
||||
return data.googleSheet;
|
||||
static getSheet() {
|
||||
return data.sheet;
|
||||
}
|
||||
|
||||
static async setGoogleSheet(newData: GoogleSheet) {
|
||||
data.googleSheet = { ...newData };
|
||||
static async setSheet(newData: Sheet) {
|
||||
data.sheet = { ...newData };
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ import { DatabaseModel } from 'ontime-types';
|
||||
* @param {object} newData
|
||||
*/
|
||||
export function safeMerge(existing: DatabaseModel, newData: Partial<DatabaseModel>) {
|
||||
const { rundown, project, settings, googleSheet, viewSettings, osc, aliases, userFields } = newData || {};
|
||||
const { rundown, project, settings, sheet, viewSettings, osc, aliases, userFields } = newData || {};
|
||||
return {
|
||||
...existing,
|
||||
rundown: rundown ?? existing.rundown,
|
||||
project: { ...existing.project, ...project },
|
||||
settings: { ...existing.settings, ...settings },
|
||||
googleSheet: { ...existing.googleSheet, ...googleSheet },
|
||||
sheet: { ...existing.sheet, ...sheet },
|
||||
viewSettings: { ...existing.viewSettings, ...viewSettings },
|
||||
aliases: aliases ?? existing.aliases,
|
||||
userFields: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Alias, DatabaseModel, GoogleSheet, OntimeRundown, Settings } from 'ontime-types';
|
||||
import { Alias, DatabaseModel, Sheet, OntimeRundown, Settings } from 'ontime-types';
|
||||
import { safeMerge } from '../DataProvider.utils.js';
|
||||
|
||||
describe('safeMerge', () => {
|
||||
@@ -21,7 +21,7 @@ describe('safeMerge', () => {
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
},
|
||||
googleSheet: {
|
||||
sheet: {
|
||||
worksheet: '1',
|
||||
id: '2',
|
||||
},
|
||||
@@ -102,15 +102,15 @@ describe('safeMerge', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('merges the google sheet key', () => {
|
||||
it('merges the sheet key', () => {
|
||||
const newData = {
|
||||
googleSheet: {
|
||||
sheet: {
|
||||
id: '4',
|
||||
worksheet: '5',
|
||||
} as GoogleSheet,
|
||||
} as Sheet,
|
||||
};
|
||||
const mergedData = safeMerge(existing, newData);
|
||||
expect(mergedData.googleSheet).toEqual({
|
||||
expect(mergedData.sheet).toEqual({
|
||||
id: '4',
|
||||
worksheet: '5',
|
||||
});
|
||||
|
||||
@@ -488,7 +488,7 @@ export async function pushSheet(req, res) {
|
||||
* uploads Client secrets file
|
||||
* @returns parsed result
|
||||
*/
|
||||
export async function uploadGoogleSheetClientFile(req, res) {
|
||||
export async function uploadSheetClientFile(req, res) {
|
||||
if (!req.file.path) {
|
||||
res.status(400).send({ message: 'File not found' });
|
||||
return;
|
||||
@@ -520,11 +520,11 @@ export async function sheetAuthUrl(req, res) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get google sheet Settings
|
||||
* @description Get s sheet Settings
|
||||
* @method GET
|
||||
*/
|
||||
export const getGoogleSheetSettings = async (req, res) => {
|
||||
const sheet = await DataProvider.getGoogleSheet();
|
||||
export const getSheetSettings = async (req, res) => {
|
||||
const sheet = await DataProvider.getSheet();
|
||||
res.status(200).send(sheet);
|
||||
};
|
||||
|
||||
@@ -532,7 +532,7 @@ export const getGoogleSheetSettings = async (req, res) => {
|
||||
* @description Change view Settings
|
||||
* @method POST
|
||||
*/
|
||||
export const postGoogleSheetSettings = async (req, res) => {
|
||||
export const postSheetSettings = async (req, res) => {
|
||||
if (failEmptyObjects(req.body, res)) {
|
||||
return;
|
||||
}
|
||||
@@ -542,7 +542,7 @@ export const postGoogleSheetSettings = async (req, res) => {
|
||||
id: req.body.id,
|
||||
worksheet: req.body.worksheet,
|
||||
};
|
||||
await DataProvider.setGoogleSheet(newData);
|
||||
await DataProvider.setSheet(newData);
|
||||
res.status(200).send(newData);
|
||||
} catch (error) {
|
||||
res.status(400).send({ message: error.toString() });
|
||||
@@ -550,9 +550,9 @@ export const postGoogleSheetSettings = async (req, res) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get google sheet state
|
||||
* @description Get sheet state
|
||||
* @method GET
|
||||
*/
|
||||
export const getGoogleSheetState = async (req, res) => {
|
||||
export const getSheetState = async (req, res) => {
|
||||
res.status(200).send(await Sheet.getSheetState());
|
||||
};
|
||||
|
||||
@@ -165,7 +165,7 @@ export const validateSheetPreview = [
|
||||
},
|
||||
];
|
||||
|
||||
export const validateGoogleSheetSettings = [
|
||||
export const validateSheetSettings = [
|
||||
body('id').isString().optional({ nullable: false }),
|
||||
body('worksheet').isString().optional({ nullable: false }),
|
||||
(req, res, next) => {
|
||||
|
||||
@@ -20,9 +20,9 @@ export const dbModel: DatabaseModel = {
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
},
|
||||
googleSheet: {
|
||||
worksheet: '',
|
||||
sheet: {
|
||||
id: '',
|
||||
worksheet: '',
|
||||
},
|
||||
viewSettings: {
|
||||
overrideStyles: false,
|
||||
|
||||
@@ -22,17 +22,17 @@ import {
|
||||
previewExcel,
|
||||
postHTTP,
|
||||
sheetAuthUrl,
|
||||
uploadGoogleSheetClientFile,
|
||||
uploadSheetClientFile,
|
||||
previewSheet,
|
||||
pushSheet,
|
||||
getGoogleSheetSettings,
|
||||
postGoogleSheetSettings,
|
||||
getGoogleSheetState,
|
||||
getSheetSettings,
|
||||
postSheetSettings,
|
||||
getSheetState,
|
||||
} from '../controllers/ontimeController.js';
|
||||
|
||||
import {
|
||||
validateAliases,
|
||||
validateGoogleSheetSettings,
|
||||
validateSheetSettings,
|
||||
validateOSC,
|
||||
validatePatchProjectFile,
|
||||
validateSettings,
|
||||
@@ -107,7 +107,7 @@ router.post('/http', validateHTTP, postHTTP);
|
||||
router.post('/new', projectSanitiser, postNew);
|
||||
|
||||
// create route between controller and '/ontime/sheet-client' endpoint
|
||||
router.post('/sheet-clientsecrect', uploadFile, uploadGoogleSheetClientFile);
|
||||
router.post('/sheet-clientsecrect', uploadFile, uploadSheetClientFile);
|
||||
|
||||
// create route between controller and '/ontime/sheet-authstatus' endpoint
|
||||
router.get('/sheet-authurl', sheetAuthUrl);
|
||||
@@ -119,10 +119,10 @@ router.post('/sheet-preview', validateSheetPreview, previewSheet);
|
||||
router.post('/sheet-push', pushSheet);
|
||||
|
||||
// create route between controller and '/ontime/sheet-settings' endpoint
|
||||
router.get('/sheet-settings', getGoogleSheetSettings);
|
||||
router.get('/sheet-settings', getSheetSettings);
|
||||
|
||||
// create route between controller and '/ontime/sheet-settings' endpoint
|
||||
router.post('/sheet-settings', validateGoogleSheetSettings, postGoogleSheetSettings);
|
||||
router.post('/sheet-settings', validateSheetSettings, postSheetSettings);
|
||||
|
||||
// create route between controller and '/ontime/sheet-state' endpoint
|
||||
router.get('/sheet-state', getGoogleSheetState);
|
||||
router.get('/sheet-state', getSheetState);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { millisToString } from 'ontime-utils';
|
||||
import { getA1Notation, cellRequenstFromEvent, cellRequenstFromProjectData } from '../googleSheetUtils.js';
|
||||
import { getA1Notation, cellRequenstFromEvent, cellRequenstFromProjectData } from '../sheetUtils.js';
|
||||
import { EndAction, OntimeRundownEntry, ProjectData, SupportedEvent, TimerType } from 'ontime-types';
|
||||
|
||||
describe('getA1Notation()', () => {
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
parseSettings,
|
||||
parseUserFields,
|
||||
parseViewSettings,
|
||||
parseGoogleSheet,
|
||||
parseSheet,
|
||||
} from './parserFunctions.js';
|
||||
import { parseExcelDate } from './time.js';
|
||||
import { coerceBoolean } from './coerceType.js';
|
||||
@@ -371,8 +371,8 @@ export const parseJson = async (jsonData): Promise<DatabaseModel | null> => {
|
||||
returnData.osc = parseOsc(jsonData) ?? dbModel.osc;
|
||||
// Import HTTP settings if any
|
||||
returnData.http = parseHttp(jsonData) ?? dbModel.http;
|
||||
// Import GoogleSheet settings if any
|
||||
returnData.googleSheet = parseGoogleSheet(jsonData, true);
|
||||
// Import Sheet settings if any
|
||||
returnData.sheet = parseSheet(jsonData, true);
|
||||
|
||||
return returnData as DatabaseModel;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { generateId } from 'ontime-utils';
|
||||
import {
|
||||
Alias,
|
||||
GoogleSheet,
|
||||
Sheet,
|
||||
OntimeRundown,
|
||||
HttpSettings,
|
||||
OSCSettings,
|
||||
@@ -335,20 +335,20 @@ export const parseUserFields = (data): UserFields => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse Google Sheet portion of an entry
|
||||
* Parse Sheet portion of an entry
|
||||
* @param {object} data - data object
|
||||
* @param {boolean} enforce - whether to create a definition if one is missing
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseGoogleSheet = (data, enforce) => {
|
||||
const newSheet: GoogleSheet = {
|
||||
export const parseSheet = (data, enforce) => {
|
||||
const newSheet: Sheet = {
|
||||
id: '',
|
||||
worksheet: '',
|
||||
};
|
||||
if ('googleSheet' in data) {
|
||||
console.log('Found Google Sheet definition, importing...');
|
||||
newSheet.id ??= data.googleSheet?.id;
|
||||
newSheet.worksheet ??= data.googleSheet?.worksheet;
|
||||
if ('sheet' in data) {
|
||||
console.log('Found Sheet definition, importing...');
|
||||
newSheet.id ??= data.sheet?.id;
|
||||
newSheet.worksheet ??= data.sheet?.worksheet;
|
||||
return newSheet;
|
||||
} else if (enforce) {
|
||||
return newSheet;
|
||||
|
||||
@@ -3,14 +3,14 @@ import { writeFile } from 'fs/promises';
|
||||
import { readFileSync } from 'fs';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
import http from 'http';
|
||||
import { DatabaseModel, GoogleSheetState, LogOrigin } from 'ontime-types';
|
||||
import { DatabaseModel, SheetState, LogOrigin } from 'ontime-types';
|
||||
import { join } from 'path';
|
||||
import { URL } from 'url';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
import { DataProvider } from '../classes/data-provider/DataProvider.js';
|
||||
import { getAppDataPath } from '../setup.js';
|
||||
import { ensureDirectory } from './fileManagement.js';
|
||||
import { cellRequenstFromEvent, cellRequenstFromProjectData, getA1Notation } from './googleSheetUtils.js';
|
||||
import { cellRequenstFromEvent, cellRequenstFromProjectData, getA1Notation } from './sheetUtils.js';
|
||||
import { parseExcel } from './parser.js';
|
||||
import { parseProject, parseRundown, parseUserFields } from './parserFunctions.js';
|
||||
|
||||
@@ -41,8 +41,8 @@ class sheet {
|
||||
}
|
||||
}
|
||||
|
||||
public async getSheetState(): Promise<GoogleSheetState> {
|
||||
const ret: GoogleSheetState = {
|
||||
public async getSheetState(): Promise<SheetState> {
|
||||
const ret: SheetState = {
|
||||
secret: false,
|
||||
auth: false,
|
||||
id: false,
|
||||
@@ -60,12 +60,12 @@ class sheet {
|
||||
try {
|
||||
ret.auth = await this.refreshToken();
|
||||
} catch (err) {
|
||||
logger.error(LogOrigin.Server, `Google Sheet: Faild to refresh token ${err}`);
|
||||
logger.error(LogOrigin.Server, `Sheet: Faild to refresh token ${err}`);
|
||||
}
|
||||
if (!ret.auth) {
|
||||
return ret;
|
||||
}
|
||||
const settings = DataProvider.getGoogleSheet();
|
||||
const settings = DataProvider.getSheet();
|
||||
if (settings.id != '') {
|
||||
const spreadsheets = await sheets({ version: 'v4', auth: sheet.client })
|
||||
.spreadsheets.get({
|
||||
@@ -73,7 +73,7 @@ class sheet {
|
||||
includeGridData: false,
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(LogOrigin.Server, `Google Sheet: faild to load sheet ${err}`);
|
||||
logger.error(LogOrigin.Server, `Sheet: faild to load sheet ${err}`);
|
||||
});
|
||||
if (!spreadsheets || spreadsheets.status != 200) {
|
||||
return ret;
|
||||
@@ -119,7 +119,7 @@ class sheet {
|
||||
* @throws
|
||||
*/
|
||||
public async push() {
|
||||
const { id, worksheet } = DataProvider.getGoogleSheet();
|
||||
const { id, worksheet } = DataProvider.getSheet();
|
||||
const { worksheetId, range } = await this.exist(id, worksheet);
|
||||
|
||||
const rq = await sheets({ version: 'v4', auth: sheet.client }).spreadsheets.values.get({
|
||||
@@ -198,7 +198,7 @@ class sheet {
|
||||
* @throws
|
||||
*/
|
||||
public async pull(): Promise<Partial<ResponseOK>> {
|
||||
const { id, worksheet } = DataProvider.getGoogleSheet();
|
||||
const { id, worksheet } = DataProvider.getSheet();
|
||||
const { range } = await this.exist(id, worksheet);
|
||||
|
||||
const res: Partial<ResponseOK> = {};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { OSCSettings } from './core/OscSettings.type.js';
|
||||
import { Settings } from './core/Settings.type.js';
|
||||
import { UserFields } from './core/UserFields.type.js';
|
||||
import { ViewSettings } from './core/Views.type.js';
|
||||
import { GoogleSheet, HttpSettings } from '../index.js';
|
||||
import { Sheet, HttpSettings } from '../index.js';
|
||||
|
||||
export type DatabaseModel = {
|
||||
rundown: OntimeRundown;
|
||||
@@ -14,7 +14,7 @@ export type DatabaseModel = {
|
||||
viewSettings: ViewSettings;
|
||||
aliases: Alias[];
|
||||
userFields: UserFields;
|
||||
googleSheet: GoogleSheet;
|
||||
sheet: Sheet;
|
||||
osc: OSCSettings;
|
||||
http: HttpSettings;
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
export type GoogleSheet = {
|
||||
export type Sheet = {
|
||||
worksheet: string | null;
|
||||
id: string | null;
|
||||
};
|
||||
|
||||
export type GoogleSheetState = {
|
||||
export type SheetState = {
|
||||
secret: boolean;
|
||||
auth: boolean;
|
||||
id: boolean;
|
||||
@@ -37,8 +37,8 @@ export type { OSCSettings, OscSubscription, OscSubscriptionOptions } from './def
|
||||
// ---> HTTP
|
||||
export type { HttpSettings, HttpSubscription, HttpSubscriptionOptions } from './definitions/core/HttpSettings.type.js';
|
||||
|
||||
// ---> Google Sheet
|
||||
export type { GoogleSheet, GoogleSheetState } from './definitions/core/GoogleSheet.type.js';
|
||||
// ---> Sheet
|
||||
export type { Sheet, SheetState } from './definitions/core/Sheet.type.js';
|
||||
|
||||
// SERVER RESPONSES
|
||||
export type { NetworkInterface, GetInfo } from './api/ontime-controller/BackendResponse.type.js';
|
||||
|
||||
Reference in New Issue
Block a user