chore(deps): update dependency @sveltejs/kit to v2.5.25 #68
6
package-lock.json
generated
6
package-lock.json
generated
@ -1108,9 +1108,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@sveltejs/kit": {
|
"node_modules/@sveltejs/kit": {
|
||||||
"version": "2.5.24",
|
"version": "2.5.25",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.24.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.25.tgz",
|
||||||
"integrity": "sha512-Nr2oxsCsDfEkdS/zzQQQbsPYTbu692Qs3/iE3L7VHzCVjG2+WujF9oMUozWI7GuX98KxYSoPMlAsfmDLSg44hQ==",
|
"integrity": "sha512-5hBSEN8XEjDZ5+2bHkFh8Z0QyOk0C187cyb12aANe1c8aeKbfu5ZD5XaC2vEH4h0alJFDXPdUkXQBmeeXeMr1A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -24,9 +24,9 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||||||
// make requestId available to handlers
|
// make requestId available to handlers
|
||||||
event.locals.requestId = requestId;
|
event.locals.requestId = requestId;
|
||||||
|
|
||||||
const { executionTime, result: response } = await timedExecution(async () => {
|
const { executionTime, result: response } = await timedExecution(
|
||||||
return await resolve(event);
|
async () => await resolve(event)
|
||||||
});
|
);
|
||||||
response.headers.set(requestIdHeader, requestId);
|
response.headers.set(requestIdHeader, requestId);
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import safePath from '$lib';
|
import safePath, { timedExecution } from '$lib';
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
|
|
||||||
describe('safe path', () => {
|
describe('safe path', () => {
|
||||||
@ -30,3 +30,21 @@ describe('safe path', () => {
|
|||||||
expect(safePath('./uplodas', '..foobar..')).toBe(true);
|
expect(safePath('./uplodas', '..foobar..')).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('timedExecution', () => {
|
||||||
|
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));
|
||||||
|
expect(result).toBe(5);
|
||||||
|
// execution time is always positive
|
||||||
|
expect(executionTime).toBeGreaterThanOrEqual(0);
|
||||||
|
});
|
||||||
|
it('works with sync', async () => {
|
||||||
|
const { executionTime, result } = await timedExecution(() => identity(5));
|
||||||
|
expect(result).toBe(5);
|
||||||
|
// execution time is always positive
|
||||||
|
expect(executionTime).toBeGreaterThanOrEqual(0);
|
||||||
|
});
|
||||||
|
});
|
@ -1,7 +1,6 @@
|
|||||||
// place files you want to import through the `$lib` alias in this folder.
|
// place files you want to import through the `$lib` alias in this folder.
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import bunyan from 'bunyan';
|
import bunyan from 'bunyan';
|
||||||
import type { MaybePromise } from '@sveltejs/kit';
|
|
||||||
|
|
||||||
export const log = bunyan.createLogger({
|
export const log = bunyan.createLogger({
|
||||||
name: 'fotochallenge',
|
name: 'fotochallenge',
|
||||||
@ -9,7 +8,7 @@ export const log = bunyan.createLogger({
|
|||||||
src: true,
|
src: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
function safePath(basePath: string, name: string): boolean {
|
const safePath = (basePath: string, name: string): boolean => {
|
||||||
const fullPath = `${basePath}/${name}`;
|
const fullPath = `${basePath}/${name}`;
|
||||||
const relative = path.relative(basePath, fullPath);
|
const relative = path.relative(basePath, fullPath);
|
||||||
return (
|
return (
|
||||||
@ -21,7 +20,9 @@ function safePath(basePath: string, name: string): boolean {
|
|||||||
// result is not an absolute path
|
// result is not an absolute path
|
||||||
!path.isAbsolute(relative)
|
!path.isAbsolute(relative)
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default safePath;
|
||||||
|
|
||||||
const defaultPath: string = './uploads';
|
const defaultPath: string = './uploads';
|
||||||
if (!('STORAGE_PATH' in process.env)) {
|
if (!('STORAGE_PATH' in process.env)) {
|
||||||
@ -31,7 +32,7 @@ export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath;
|
|||||||
|
|
||||||
export const requestIdHeader = 'x-request-id';
|
export const requestIdHeader = 'x-request-id';
|
||||||
|
|
||||||
export default safePath;
|
export type MaybePromise<T> = T | Promise<T>;
|
||||||
|
|
||||||
export async function timedExecution<T>(
|
export async function timedExecution<T>(
|
||||||
fn: () => MaybePromise<T>
|
fn: () => MaybePromise<T>
|
||||||
|
Reference in New Issue
Block a user