Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .nixpacks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[phases.setup]
nixPkgs = ["nodejs"]

[phases.install]
cmds = ["npm install"]
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: yarn start
web: npm start
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.4.1",
"express": "^4.18.2"
"express": "^4.18.2",
"axios": "^1.6.7"
},
"devDependencies": {
"@types/cors": "^2.8.17",
Expand All @@ -23,3 +24,4 @@
"typescript": "^5.3.3"
}
}

63 changes: 53 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
import { config } from 'dotenv';
import express, { Request, Response } from "express";
import axios from "axios";

if (process.env.NODE_ENV !== 'production') {
config();
}
// call after config() to access the env variables
import { app } from './api';
const app = express();
const port = process.env.PORT || 3000;

const port = process.env.PORT || 3333;
// Rota de teste
app.get("/", (req: Request, res: Response) => {
res.json({ status: "ok" });
return;
});

// Rota para baixar vídeo do Panda Video
app.get("/baixar-video/:videoId", async (req: Request, res: Response) => {
const { videoId } = req.params;
const pandaUrl = `https://download-us02.pandavideo.com:7443/videos/${videoId}/download`;

console.log(`🔍 Baixando vídeo: ${videoId}`);
console.log(`🌍 URL gerada: ${pandaUrl}`);

try {
const response = await axios.get(pandaUrl, {
responseType: "stream",
headers: {
Authorization: "Bearer ",
},
});

console.log("✅ Resposta recebida do Panda Video");

res.setHeader("Content-Disposition", `attachment; filename="${videoId}.mp4"`);
res.setHeader("Content-Type", "video/mp4");

response.data.pipe(res);
return;
} catch (error: any) {
console.error("❌ Erro ao baixar o vídeo:", error.message);

res.status(500).json({
error: "Erro ao baixar o vídeo",
details: error.message,
});
return;
}
});

// Iniciar o servidor
app.listen(port, () => {
console.log(`🚀 Servidor rodando na porta ${port}`);
});


app.listen(port, () => {
console.log(`🚀 Servidor rodando na porta ${port}`);
});

app.listen(port, () =>
console.log(`API available on http://localhost:${port}`)
);
Loading