Skip to content

Commit

Permalink
fix: new installs broken due to bizarre dependency refresh
Browse files Browse the repository at this point in the history
Added an `onStart` to data since I believe that's what was crashing it.
  • Loading branch information
tycrek committed Dec 26, 2022
1 parent d91e572 commit 3322078
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/ass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion src/routers/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Config } from 'ass-json';
import { FileData } from './types/definitions';
import fs from 'fs-extra';
import Path from 'path';
Expand All @@ -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);
Expand Down

0 comments on commit 3322078

Please sign in to comment.