Prevented unwanted files from being listed in file explorer.

This commit is contained in:
2025-10-23 22:34:56 +03:00
parent 8fc749b735
commit 0adb3240e1
2 changed files with 50 additions and 6 deletions

10
server/.ignoreFiles Normal file
View File

@@ -0,0 +1,10 @@
# Sistem dosyaları
.DS_Store
Thumbs.db
desktop.ini
# Uzantılar
nfo
srt
txt
vtt

View File

@@ -242,6 +242,36 @@ app.get("/media/:path(*)", requireAuth, (req, res) => {
// --- 📁 Dosya gezgini (🆕 type ve url alanları eklendi; resim thumb'ı) --- // --- 📁 Dosya gezgini (🆕 type ve url alanları eklendi; resim thumb'ı) ---
app.get("/api/files", requireAuth, (req, res) => { 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 ignoreListte 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) => { const walk = (dir) => {
let result = []; let result = [];
const list = fs.readdirSync(dir, { withFileTypes: true }); 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 full = path.join(dir, entry.name);
const rel = path.relative(DOWNLOAD_DIR, full); 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()) { if (entry.isDirectory()) {
result = result.concat(walk(full)); result = result.concat(walk(full));
} else { } else {
@@ -258,17 +291,18 @@ app.get("/api/files", requireAuth, (req, res) => {
const size = fs.statSync(full).size; const size = fs.statSync(full).size;
const type = mime.lookup(full) || "application/octet-stream"; 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 parts = rel.split(path.sep);
const rootHash = parts[0]; 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); const hasVideoThumb = fs.existsSync(videoThumbPath);
// URL (segment bazlı encode → / işaretlerini koru)
const urlPath = encodeURIComponent(rel).replace(/%2F/g, "/"); const urlPath = encodeURIComponent(rel).replace(/%2F/g, "/");
const url = `/media/${urlPath}`; const url = `/media/${urlPath}`;
// Resimler için küçük önizleme: kendi dosyasını thumbnail yap
const isImage = String(type).startsWith("image/"); const isImage = String(type).startsWith("image/");
const isVideo = String(type).startsWith("video/"); const isVideo = String(type).startsWith("video/");
const thumb = isImage const thumb = isImage
@@ -280,8 +314,8 @@ app.get("/api/files", requireAuth, (req, res) => {
result.push({ result.push({
name: rel, name: rel,
size, size,
type, // 🆕 "image/jpeg", "video/mp4", vs. type,
url, // 🆕 doğrudan görüntüleme/oynatma için url,
thumbnail: thumb thumbnail: thumb
}); });
} }