From 2b5bb86b3e83e51da847c5f37aae4a78c8ef35c9 Mon Sep 17 00:00:00 2001 From: wisecolt Date: Mon, 2 Feb 2026 22:30:38 +0300 Subject: [PATCH] =?UTF-8?q?feat(rclone):=20GDrive=20dosya=20silme=20deste?= =?UTF-8?q?=C4=9Fi=20ekle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Silme API'si artık dosyaların konumunu otomatik olarak tespit edebiliyor (DOWNLOAD_DIR veya GDRIVE_ROOT). GDrive dosyaları için doğrudan silme mantığı uygulanırken, Downloads dosyaları için mevcut trash sistemi korunuyor. --- server/server.js | 84 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/server/server.js b/server/server.js index 194e4e1..0d96f83 100644 --- a/server/server.js +++ b/server/server.js @@ -7767,17 +7767,58 @@ app.delete("/api/file", requireAuth, (req, res) => { if (!filePath) return res.status(400).json({ error: "path gerekli" }); const safePath = sanitizeRelative(filePath); - const fullPath = path.join(DOWNLOAD_DIR, safePath); - let folderId = (safePath.split(/[\/]/)[0] || "").trim(); - let rootDir = folderId ? path.join(DOWNLOAD_DIR, folderId) : null; - let folderIsDirectory = false; - if (rootDir && fs.existsSync(rootDir)) { - try { - folderIsDirectory = fs.statSync(rootDir).isDirectory(); - } catch (err) { - folderIsDirectory = false; + + // Dosyanın nerede olduğunu bul (DOWNLOAD_DIR veya GDRIVE_ROOT) + let fullPath = null; + let storageBase = null; // Dosyanın bulunduğu storage base (DOWNLOAD_DIR veya GDRIVE_ROOT) + + for (const baseDir of getStorageRoots()) { + const testPath = path.join(baseDir, safePath); + if (fs.existsSync(testPath)) { + fullPath = testPath; + storageBase = baseDir; + break; } } + + // Dosya bulunamadı + if (!fullPath) { + return res.status(404).json({ error: "Dosya bulunamadı" }); + } + + let folderId = (safePath.split(/[\/]/)[0] || "").trim(); + let rootDir = null; + let folderIsDirectory = false; + + // GDrive'da ise special handling - GDrive'ın kendisi root olarak kabul edilir + const isGDriveFile = storageBase === GDRIVE_ROOT; + + if (isGDriveFile) { + // GDrive'da klasör yapısı farklıdır + // folderId varsa ve GDRIVE_ROOT/folderId bir klasörse + const testRootDir = path.join(GDRIVE_ROOT, folderId); + if (folderId && fs.existsSync(testRootDir)) { + try { + folderIsDirectory = fs.statSync(testRootDir).isDirectory(); + if (folderIsDirectory) { + rootDir = GDRIVE_ROOT; // GDrive root'u + } + } catch (err) { + folderIsDirectory = false; + } + } + } else { + // Downloads klasörü için normal mantık + rootDir = folderId ? path.join(DOWNLOAD_DIR, folderId) : null; + if (rootDir && fs.existsSync(rootDir)) { + try { + folderIsDirectory = fs.statSync(rootDir).isDirectory(); + } catch (err) { + folderIsDirectory = false; + } + } + } + // Kök dosyalarda ilk segment dosya adıdır; klasör değilse root davranışı uygula if (folderId && !folderIsDirectory) { folderId = ""; @@ -7806,6 +7847,31 @@ app.delete("/api/file", requireAuth, (req, res) => { const isDirectory = stats.isDirectory(); const relWithinRoot = safePath.split(/[\\/]/).slice(1).join("/"); let trashEntry = null; + + // GDrive dosyaları için özel handling - doğrudan sil + const isGDriveFile = storageBase === GDRIVE_ROOT; + + if (isGDriveFile) { + // GDrive dosyaları için doğrudan silme (trash sistemi yok) + try { + if (isDirectory) { + fs.rmSync(fullPath, { recursive: true, force: true }); + console.log(`🗑️ GDrive klasör silindi: ${safePath}`); + } else { + fs.unlinkSync(fullPath); + console.log(`🗑️ GDrive dosya silindi: ${safePath}`); + } + removeThumbnailsForPath(safePath); + broadcastFileUpdate("gdrive"); + broadcastDiskSpace(); + return res.json({ ok: true, filesRemoved: true, deletedFrom: "gdrive" }); + } catch (deleteErr) { + console.error(`❌ GDrive dosya silme hatası: ${deleteErr.message}`); + return res.status(500).json({ error: `Silme hatası: ${deleteErr.message}` }); + } + } + + // Downloads klasörü için normal trash sistemi if (folderId && folderIsDirectory && rootDir) { const infoBeforeDelete = readInfoForRoot(folderId); mediaFlags = detectMediaFlagsForPath(