fix: new installs broken due to bizarre dependency refresh

Added an `onStart` to data since I believe that's what was crashing it.
pull/197/head
tycrek 2 years ago
parent d91e572e82
commit 332207829c
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

@ -45,7 +45,7 @@ const ROUTERS = {
// Read users and data
import { onStart as AuthOnStart, users } from './auth';
import { data } from './data';
import { onStart as DataOnStart, data } from './data';
//#endregion
// Create thumbnails directory
@ -133,6 +133,7 @@ app.use((err: ErrWrap, _req: Request, res: Response) => log.error(err.message).e
(async function start() {
await AuthOnStart();
await DataOnStart();
if (data() == null) setTimeout(start, 100);
else log

@ -8,11 +8,18 @@ import { JsonDataEngine } from '@tycrek/papito'
let theData: any;
// Actual data engine
const { dataEngine }: Config = fs.readJsonSync('config.json');
import(dataEngine)
.then(({ _ENGINE_ }) => theData = _ENGINE_(new JsonDataEngine()))
.catch(err => console.error(err));
/**
* Called by ass.ts on startup
* @since v0.14.2
*/
export const onStart = () => new Promise((resolve, reject) => {
// Actual data engine
const { dataEngine }: Config = fs.readJsonSync('config.json');
import(dataEngine)
.then(({ _ENGINE_ }) => theData = _ENGINE_(new JsonDataEngine()))
.then(resolve)
.catch(reject);
});
// Export a self-calling const function returning the data
export const data = ((): any => theData);

@ -50,7 +50,7 @@ router.use('/', (err: ErrWrap, _req: Request, res: Response, next: Function) =>
// Process uploaded file
router.post('/', (req: Request, res: Response, next: Function) => {
// Load overrides
const trueDomain = getTrueDomain(req.headers['x-ass-domain']);
const trueDomain = getTrueDomain(req.headers['x-ass-domain']?.toString() ?? undefined);
const generator = req.headers['x-ass-access']?.toString() || resourceIdType;
// Save domain with file

@ -1,3 +1,4 @@
import { Config } from 'ass-json';
import { FileData } from './types/definitions';
import fs from 'fs-extra';
import Path from 'path';
@ -16,7 +17,9 @@ const { HTTP, HTTPS, KILOBYTES } = require('../MagicNumbers.json');
// Catch config.json not existing when running setup script
try {
// todo: fix this
var { useSsl, port, domain, isProxied, diskFilePath, s3bucket, s3endpoint, s3usePathStyle } = require('../config.json'); // skipcq: JS-0239, JS-0102
const configPath = Path.join(process.cwd(), 'config.json');
if (!fs.existsSync(configPath)) throw new Error('Config file not found');
var { useSsl, port, domain, isProxied, diskFilePath, s3bucket, s3endpoint, s3usePathStyle }: Config = fs.readJsonSync(configPath);
} catch (ex) {
// @ts-ignore
if (ex.code !== 'MODULE_NOT_FOUND' || !ex.toString().includes('Unexpected end')) console.error(ex);

Loading…
Cancel
Save