feat(rclone): GDrive dosya silme desteği ekle
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.
This commit is contained in:
@@ -7767,10 +7767,49 @@ app.delete("/api/file", requireAuth, (req, res) => {
|
|||||||
if (!filePath) return res.status(400).json({ error: "path gerekli" });
|
if (!filePath) return res.status(400).json({ error: "path gerekli" });
|
||||||
|
|
||||||
const safePath = sanitizeRelative(filePath);
|
const safePath = sanitizeRelative(filePath);
|
||||||
const fullPath = path.join(DOWNLOAD_DIR, safePath);
|
|
||||||
|
// 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 folderId = (safePath.split(/[\/]/)[0] || "").trim();
|
||||||
let rootDir = folderId ? path.join(DOWNLOAD_DIR, folderId) : null;
|
let rootDir = null;
|
||||||
let folderIsDirectory = false;
|
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)) {
|
if (rootDir && fs.existsSync(rootDir)) {
|
||||||
try {
|
try {
|
||||||
folderIsDirectory = fs.statSync(rootDir).isDirectory();
|
folderIsDirectory = fs.statSync(rootDir).isDirectory();
|
||||||
@@ -7778,6 +7817,8 @@ app.delete("/api/file", requireAuth, (req, res) => {
|
|||||||
folderIsDirectory = false;
|
folderIsDirectory = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Kök dosyalarda ilk segment dosya adıdır; klasör değilse root davranışı uygula
|
// Kök dosyalarda ilk segment dosya adıdır; klasör değilse root davranışı uygula
|
||||||
if (folderId && !folderIsDirectory) {
|
if (folderId && !folderIsDirectory) {
|
||||||
folderId = "";
|
folderId = "";
|
||||||
@@ -7806,6 +7847,31 @@ app.delete("/api/file", requireAuth, (req, res) => {
|
|||||||
const isDirectory = stats.isDirectory();
|
const isDirectory = stats.isDirectory();
|
||||||
const relWithinRoot = safePath.split(/[\\/]/).slice(1).join("/");
|
const relWithinRoot = safePath.split(/[\\/]/).slice(1).join("/");
|
||||||
let trashEntry = null;
|
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) {
|
if (folderId && folderIsDirectory && rootDir) {
|
||||||
const infoBeforeDelete = readInfoForRoot(folderId);
|
const infoBeforeDelete = readInfoForRoot(folderId);
|
||||||
mediaFlags = detectMediaFlagsForPath(
|
mediaFlags = detectMediaFlagsForPath(
|
||||||
|
|||||||
Reference in New Issue
Block a user