-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
9,456 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,5 @@ sonar-project.properties | |
public/uploads/assets/*.* | ||
/src/backup/bin/ | ||
backups/ | ||
|
||
public/uploads/assets/upload/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -463,25 +463,46 @@ function randomDate (start, end) { | |
|
||
debugController.sendmail = function (req, res) { | ||
var mailer = require('../mailer') | ||
var templateSchema = require('../models/template') | ||
var Email = require('email-templates') | ||
var templateDir = path.resolve(__dirname, '..', 'mailer', 'templates') | ||
// var templateDir = path.resolve(__dirname, '..', 'mailer', 'templates') | ||
|
||
var to = req.query.email | ||
if (to === undefined) { | ||
return res.status(400).send('Invalid Email in querystring "email"') | ||
} | ||
|
||
var email = new Email({ | ||
views: { | ||
root: templateDir, | ||
options: { | ||
extension: 'handlebars' | ||
} | ||
render: function (view, locals) { | ||
return new Promise(function (resolve, reject) { | ||
if (!global.Handlebars) return reject(new Error('Could not load global.Handlebars')) | ||
templateSchema.findOne({ name: view }, function (err, template) { | ||
if (err) return reject(err) | ||
if (!template) return reject(new Error('Invalid Template')) | ||
var html = global.Handlebars.compile(template.data['gjs-fullHtml'])(locals) | ||
console.log(html) | ||
email.juiceResources(html).then(resolve) | ||
}) | ||
}) | ||
} | ||
}) | ||
|
||
var ticket = { | ||
uid: 100001, | ||
comments: [ | ||
{ | ||
date: new Date(), | ||
comment: 'TESTING', | ||
owner: { | ||
fullname: 'test user', | ||
email: '[email protected]' | ||
} | ||
} | ||
] | ||
} | ||
|
||
.render('ticket-updated', {}) | ||
.render('ticket-updated', { base_url: global.TRUDESK_BASEURL, ticket: ticket }) | ||
.then(function (html) { | ||
var mailOptions = { | ||
to: to, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* . .o8 oooo | ||
* .o8 "888 `888 | ||
* .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo | ||
* 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' | ||
* 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. | ||
* 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. | ||
* "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o | ||
* ======================================================================== | ||
* Author: Chris Brame | ||
* Updated: 1/24/19 11:50 PM | ||
* Copyright (c) 2014-2019. All rights reserved. | ||
*/ | ||
|
||
var _ = require('lodash') | ||
var path = require('path') | ||
var fs = require('fs-extra') | ||
var Busboy = require('busboy') | ||
var templateSchema = require('../models/template') | ||
|
||
var editor = {} | ||
|
||
editor.page = function (req, res) { | ||
var content = {} | ||
content.title = 'Editor' | ||
content.nav = 'settings' | ||
|
||
content.data = {} | ||
content.data.user = req.user | ||
content.data.common = req.viewdata | ||
content.data.template = req.params.template | ||
|
||
return res.render('editor', content) | ||
} | ||
|
||
editor.getAssets = function (req, res) { | ||
var imageExts = ['.gif', '.png', '.jpg', '.jpeg', '.ico', '.bmp'] | ||
|
||
fs.readdir(path.join(__dirname, '../../public/uploads/assets/upload'), function (err, files) { | ||
if (err) return res.status(400).json({ success: false, error: err }) | ||
|
||
files = files.filter(function (file) { | ||
return _.indexOf(imageExts, path.extname(file).toLowerCase() !== -1) | ||
}) | ||
|
||
files = _.map(files, function (i) { | ||
return { src: '/uploads/assets/upload/' + i } | ||
}) | ||
|
||
return res.json({ success: true, assets: files }) | ||
}) | ||
} | ||
|
||
editor.removeAsset = function (req, res) { | ||
var id = req.body.fileUrl | ||
if (!id) return res.status(400).json({ success: false, error: 'Invalid File' }) | ||
|
||
var file = path.basename(id) | ||
fs.unlink(path.join(__dirname, '../../public/uploads/assets/upload', file), function (err) { | ||
if (err) return res.status(500).json({ success: false, error: err }) | ||
|
||
return res.json({ success: true }) | ||
}) | ||
} | ||
|
||
editor.assetsUpload = function (req, res) { | ||
// var chance = new Chance() | ||
var busboy = new Busboy({ | ||
headers: req.headers, | ||
limits: { | ||
files: 1, | ||
fileSize: 5 * 1024 * 1024 // 5mb limit | ||
} | ||
}) | ||
|
||
var object = {} | ||
var error | ||
|
||
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { | ||
if (mimetype.indexOf('image/') === -1) { | ||
error = { | ||
status: 500, | ||
message: 'Invalid File Type' | ||
} | ||
|
||
return file.resume() | ||
} | ||
|
||
// var ext = path.extname(filename) | ||
|
||
var savePath = path.join(__dirname, '../../public/uploads/assets/upload') | ||
// var sanitizedFilename = chance.hash({ length: 20 }) + ext | ||
if (!fs.existsSync(savePath)) fs.ensureDirSync(savePath) | ||
|
||
object.filePath = path.join(savePath, filename) | ||
object.filename = filename | ||
object.mimetype = mimetype | ||
|
||
if (fs.existsSync(object.filePath)) { | ||
error = { | ||
status: 500, | ||
message: 'File already exists' | ||
} | ||
|
||
return file.resume() | ||
} | ||
|
||
file.on('limit', function () { | ||
error = { | ||
status: 500, | ||
message: 'File too large' | ||
} | ||
|
||
return file.resume() | ||
}) | ||
|
||
file.pipe(fs.createWriteStream(object.filePath)) | ||
}) | ||
|
||
busboy.on('finish', function () { | ||
if (error) return res.status(error.status).json({ success: false, error: error }) | ||
|
||
if (_.isUndefined(object.filename) || _.isUndefined(object.filePath)) { | ||
return res.status(400).json({ success: false, error: { message: 'Invalid Form Data' } }) | ||
} | ||
|
||
// Everything Checks out lets make sure the file exists and then add it to the attachments array | ||
if (!fs.existsSync(object.filePath)) | ||
return res.status(500).json({ success: false, error: { message: 'File Failed to Save to Disk' } }) | ||
|
||
var includePort = global.TRUDESK_PORT && global.TRUDESK_PORT !== (80 || 443) | ||
|
||
var fileUrl = | ||
req.protocol + | ||
'://' + | ||
req.hostname + | ||
(includePort ? ':' + global.TRUDESK_PORT.toString() : '') + | ||
'/uploads/assets/upload/' + | ||
object.filename | ||
|
||
// var dimensions = sizeOf(fileUrl) | ||
|
||
return res.json({ | ||
success: true, | ||
data: [fileUrl] | ||
}) | ||
}) | ||
|
||
req.pipe(busboy) | ||
} | ||
|
||
editor.load = function (req, res) { | ||
templateSchema.get(req.params.id, function (err, template) { | ||
if (err) return res.status(400).json({ success: false, error: err }) | ||
|
||
if (!template) | ||
return res.status(400).json({ success: false, invalid: true, error: { message: 'Invalid Template.' } }) | ||
|
||
template.data.id = 'gjs-' | ||
|
||
return res.json(template.data) | ||
}) | ||
} | ||
|
||
editor.save = function (req, res) { | ||
var name = req.body.template | ||
delete req.body.template | ||
templateSchema.findOneAndUpdate( | ||
{ name: name }, | ||
{ name: name, data: req.body }, | ||
{ new: true, upsert: true }, | ||
function (err, template) { | ||
if (err) return res.status(500).json({ success: false, error: err }) | ||
|
||
return res.json({ success: true, tempalte: template }) | ||
} | ||
) | ||
} | ||
|
||
module.exports = editor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.