File size: 630 Bytes
b911249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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");
});