mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 14:18:12 +02:00
formatted file
This commit is contained in:
@ -1,33 +1,34 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from "express";
|
||||||
import { join } from 'path';
|
import { join } from "path";
|
||||||
import { getProjectPath } from '../utils/paths.js';
|
import { getProjectPath } from "../utils/paths.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// Environment variables for paths (all relative to project root)
|
// Environment variables for paths (all relative to project root)
|
||||||
const DATA_DIR = process.env.DATA_DIR ? getProjectPath(process.env.DATA_DIR) : getProjectPath('data');
|
const DATA_DIR = process.env.DATA_DIR
|
||||||
|
? getProjectPath(process.env.DATA_DIR)
|
||||||
|
: getProjectPath("data");
|
||||||
|
|
||||||
const DATASETS = [
|
const DATASETS = ["comment_generation", "code_refinement"];
|
||||||
"comment_generation",
|
|
||||||
"code_refinement"
|
|
||||||
];
|
|
||||||
|
|
||||||
router.get('/download/:dataset', async (req, res) => {
|
router.get("/download/:dataset", async (req, res) => {
|
||||||
const { dataset } = req.params;
|
const { dataset } = req.params;
|
||||||
const withContext = req.query.withContext ? JSON.parse(req.query.withContext) : false;
|
const withContext = req.query.withContext
|
||||||
|
? JSON.parse(req.query.withContext)
|
||||||
|
: false;
|
||||||
|
|
||||||
if (!DATASETS.includes(dataset)) {
|
if (!DATASETS.includes(dataset)) {
|
||||||
return res.status(400).json({ error: 'Invalid dataset name' });
|
return res.status(400).json({ error: "Invalid dataset name" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileName = `${dataset}_${withContext ? 'with_context' : 'no_context'}.zip`;
|
const fileName = `${dataset}_${withContext ? "with_context" : "no_context"}.zip`;
|
||||||
const filePath = join(DATA_DIR, fileName);
|
const filePath = join(DATA_DIR, fileName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res.download(filePath);
|
res.download(filePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error serving file:', error);
|
console.error("Error serving file:", error);
|
||||||
res.status(500).json({ error: 'Error serving file' });
|
res.status(500).json({ error: "Error serving file" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user