FileBrowser
This commit is contained in:
@@ -30,6 +30,22 @@ router.get(
|
||||
})
|
||||
);
|
||||
|
||||
// GET /api/programs/:id/download — rohe .gcode-Datei als Download
|
||||
router.get(
|
||||
'/:id/download',
|
||||
asyncH(async (req, res) => {
|
||||
const id = req.params.id;
|
||||
const prog = await store.read(id); // wirft 404 wenn nicht vorhanden
|
||||
const filePath = store.gcodePath(id);
|
||||
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${id}.gcode"`);
|
||||
// sendFile braucht absoluten Pfad — wir haben ihn direkt aus dem Store
|
||||
const fsp = require('fs/promises');
|
||||
const body = await fsp.readFile(filePath, 'utf8');
|
||||
res.send(body);
|
||||
})
|
||||
);
|
||||
|
||||
// POST /api/programs (FSave) — aus aktivem Puffer ODER expliziter Inhalt.
|
||||
router.post(
|
||||
'/',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Express-App der appRobotFileservice. createApp() ist test-freundlich (kein listen).
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const programsRouter = require('./routes/programs');
|
||||
const activeRouter = require('./routes/active');
|
||||
@@ -25,6 +26,9 @@ function createApp() {
|
||||
app.use('/api/programs', programsRouter);
|
||||
app.use('/api/active', activeRouter);
|
||||
|
||||
// Web-UI: statische Dateien aus public/ (index.html, index.css)
|
||||
app.use(express.static(path.join(__dirname, '..', 'public')));
|
||||
|
||||
// Unbekannter Pfad → 404-Envelope
|
||||
app.use((req, res) => res.status(404).json(envelope('NOT_FOUND', 'unknown endpoint', req.path)));
|
||||
app.use(errorMiddleware);
|
||||
|
||||
Reference in New Issue
Block a user