* feat: support hono rpc * add wrangler file * update name of wrangler file * add wrangler as a dependency * add compatibility_flags * trigger ci * core: add health check to docker file * expose port 80 * update custom healthcheck * feat: implement openapi * install dependencies in root * debug yml * update yml * update port * update dockerfile with envs * completely move away from apiClient * rename backend to api * refactor: update server descriptions and comment out local spec saving * update lock file * use api.classroomio.com * add support for redis * fix: add missing line break in WelcomeModal.svelte * refactor: remove wrangler configuration and update Vite config for API integration
25 lines
763 B
TypeScript
25 lines
763 B
TypeScript
import { nanoid } from 'nanoid';
|
|
import path from 'path';
|
|
|
|
/**
|
|
* Safely extracts the file extension from a filename.
|
|
* Returns an empty string if no extension is found.
|
|
*/
|
|
export function getExtension(filename: string): string {
|
|
if (!filename || typeof filename !== 'string') return '';
|
|
const ext = path.extname(filename).split('.');
|
|
return ext.length > 1 ? ext[ext.length - 1] : '';
|
|
}
|
|
|
|
/**
|
|
* Generates a unique file key for storage, preserving the file extension.
|
|
* Throws an error if the filename is invalid or has no extension.
|
|
*/
|
|
export function generateFileKey(fileName: string): string {
|
|
const ext = getExtension(fileName);
|
|
if (!ext) {
|
|
throw new Error('Invalid file name or missing file extension');
|
|
}
|
|
return `${nanoid()}.${ext}`;
|
|
}
|