34 lines
1.0 KiB
Java
34 lines
1.0 KiB
Java
package com.filejet.API;
|
|
// server logic
|
|
|
|
import com.filejet.API.routes.DownloadRoute;
|
|
import com.filejet.API.util.EnvLoader;
|
|
import io.javalin.Javalin;
|
|
|
|
|
|
public class Server {
|
|
public static void main(String[] args) {
|
|
Javalin app = Javalin.create(config -> {
|
|
config.staticFiles.add("/HTML/");
|
|
}).start(EnvLoader.getPort());
|
|
|
|
app.get("/api/download", DownloadRoute::handle); // for ?path=... downloads
|
|
app.get("/api/download/{file}", DownloadRoute::handle); // legacy/compat
|
|
app.get("/api/list-isos", DownloadRoute::list);
|
|
app.get("/api/view", DownloadRoute::view); // for file preview
|
|
|
|
// New endpoint for directory version/hash
|
|
app.get("/api/dir-version", DownloadRoute::dirVersion);
|
|
|
|
app.before("/api/*", ctx -> {
|
|
String ua = ctx.header("User-Agent");
|
|
if (ua == null || ua.toLowerCase().contains("bot")
|
|
|| ua.toLowerCase().contains("curl")
|
|
) {
|
|
ctx.status(403).result("Forbidden");
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|