Typing
All checks were successful
/ Misc Linters (pull_request) Successful in 21s
/ Build App (pull_request) Successful in 1m27s

This commit is contained in:
Valentin Brandl 2024-08-29 10:37:38 +02:00
parent b177a348b7
commit 15de87432b
2 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { safePath, timedExecution } from '$lib';
import safePath, { timedExecution } from '$lib';
import { describe, it, expect } from 'vitest';
describe('safe path', () => {
@ -32,8 +32,8 @@ describe('safe path', () => {
});
describe('timedExecution', () => {
const asyncIdentity = async (v) => v;
const identity = (v) => v;
const asyncIdentity = async <T>(v: T): Promise<T> => v;
const identity = <T>(v: T): T => v;
it('works with async', async () => {
const { executionTime, result } = await timedExecution(() => asyncIdentity(5));

View File

@ -8,7 +8,7 @@ export const log = bunyan.createLogger({
src: true,
});
function safePath(basePath: string, name: string): boolean {
const safePath = (basePath: string, name: string): boolean => {
const fullPath = `${basePath}/${name}`;
const relative = path.relative(basePath, fullPath);
return (
@ -20,7 +20,9 @@ function safePath(basePath: string, name: string): boolean {
// result is not an absolute path
!path.isAbsolute(relative)
);
}
};
export default safePath;
const defaultPath: string = './uploads';
if (!('STORAGE_PATH' in process.env)) {
@ -30,8 +32,6 @@ export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath;
export const requestIdHeader = 'x-request-id';
export default safePath;
export type MaybePromise<T> = T | Promise<T>;
export async function timedExecution<T>(