From 0adb3240e1ce2fde6a077556160f4a772ca2d48e Mon Sep 17 00:00:00 2001 From: szbk Date: Thu, 23 Oct 2025 22:34:56 +0300 Subject: [PATCH] Prevented unwanted files from being listed in file explorer. --- server/.ignoreFiles | 10 ++++++++++ server/server.js | 46 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 server/.ignoreFiles diff --git a/server/.ignoreFiles b/server/.ignoreFiles new file mode 100644 index 0000000..d8b8431 --- /dev/null +++ b/server/.ignoreFiles @@ -0,0 +1,10 @@ +# Sistem dosyaları +.DS_Store +Thumbs.db +desktop.ini + +# Uzantılar +nfo +srt +txt +vtt diff --git a/server/server.js b/server/server.js index 3e6a284..9b4eff3 100644 --- a/server/server.js +++ b/server/server.js @@ -242,6 +242,36 @@ app.get("/media/:path(*)", requireAuth, (req, res) => { // --- 📁 Dosya gezgini (🆕 type ve url alanları eklendi; resim thumb'ı) --- app.get("/api/files", requireAuth, (req, res) => { + // --- 🧩 .ignoreFiles içeriğini oku --- + let ignoreList = []; + const ignorePath = path.join(__dirname, ".ignoreFiles"); + + if (fs.existsSync(ignorePath)) { + try { + const raw = fs.readFileSync(ignorePath, "utf-8"); + ignoreList = raw + .split("\n") + .map((l) => l.trim().toLowerCase()) + .filter((l) => l && !l.startsWith("#")); + } catch (err) { + console.warn("⚠️ .ignoreFiles okunamadı:", err.message); + } + } + + // --- 🔍 Yardımcı fonksiyon: dosya ignoreList’te mi? --- + const isIgnored = (name) => { + const lower = name.toLowerCase(); + const ext = path.extname(lower).replace(".", ""); + return ignoreList.some( + (ignored) => + lower === ignored || + lower.endsWith(ignored) || + lower.endsWith(`.${ignored}`) || + ext === ignored.replace(/^\./, "") + ); + }; + + // --- 📁 Klasörleri dolaş --- const walk = (dir) => { let result = []; const list = fs.readdirSync(dir, { withFileTypes: true }); @@ -250,6 +280,9 @@ app.get("/api/files", requireAuth, (req, res) => { const full = path.join(dir, entry.name); const rel = path.relative(DOWNLOAD_DIR, full); + // 🔥 Ignore kontrolü (hem dosya hem klasör için) + if (isIgnored(entry.name) || isIgnored(rel)) continue; + if (entry.isDirectory()) { result = result.concat(walk(full)); } else { @@ -258,17 +291,18 @@ app.get("/api/files", requireAuth, (req, res) => { const size = fs.statSync(full).size; const type = mime.lookup(full) || "application/octet-stream"; - // kök klasör (thumbnail varsa video kartlarında kullanıyoruz) const parts = rel.split(path.sep); const rootHash = parts[0]; - const videoThumbPath = path.join(DOWNLOAD_DIR, rootHash, "thumbnail.jpg"); + const videoThumbPath = path.join( + DOWNLOAD_DIR, + rootHash, + "thumbnail.jpg" + ); const hasVideoThumb = fs.existsSync(videoThumbPath); - // URL (segment bazlı encode → / işaretlerini koru) const urlPath = encodeURIComponent(rel).replace(/%2F/g, "/"); const url = `/media/${urlPath}`; - // Resimler için küçük önizleme: kendi dosyasını thumbnail yap const isImage = String(type).startsWith("image/"); const isVideo = String(type).startsWith("video/"); const thumb = isImage @@ -280,8 +314,8 @@ app.get("/api/files", requireAuth, (req, res) => { result.push({ name: rel, size, - type, // 🆕 "image/jpeg", "video/mp4", vs. - url, // 🆕 doğrudan görüntüleme/oynatma için + type, + url, thumbnail: thumb }); }