index.js 1.4 KB
var express = require('express');
var createError = require('http-errors');
var router = express.Router();
const post = require('../../../model/video');
const tags = require('../../../model/tagList');
const multer = require('multer');
var moment = require('moment');
var fs = require('fs');
// event post
router.post(
	'/video',
	multer({ dest: 'videos/' }).single('bin'),
	(req, res, next) => {
		console.log(req.file);

		fs.rename(
			`../../../videos/${req.file.filename}`,
			`../../../videos/${req.file.originalname}`,
			(r) => {
				console.log(r);
			}
		);
		var atc = {
			videoUrl: req.file.location,
			title: req.body.title,
			tag: req.body.tag,
		};
		// post.create(atc)
		//   .then( r => {
		//     res.send({ success: true, d: r, token: req.token })
		//   })
		//   .catch((err) => {
		//     console.log(err);
		//       res.send({ success: false, msg: err.message })
		//   });
	}
);
router.post('/post', (req, res, next) => {
	console.log(req.body);
	var atc = {
		title: req.body.title,
		tag: req.body.tag,
	};
	tags
		.create({ tag: req.body.tag })
		.then(() => {
			return post.create(atc);
		})
		.then((r) => {
			res.send({ success: true, d: r, token: req.token });
		})
		.catch((err) => {
			console.log(err);
			res.send({ success: false, msg: err.message });
		});
});

router.all('*', function (req, res, next) {
	next(createError(404, 'This page is not exisit'));
});

module.exports = router;