Add new ACP option to upload Touch Icon, #3668

Also added a number of fixes for mobile enhancements, such
as serving a manifest.json file for Android devices, and
serving proper link tags for all uploaded touch icons.

This commit also creates a new template helper for link tags.
This commit is contained in:
Julian Lam
2015-09-24 12:04:24 -04:00
parent ae856395c3
commit ebed9d641c
11 changed files with 180 additions and 13 deletions

View File

@@ -2,9 +2,11 @@
var fs = require('fs'),
path = require('path'),
async = require('async'),
nconf = require('nconf'),
winston = require('winston'),
file = require('../../file'),
image = require('../../image'),
plugins = require('../../plugins');
@@ -52,6 +54,41 @@ uploadsController.uploadFavicon = function(req, res, next) {
}
};
uploadsController.uploadTouchIcon = function(req, res, next) {
var uploadedFile = req.files.files[0],
allowedTypes = ['image/png'],
sizes = [36, 48, 72, 96, 144, 192];
if (validateUpload(req, res, next, uploadedFile, allowedTypes)) {
file.saveFileToLocal('touchicon-orig.png', 'system', uploadedFile.path, function(err, imageObj) {
// Resize the image into squares for use as touch icons at various DPIs
async.each(sizes, function(size, next) {
async.series([
async.apply(file.saveFileToLocal, 'touchicon-' + size + '.png', 'system', uploadedFile.path),
async.apply(image.resizeImage, {
path: path.join(nconf.get('base_dir'), nconf.get('upload_path'), 'system', 'touchicon-' + size + '.png'),
extension: 'png',
width: size,
height: size
})
], next);
}, function(err) {
fs.unlink(uploadedFile.path, function(err) {
if (err) {
winston.error(err);
}
});
if (err) {
return next(err);
}
res.json([{name: uploadedFile.name, url: imageObj.url}]);
});
});
}
};
uploadsController.uploadLogo = function(req, res, next) {
upload('site-logo', req, res, next);
};

View File

@@ -186,6 +186,52 @@ Controllers.robots = function (req, res) {
}
};
Controllers.manifest = function(req, res) {
var manifest = {
name: meta.config.title || 'NodeBB',
start_url: nconf.get('relative_path') + '/',
display: 'standalone',
orientation: 'portrait',
icons: []
};
if (meta.config['brand:touchIcon']) {
manifest.icons.push({
src: nconf.get('relative_path') + '/uploads/system/touchicon-36.png',
sizes: '36x36',
type: 'image/png',
density: 0.75
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-48.png',
sizes: '48x48',
type: 'image/png',
density: 1.0
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-72.png',
sizes: '72x72',
type: 'image/png',
density: 1.5
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-96.png',
sizes: '96x96',
type: 'image/png',
density: 2.0
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-144.png',
sizes: '144x144',
type: 'image/png',
density: 3.0
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-192.png',
sizes: '192x192',
type: 'image/png',
density: 4.0
})
}
res.status(200).json(manifest);
};
Controllers.outgoing = function(req, res, next) {
var url = req.query.url,
data = {

View File

@@ -74,7 +74,12 @@ uploadsController.uploadThumb = function(req, res, next) {
if (uploadedFile.type.match(/image./)) {
var size = meta.config.topicThumbSize || 120;
image.resizeImage(uploadedFile.path, path.extname(uploadedFile.name), size, size, function(err) {
image.resizeImage({
path: uploadedFile.path,
extension: path.extname(uploadedFile.name),
width: size,
height: size
}, function(err) {
if (err) {
return next(err);
}