Spaces:
Running
Running
| import express from "express"; | |
| import multer from "multer"; | |
| import fs from "fs"; | |
| import { uploadToHF } from "./upload"; | |
| const app = express(); | |
| const upload = multer({ dest: "tmp/" }); | |
| app.post("/api/upload", upload.single("file"), async (req, res) => { | |
| try { | |
| if (!req.file) return res.status(400).json({ error: "No file" }); | |
| const url = await uploadToHF( | |
| req.file.path, | |
| req.file.originalname | |
| ); | |
| fs.unlinkSync(req.file.path); | |
| res.json({ url }); | |
| } catch (e: any) { | |
| res.status(500).json({ error: e.message }); | |
| } | |
| }); | |
| app.listen(3000, () => { | |
| console.log("Backend running :3000"); | |
| }); | |