mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 02:36:16 +01:00
added admin route to upload favicon
This commit is contained in:
@@ -82,7 +82,7 @@ define(['uploader'], function(uploader) {
|
||||
uploader.hideAlerts();
|
||||
});
|
||||
|
||||
$('#uploadLogoBtn').on('click', function() {
|
||||
$('#uploadFaviconBtn').on('click', function() {
|
||||
uploader.open(RELATIVE_PATH + '/admin/uploadfavicon', function() {
|
||||
$('#favicon').attr('src', './../favicon.ico?v=' + new Date().getTime());
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<label>Maximum User Image Size</label>
|
||||
<input type="text" class="form-control" placeholder="Maximum size of uploaded user images in kilobytes" data-field="maximumProfileImageSize" /><br />
|
||||
<label>Favicon</label><br />
|
||||
<img src="./../favicon.ico" />
|
||||
<img id="favicon" src="./../favicon.ico" />
|
||||
<input id="uploadFaviconBtn" type="button" class="btn btn-default" value="Upload Favicon"></input> <br />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -145,6 +145,53 @@ var nconf = require('nconf'),
|
||||
is.pipe(os);
|
||||
});
|
||||
|
||||
app.post('/uploadfavicon', function(req, res) {
|
||||
if (!req.user)
|
||||
return res.redirect('/403');
|
||||
|
||||
var allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'];
|
||||
|
||||
if (allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
|
||||
res.send({
|
||||
error: 'You can only upload icon file type!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var tempPath = req.files.userPhoto.path;
|
||||
var extension = path.extname(req.files.userPhoto.name);
|
||||
|
||||
if (!extension) {
|
||||
res.send({
|
||||
error: 'Error uploading file! Error : Invalid extension!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var filename = 'favicon.ico';
|
||||
var uploadPath = path.join(nconf.get('base_dir'), 'public', filename);
|
||||
|
||||
winston.info('Attempting upload to: ' + uploadPath);
|
||||
|
||||
var is = fs.createReadStream(tempPath);
|
||||
var os = fs.createWriteStream(uploadPath);
|
||||
|
||||
is.on('end', function () {
|
||||
fs.unlinkSync(tempPath);
|
||||
|
||||
res.json({
|
||||
path: nconf.get('upload_url') + filename
|
||||
});
|
||||
});
|
||||
|
||||
os.on('error', function (err) {
|
||||
fs.unlinkSync(tempPath);
|
||||
winston.err(err);
|
||||
});
|
||||
|
||||
is.pipe(os);
|
||||
});
|
||||
|
||||
app.post('/uploadlogo', function(req, res) {
|
||||
|
||||
if (!req.user)
|
||||
|
||||
Reference in New Issue
Block a user