Disk Space alanı eklendi.
This commit is contained in:
@@ -9,6 +9,7 @@ import { WebSocketServer } from "ws";
|
||||
import { fileURLToPath } from "url";
|
||||
import { exec } from "child_process";
|
||||
import crypto from "crypto"; // 🔒 basit token üretimi için
|
||||
import { getSystemDiskInfo } from "./utils/diskSpace.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -2082,6 +2083,20 @@ function broadcastFileUpdate(rootFolder) {
|
||||
wss.clients.forEach((c) => c.readyState === 1 && c.send(data));
|
||||
}
|
||||
|
||||
function broadcastDiskSpace() {
|
||||
if (!wss) return;
|
||||
getSystemDiskInfo(DOWNLOAD_DIR).then(diskInfo => {
|
||||
console.log("🔄 Broadcasting disk space:", diskInfo);
|
||||
const data = JSON.stringify({
|
||||
type: "diskSpace",
|
||||
data: diskInfo
|
||||
});
|
||||
wss.clients.forEach((c) => c.readyState === 1 && c.send(data));
|
||||
}).catch(err => {
|
||||
console.error("❌ Disk space broadcast error:", err.message);
|
||||
});
|
||||
}
|
||||
|
||||
function broadcastSnapshot() {
|
||||
if (!wss) return;
|
||||
const data = JSON.stringify({ type: "progress", torrents: snapshot() });
|
||||
@@ -2342,6 +2357,9 @@ app.post("/api/transfer", requireAuth, upload.single("torrent"), (req, res) => {
|
||||
|
||||
upsertInfoFile(entry.savePath, infoUpdate);
|
||||
broadcastFileUpdate(rootFolder);
|
||||
|
||||
// Torrent tamamlandığında disk space bilgisini güncelle
|
||||
broadcastDiskSpace();
|
||||
|
||||
broadcastSnapshot();
|
||||
});
|
||||
@@ -2755,6 +2773,9 @@ app.delete("/api/file", requireAuth, (req, res) => {
|
||||
torrents.delete(matchedInfoHash);
|
||||
console.log(`🧹 Torrent kaydı da temizlendi: ${matchedInfoHash}`);
|
||||
broadcastSnapshot();
|
||||
|
||||
// Torrent silindiğinde disk space bilgisini güncelle
|
||||
broadcastDiskSpace();
|
||||
});
|
||||
} else {
|
||||
broadcastSnapshot();
|
||||
@@ -3501,7 +3522,18 @@ const server = app.listen(PORT, () =>
|
||||
|
||||
wss = new WebSocketServer({ server });
|
||||
wss.on("connection", (ws) => {
|
||||
console.log("🔌 New WebSocket connection established");
|
||||
ws.send(JSON.stringify({ type: "progress", torrents: snapshot() }));
|
||||
// Bağlantı kurulduğunda disk space bilgisi gönder
|
||||
broadcastDiskSpace();
|
||||
|
||||
ws.on("close", () => {
|
||||
console.log("🔌 WebSocket connection closed");
|
||||
});
|
||||
|
||||
ws.on("error", (error) => {
|
||||
console.error("🔌 WebSocket error:", error);
|
||||
});
|
||||
});
|
||||
|
||||
// --- ⏱️ Her 2 saniyede bir aktif torrent durumu yayınla ---
|
||||
@@ -3511,6 +3543,27 @@ setInterval(() => {
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
// --- ⏱️ Her 30 saniyede bir disk space bilgisi yayınla ---
|
||||
setInterval(() => {
|
||||
broadcastDiskSpace();
|
||||
}, 30000);
|
||||
|
||||
// --- Disk space bilgisi ---
|
||||
app.get("/api/disk-space", requireAuth, async (req, res) => {
|
||||
try {
|
||||
// Downloads klasörü yoksa oluştur
|
||||
if (!fs.existsSync(DOWNLOAD_DIR)) {
|
||||
fs.mkdirSync(DOWNLOAD_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
const diskInfo = await getSystemDiskInfo(DOWNLOAD_DIR);
|
||||
res.json(diskInfo);
|
||||
} catch (err) {
|
||||
console.error("❌ Disk space error:", err.message);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
client.on("error", (err) => {
|
||||
if (!String(err).includes("uTP"))
|
||||
console.error("WebTorrent error:", err.message);
|
||||
|
||||
Reference in New Issue
Block a user