Endpoint for name autocomplete
Some checks failed
/ Build App (push) Failing after 2s

This commit is contained in:
Valentin Brandl 2024-07-30 08:38:58 +02:00
parent e93d7a5652
commit ff9c0a6941
Signed by: vbrandl
GPG Key ID: CAD4DA1A789125F9
3 changed files with 13 additions and 3 deletions

View File

@ -1,5 +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.
const safePath = (input: string) => input.replace(/\W/g, ''); const safePath = (input: string) => input.replace(/\W/g, '');
export const storagePath: string = './uploads';
export default safePath; export default safePath;

View File

@ -1,12 +1,10 @@
import { writeFileSync, mkdirSync, existsSync } from 'fs'; import { writeFileSync, mkdirSync, existsSync } from 'fs';
import { fail } from '@sveltejs/kit'; import { fail } from '@sveltejs/kit';
import type { RequestEvent } from './$types'; import type { RequestEvent } from './$types';
import safePath from '$lib'; import safePath, { storagePath } from '$lib';
import { hash } from 'crypto'; import { hash } from 'crypto';
import path from 'path'; import path from 'path';
const storagePath: string = './uploads';
const mkdirIfNotExists = (path: string) => { const mkdirIfNotExists = (path: string) => {
if (!existsSync(path)) { if (!existsSync(path)) {
mkdirSync(path); mkdirSync(path);

View File

@ -0,0 +1,11 @@
import { storagePath } from '$lib';
import { json } from '@sveltejs/kit';
import { readdirSync, statSync } from 'fs';
export function GET() {
const names = readdirSync(storagePath).filter((f) =>
statSync(`${storagePath}/${f}`).isDirectory()
);
return json(names);
}