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 973B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var fs = require("fs");
  2. var pathlib = require("path");
  3. var web = require("webstuff");
  4. var play = require("./js/play");
  5. var fsutil = require("./js/fsutil");
  6. var conf = JSON.parse(fs.readFileSync("conf.json"));
  7. var app = web();
  8. play.init(app, conf);
  9. app.express.use((req, res, next) => {
  10. if (req.url === "/" && play.isPlaying())
  11. res.redirect(play.httpPath);
  12. else
  13. next();
  14. });
  15. app.static("web");
  16. app.post("/play/url", (req, res) => {
  17. req.parseBody((err, fields) => {
  18. if (!fields.url)
  19. return res.redirect("/");
  20. function cb(err) {
  21. if (err) {
  22. console.log(err);
  23. res.redirect("/");
  24. } else {
  25. res.redirect(play.httpPath);
  26. }
  27. }
  28. if (fields.url.indexOf("magnet:") === 0) {
  29. play.playTorrent(fields.url, cb);
  30. } else if (fields.url.indexOf("/torrent") !== -1) {
  31. play.playTorrentPage(fields.url, cb);
  32. } else {
  33. return res.redirect("/");
  34. }
  35. });
  36. });
  37. app.get("/additional-links", (req, res) => {
  38. res.json(conf.additional_links);
  39. });