watch.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.layout = req.body.layout;
  113. watch.featured = req.body.featured;
  114. if (req.user.adm) {
  115. watch.criador = req.body.criador;
  116. watch.top = req.body.top;
  117. }
  118. watch.mod_message = req.body.mod_message;
  119. watch.downloadable = req.body.downloadable;
  120. watch.canwecopy = req.body.canwecopy;
  121. /* Basic */
  122. watch.title = req.body.title;
  123. watch.subtitle = req.body.subtitle;
  124. watch.original_title = req.body.original_title;
  125. watch.year = req.body.year;
  126. watch.duration = req.body.duration;
  127. watch.classind = req.body.classind;
  128. watch.sinopse = req.body.sinopse;
  129. /* More Info */
  130. watch.description = req.body.description;
  131. watch.license = req.body.license;
  132. watch.location.country = req.body.location_country;
  133. watch.location.state = req.body.location_state;
  134. watch.location.city = req.body.location_city;
  135. // watch.location.lat = req.body.location.lat;
  136. // watch.location.lon = req.body.location.lon;
  137. watch.crew.director = req.body.crew_director;
  138. watch.crew.screenplay = req.body.crew_screenplay;
  139. watch.crew.producer = req.body.crew_producer;
  140. watch.crew.cast = req.body.crew_cast;
  141. watch.crew.editor = req.body.crew_editor;
  142. watch.crew.other = req.body.crew_other;
  143. /* Images */
  144. watch.imgbg = req.body.imgbg;
  145. watch.thumb480 = req.body.thumb480;
  146. watch.thumb130 = req.body.thumb130;
  147. /* Video */
  148. watch.video = req.body.video;
  149. watch.trailer = req.body.trailer;
  150. watch.quality = req.body.quality;
  151. watch.audio_language = req.body.audio_language;
  152. watch.srt_language = req.body.srt_language;
  153. /* Files and Download*/
  154. watch.file.film = req.body.file_film;
  155. watch.file.trailer = req.body.file_trailer;
  156. watch.file.srt = req.body.file_srt;
  157. /* Categories */
  158. watch.tags = req.body.tags;
  159. watch.save(function(err) {
  160. req.flash('success', { msg: 'Alterações feitas com sucesso.' });
  161. res.redirect('/edit/' + req.params._id);
  162. });
  163. });
  164. };