You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.js 755B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var fs = require("fs");
  2. var web = require("webstuff");
  3. var play = require("./js/play");
  4. var conf = JSON.parse(fs.readFileSync("conf.json"));
  5. var app = web();
  6. play.init(app, conf);
  7. app.express.use((req, res, next) => {
  8. if (req.url === "/" && play.isPlaying())
  9. res.redirect(play.httpPath);
  10. else
  11. next();
  12. });
  13. app.static("web");
  14. app.post("/play/url", (req, res) => {
  15. req.parseBody((err, fields) => {
  16. if (!fields.url)
  17. return res.redirect("/");
  18. play.playUrl(fields.url, () => {
  19. res.redirect(play.httpPath);
  20. });
  21. });
  22. });
  23. app.post("/play/magnet", (req, res) => {
  24. req.parseBody((err, fields) => {
  25. if (!fields.magnet)
  26. return res.redirect("/");
  27. play.playTorrent(fields.magnet, () => {
  28. res.redirect(play.httpPath);
  29. });
  30. });
  31. });