watch.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. var Watch = require('../models/Watch');
  2. var mongoose = require('mongoose');
  3. const bodyParser = require('body-parser');
  4. // Get Movie or Series
  5. exports.watchGet = function(req, res){
  6. Watch.findOne({ 'permalink': req.params.permalink }, function(err, w){
  7. if (!w) {
  8. return res.redirect('/404');
  9. }
  10. else{
  11. res.render('watch', {
  12. title: w.title,
  13. layout: w.layout,
  14. subtitle: w.subtitle,
  15. sinopse: w.sinopse,
  16. year: w.year,
  17. imgbg: w.imgbg,
  18. video: w.video,
  19. thumb480: w.thumb480,
  20. thumb130: w.thumb130,
  21. runtime: w.runtime,
  22. eps: w.eps
  23. });
  24. }
  25. });
  26. };
  27. // GET New Production
  28. exports.newWatchGet = function(req, res) {
  29. if (!req.user) {
  30. return res.redirect('/login');
  31. }
  32. res.render('novo', {
  33. title: 'Criar Nova Produção'
  34. });
  35. };
  36. // POST New Production
  37. exports.newWatchPost = function(req, res, next) {
  38. var body = req.body;
  39. // para retornar depois do erro
  40. var form = {
  41. };
  42. var errors = req.validationErrors();
  43. if (errors) {
  44. req.flash('error', errors);
  45. return res.render('novo', {form: form});
  46. }
  47. Watch.findOne({ permalink: req.body.permalink }, function(err, watch) {
  48. if (watch) {
  49. req.flash('error', { msg: 'O permalink inserido já existe. Tente outro.' });
  50. return res.redirect('/novo');
  51. }
  52. // Para salvar no BD
  53. watch = new Watch({
  54. criador: req.user.id,
  55. permalink: req.body.permalink,
  56. layout: 'filme',
  57. featured : false,
  58. title: req.body.title,
  59. subtitle: req.body.subtitle,
  60. sinopse: req.body.sinopse,
  61. year: req.body.year,
  62. classind: req.body.classind,
  63. duration: req.body.duration,
  64. video: req.body.video,
  65. thumb480: req.body.thumb480,
  66. imgbg: req.body.imgbg,
  67. tags: req.body.tags
  68. });
  69. watch.save(function(err) {
  70. //req.logIn(campanha, function(err) {
  71. req.flash('success', { msg: 'Muito obrigado por sua colaboração. Em breve a produção estará no ar. <3' });
  72. res.redirect('/');
  73. //});
  74. });
  75. });
  76. };
  77. // GET Tags
  78. exports.tagsGet = function(req, res){
  79. Watch.find({ 'tags': req.params.tags }, null, {sort: '-year'}, function(err, w){
  80. if (!w) {
  81. return res.redirect('/404');
  82. }
  83. else{
  84. res.render('home', {
  85. title: 'Tag',
  86. tag: req.params.tags,
  87. watch: w
  88. });
  89. }
  90. });
  91. };
  92. //Get Edit Watch
  93. exports.watchEdit = function(req, res){
  94. Watch.findOne({ '_id': req.params._id }, function(err, w){
  95. if (!w) {
  96. return res.redirect('/404');
  97. }
  98. else{
  99. res.render('edit', {
  100. w: w
  101. });
  102. }
  103. });
  104. };
  105. // PUT or Update a Production
  106. exports.watchPut = function(req, res, next) {
  107. var body = req.body;
  108. Watch.findById(req.params._id, function(err, watch) {
  109. /* Para salvar no BD */
  110. /* Internal */
  111. watch.permalink = req.body.permalink;
  112. watch.criador = req.body.criador;
  113. watch.layout = req.body.layout;
  114. watch.featured = req.body.featured;
  115. watch.top = req.body.top
  116. /* Basic */
  117. watch.title = req.body.title;
  118. watch.subtitle = req.body.subtitle;
  119. watch.original_title = req.body.original_title;
  120. watch.year = req.body.year;
  121. watch.duration = req.body.duration;
  122. watch.classind = req.body.classind;
  123. watch.sinopse = req.body.sinopse;
  124. /* More Info */
  125. watch.description = req.body.description;
  126. watch.license = req.body.license;
  127. watch.location.country = req.body.location_country;
  128. watch.location.state = req.body.location_state;
  129. watch.location.city = req.body.location_city;
  130. // watch.location.lat = req.body.location.lat;
  131. // watch.location.lon = req.body.location.lon;
  132. watch.crew.director = req.body.crew_director;
  133. watch.crew.screenplay = req.body.crew_screenplay;
  134. watch.crew.producer = req.body.crew_producer;
  135. watch.crew.cast = req.body.crew_cast;
  136. watch.crew.editor = req.body.crew_editor;
  137. watch.crew.other = req.body.crew_other;
  138. /* Images */
  139. watch.imgbg = req.body.imgbg;
  140. watch.thumb480 = req.body.thumb480;
  141. watch.thumb130 = req.body.thumb130;
  142. /* Video */
  143. watch.video = req.body.video;
  144. watch.trailer = req.body.trailer;
  145. watch.quality = req.body.quality;
  146. watch.audio_language = req.body.audio_language;
  147. watch.srt_language = req.body.srt_language;
  148. /* Files and Download*/
  149. watch.file.film = req.body.file_film;
  150. watch.file.trailer = req.body.file_trailer;
  151. watch.file.srt = req.body.file_srt;
  152. /* Categories */
  153. watch.tags = req.body.tags;
  154. watch.save(function(err) {
  155. req.flash('success', { msg: 'Alterações feitas com sucesso.' });
  156. res.redirect('/edit/' + req.params._id);
  157. });
  158. });
  159. };