Samples work in ui now

This commit is contained in:
Jaret Burkett
2025-02-21 20:28:52 -07:00
parent 2b6e66e0cb
commit 710c6de1c9
24 changed files with 408 additions and 68 deletions

View File

@@ -2,23 +2,25 @@
import { NextRequest, NextResponse } from 'next/server';
import fs from 'fs';
import path from 'path';
import { getDatasetsRoot } from '@/app/api/datasets/utils';
import { getDatasetsRoot, getTrainingFolder } from '@/server/settings';
export async function GET(request: NextRequest, { params }: { params: { imagePath: string } }) {
const { imagePath } = await params;
try {
// Decode the path
const filepath = decodeURIComponent(imagePath);
console.log('Serving image:', filepath);
// Get allowed directories
const allowedDir = await getDatasetsRoot();
const datasetRoot = await getDatasetsRoot();
const trainingRoot = await getTrainingFolder();
const allowedDirs = [datasetRoot, trainingRoot];
// Security check: Ensure path is in allowed directory
const isAllowed = filepath.startsWith(allowedDir) && !filepath.includes('..');
const isAllowed = allowedDirs.some(allowedDir => filepath.startsWith(allowedDir)) && !filepath.includes('..');
if (!isAllowed) {
console.warn(`Access denied: ${filepath} not in ${allowedDir}`);
console.warn(`Access denied: ${filepath} not in ${allowedDirs.join(', ')}`);
return new NextResponse('Access denied', { status: 403 });
}