BuildOurOwnBabylonJSController.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Web.Mvc;
  2. using System.IO;
  3. using System.Text;
  4. using System;
  5. namespace BuildOurOwnBabylonJSServer.Controllers
  6. {
  7. public class BuildOurOwnBabylonJSController : Controller
  8. {
  9. public const string GetFileContentActionName = "GetFileContent";
  10. [ActionName(BuildOurOwnBabylonJSController.GetFileContentActionName)]
  11. public ActionResult GetFileContent(string rootPath, string relPath)
  12. {
  13. var babylonJSPath = Path.Combine(Server.MapPath("~"), rootPath);
  14. var absPath = Path.Combine(babylonJSPath, relPath);
  15. var type = "";
  16. var extension = "";
  17. if (!String.IsNullOrEmpty(relPath))
  18. extension = Path.GetExtension(relPath).ToLower();
  19. switch (extension)
  20. {
  21. case ".js":
  22. case ".babylon":
  23. case ".manifest":
  24. type = "text/javascript";
  25. break;
  26. case ".png":
  27. type = "image/png";
  28. break;
  29. case ".jpeg":
  30. case ".jpg":
  31. type = "image/jpeg";
  32. break;
  33. case ".bmp":
  34. type = "image/bmp";
  35. break;
  36. default:
  37. type = "text/plain";
  38. break;
  39. }
  40. return File(new FileStream(absPath, FileMode.Open), type);
  41. }
  42. }
  43. }