Compare commits

..

No commits in common. "main" and "v0.0.7" have entirely different histories.
main ... v0.0.7

6 changed files with 1320 additions and 841 deletions

2114
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "fotochallenge", "name": "fotochallenge",
"version": "0.0.8", "version": "0.0.7",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
@ -34,7 +34,7 @@
"sass": "^1.77.5", "sass": "^1.77.5",
"simple-svelte-autocomplete": "^2.5.2", "simple-svelte-autocomplete": "^2.5.2",
"svelte": "^4.2.7", "svelte": "^4.2.7",
"svelte-check": "^4.0.0", "svelte-check": "^3.6.0",
"tslib": "^2.4.1", "tslib": "^2.4.1",
"typescript": "^5.0.0", "typescript": "^5.0.0",
"typescript-eslint": "^8.0.0-alpha.20", "typescript-eslint": "^8.0.0-alpha.20",

View File

@ -1,12 +1,4 @@
{ {
$schema: 'https://docs.renovatebot.com/renovate-schema.json', $schema: 'https://docs.renovatebot.com/renovate-schema.json',
extends: ['local>renovate-bot/renovate-config'], extends: ['local>renovate-bot/renovate-config'],
packageRules: [
{
groupName: 'all non-major dependencies',
groupSlug: 'all-minor-patch',
matchPackageNames: ['*'],
matchUpdateTypes: ['minor', 'patch'],
},
],
} }

View File

@ -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( const { executionTime, result: response } = await timedExecution(async () => {
async () => await resolve(event) return await resolve(event);
); });
response.headers.set(requestIdHeader, requestId); response.headers.set(requestIdHeader, requestId);
log.info( log.info(

View File

@ -1,4 +1,4 @@
import safePath, { timedExecution } from '$lib'; import safePath from '$lib';
import { describe, it, expect } from 'vitest'; import { describe, it, expect } from 'vitest';
describe('safe path', () => { describe('safe path', () => {
@ -30,21 +30,3 @@ 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);
});
});

View File

@ -1,6 +1,7 @@
// 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',
@ -8,7 +9,7 @@ export const log = bunyan.createLogger({
src: true, src: true,
}); });
const safePath = (basePath: string, name: string): boolean => { function 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 (
@ -20,9 +21,7 @@ const 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)) {
@ -32,7 +31,7 @@ export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath;
export const requestIdHeader = 'x-request-id'; export const requestIdHeader = 'x-request-id';
export type MaybePromise<T> = T | Promise<T>; export default safePath;
export async function timedExecution<T>( export async function timedExecution<T>(
fn: () => MaybePromise<T> fn: () => MaybePromise<T>