mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Cleanup and fix Unicode characters.
This commit is contained in:
parent
f18f87c736
commit
9e89d13518
1 changed files with 20 additions and 24 deletions
|
@ -4,6 +4,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.localization.Localization;
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
import io.netty.handler.codec.http.QueryStringDecoder;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.DownloaderImpl;
|
import me.kavin.piped.utils.DownloaderImpl;
|
||||||
|
@ -11,7 +12,9 @@ import me.kavin.piped.utils.ResponseHelper;
|
||||||
import me.kavin.piped.utils.SponsorBlockUtils;
|
import me.kavin.piped.utils.SponsorBlockUtils;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.netty.ByteBufFlux;
|
import reactor.netty.ByteBufFlux;
|
||||||
|
import reactor.netty.NettyOutbound;
|
||||||
import reactor.netty.http.server.HttpServer;
|
import reactor.netty.http.server.HttpServer;
|
||||||
|
import reactor.netty.http.server.HttpServerResponse;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
@ -39,8 +42,7 @@ public class Main {
|
||||||
.send(ByteBufFlux.fromString(Flux.just(query.parameters().get("hub.challenge").get(0))));
|
.send(ByteBufFlux.fromString(Flux.just(query.parameters().get("hub.challenge").get(0))));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.compression(true).status(500).addHeader("Cache-Control", "private")
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
.send(ByteBufFlux.fromString(Flux.just(ExceptionUtils.getStackTrace(e))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -53,8 +55,7 @@ public class Main {
|
||||||
.send(ByteBufFlux.fromString(Flux.just("ok")));
|
.send(ByteBufFlux.fromString(Flux.just("ok")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.compression(true).status(500).addHeader("Cache-Control", "private")
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
.send(ByteBufFlux.fromString(Flux.just(ExceptionUtils.getStackTrace(e))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -64,14 +65,11 @@ public class Main {
|
||||||
QueryStringDecoder query = new QueryStringDecoder(req.uri());
|
QueryStringDecoder query = new QueryStringDecoder(req.uri());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return res.compression(true).addHeader("Access-Control-Allow-Origin", "*")
|
return writeResponse(res, SponsorBlockUtils.getSponsors(req.param("videoId"),
|
||||||
.addHeader("Cache-Control", "public, s-maxage=3600")
|
query.parameters().get("category").get(0)), 200, "public, max-age=3600");
|
||||||
.send(ByteBufFlux.fromString(Flux.just(SponsorBlockUtils.getSponsors(req.param("videoId"),
|
|
||||||
query.parameters().get("category").get(0)))));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.compression(true).status(500).addHeader("Cache-Control", "private")
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
.send(ByteBufFlux.fromString(Flux.just(ExceptionUtils.getStackTrace(e))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -85,8 +83,7 @@ public class Main {
|
||||||
.fromString(Flux.just(ResponseHelper.streamsResponse(req.param("videoId")))));
|
.fromString(Flux.just(ResponseHelper.streamsResponse(req.param("videoId")))));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.compression(true).status(500).addHeader("Cache-Control", "private")
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
.send(ByteBufFlux.fromString(Flux.just(ExceptionUtils.getStackTrace(e))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -94,14 +91,11 @@ public class Main {
|
||||||
routes.get("/channels/{channelId}", (req, res) -> {
|
routes.get("/channels/{channelId}", (req, res) -> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// The stream links are valid for 6 hours.
|
return writeResponse(res, ResponseHelper.channelResponse(req.param("channelId")), 200,
|
||||||
return res.compression(true).addHeader("Access-Control-Allow-Origin", "*")
|
"public, max-age=600");
|
||||||
.addHeader("Cache-Control", "public, s-maxage=21540").send(ByteBufFlux
|
|
||||||
.fromString(Flux.just(ResponseHelper.channelResponse(req.param("channelId")))));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.compression(true).status(500).addHeader("Cache-Control", "private")
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
.send(ByteBufFlux.fromString(Flux.just(ExceptionUtils.getStackTrace(e))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -109,14 +103,10 @@ public class Main {
|
||||||
routes.get("/trending", (req, res) -> {
|
routes.get("/trending", (req, res) -> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// The stream links are valid for 6 hours.
|
return writeResponse(res, ResponseHelper.trendingResponse(), 200, "public, max-age=3600");
|
||||||
return res.compression(true).addHeader("Access-Control-Allow-Origin", "*")
|
|
||||||
.addHeader("Cache-Control", "public, s-maxage=3600")
|
|
||||||
.send(ByteBufFlux.fromString(Flux.just(ResponseHelper.trendingResponse())));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.compression(true).status(500).addHeader("Cache-Control", "private")
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
.send(ByteBufFlux.fromString(Flux.just(ExceptionUtils.getStackTrace(e))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -125,4 +115,10 @@ public class Main {
|
||||||
|
|
||||||
Thread.sleep(Long.MAX_VALUE);
|
Thread.sleep(Long.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NettyOutbound writeResponse(HttpServerResponse res, String resp, int code, String cache) {
|
||||||
|
return res.compression(true).addHeader("Access-Control-Allow-Origin", "*").addHeader("Cache-Control", cache)
|
||||||
|
.send(ByteBufFlux.fromString(Flux.just(resp), java.nio.charset.StandardCharsets.UTF_8,
|
||||||
|
ByteBufAllocator.DEFAULT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue