123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- var gif = require('./gifmaker');
- var util = require('./util');
- var reload = require('auto-reload');;
- var config = reload('./data/category');
- var templates = reload('./data/template');
- var express = require('express');
- var bodyParser = require('body-parser');
- var fs = require('fs');
- var app = express();
- app.use(express.static('public'));
- //app.use(bodyParser());
- app.use(bodyParser.urlencoded({ extended: false }));
- app.use(bodyParser.json());
- app.all('*', function(req, res, next) {
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Headers", "X-Requested-With");
- res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
- res.header("X-Powered-By",' 3.2.1');
- res.header("Content-Type", "application/json;charset=utf-8");
- next();
- });
- app.get('/', function (req, res) {
- res.send('get');
- });
- app.post('/', function (req, res) {
- res.send('post');
- });
- app.get('/gif/category', function (req, res) {
- res.json(config.CATEGRORY);
- });
- app.get('/gif/template', function (req, res) {
- res.json(config.CATEGRORY);
- });
- app.post('/gif/make', function (req, res) {
- var tplid = req.body.tplid;
- var content = req.body.content;
- var quality = req.body.quality;
- var filename = 'cache/' + tplid + '_' + util.sha1(content) + '.gif';
- fs.exists('public/' + filename, function (exists) {
- if (exists) {
- res.json({
- gifurl: util.SERVER + filename
- })
- }
- else {
- var templObj = templates.templates[parseInt(tplid)];
- var sentences = content.split(',');
- templObj.template.forEach(function (element, index) {
- element.options.text = sentences[index];
- });
- gif.makewithfilters('../data/template/' + templObj.hash + '.mp4', templObj.template)
- .size('100%')
- .save('public/' + filename)
- .on('end', function () {
- res.json({
- gifurl: util.SERVER + filename
- })
- });
- }
- });
- });
- var server = app.listen(9091, function () {
- var host = server.address().address;
- var port = server.address().port;
- console.log('Start App, listening at http://%s:%s', host, port);
- });
|