index.js
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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;