mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 08:23:55 +00:00
23a44b2f04
* refactor: replace traslation hook refetch time with stale time * refactor: make it the service responsebillety to send refetch keys for asset changes
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { existsSync } from 'node:fs';
|
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
|
|
import { RefetchKey, type TranslationObject } from 'ontime-types';
|
|
|
|
import { sendRefetch } from '../../adapters/WebsocketAdapter.js';
|
|
import { defaultCss } from '../../bundle/bundledCss.js';
|
|
import { publicFiles } from '../../setup/index.js';
|
|
|
|
/**
|
|
* Reads the user's css file
|
|
* @returns css contents in the file
|
|
*/
|
|
export async function readCssFile(): Promise<string> {
|
|
const path = publicFiles.cssOverride;
|
|
if (!existsSync(path)) {
|
|
await writeFile(path, defaultCss, { encoding: 'utf8' });
|
|
}
|
|
|
|
const css = await readFile(path, { encoding: 'utf8' });
|
|
|
|
return css;
|
|
}
|
|
|
|
/**
|
|
* Writes the user's css file
|
|
* @param css the updated css to write to file
|
|
*/
|
|
export async function writeCssFile(css: string) {
|
|
const path = publicFiles.cssOverride;
|
|
if (!existsSync(path)) {
|
|
await writeFile(path, css, { encoding: 'utf8' });
|
|
return;
|
|
}
|
|
|
|
await writeFile(path, css, { encoding: 'utf8' });
|
|
setImmediate(() => {
|
|
sendRefetch(RefetchKey.CssOverride);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Writes the user's custom translation file
|
|
* @param translations the updated translations to write to file
|
|
*/
|
|
export async function writeUserTranslation(translations: TranslationObject) {
|
|
const path = publicFiles.translationsFile;
|
|
const translationsString = JSON.stringify(translations, null, 2);
|
|
await writeFile(path, translationsString, { encoding: 'utf8' });
|
|
setImmediate(() => {
|
|
sendRefetch(RefetchKey.Translation);
|
|
});
|
|
}
|