Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import { readdir } from "node:fs/promises"; import { join } from "node:path"; const FILES_DIR = "./files"; Bun.serve({ port: 3006, async fetch(req) { const url = new URL(req.url); // Kui küsitakse juurkausta, näita failide loetelu if (url.pathname === "/") { try { const files = await readdir(FILES_DIR); let html = `
Failiserver
📁 Failid
`; if (files.length === 0) { html += "
Kausta ei ole ühtegi faili
"; } else { for (const file of files) { html += `
📄
${file}
`; } } html += `
`; return new Response(html, { headers: { "Content-Type": "text/html; charset=utf-8" } }); } catch (error) { return new Response("Viga failide lugemisel", { status: 500 }); } } // Kui küsitakse faili allalaadimist if (url.pathname.startsWith("/download/")) { const filename = decodeURIComponent(url.pathname.slice(10)); const filepath = join(FILES_DIR, filename); try { const file = Bun.file(filepath); const exists = await file.exists(); if (!exists) { return new Response("Faili ei leitud", { status: 404 }); } return new Response(file, { headers: { "Content-Disposition": `attachment; filename="${filename}"`, } }); } catch (error) { return new Response("Viga faili lugemisel", { status: 500 }); } } return new Response("Lehte ei leitud", { status: 404 }); }, }); console.log("Failiserver töötab aadressil http://localhost:3006");
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)