Skip to content

Commit

Permalink
fix(appearance): issue when uploading logo/favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Feb 26, 2022
1 parent 12d724d commit cb48e79
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions src/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,20 +552,24 @@ mainController.l2authget = function (req, res) {
}

mainController.uploadFavicon = function (req, res) {
var fs = require('fs')
var settingUtil = require('../settings/settingsUtil')
var Busboy = require('busboy')
var busboy = new Busboy({
const fs = require('fs')
const settingUtil = require('../settings/settingsUtil')
const Busboy = require('busboy')
const busboy = Busboy({
headers: req.headers,
limit: {
file: 1,
fileSize: 1024 * 1024 * 1
}
})

var object = {}
var error
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
const object = {}
let error

busboy.on('file', function (name, file, info) {
const filename = info.filename
const mimetype = info.mimeType

if (mimetype.indexOf('image/') === -1) {
error = {
status: 400,
Expand All @@ -575,7 +579,7 @@ mainController.uploadFavicon = function (req, res) {
return file.resume()
}

var savePath = path.join(__dirname, '../../public/uploads/assets')
const savePath = path.join(__dirname, '../../public/uploads/assets')
if (!fs.existsSync(savePath)) fs.mkdirSync(savePath)

object.filePath = path.join(savePath, 'favicon' + path.extname(filename))
Expand Down Expand Up @@ -621,21 +625,23 @@ mainController.uploadFavicon = function (req, res) {
}

mainController.uploadLogo = function (req, res) {
var fs = require('fs')
var settingUtil = require('../settings/settingsUtil')
var Busboy = require('busboy')
var busboy = new Busboy({
const fs = require('fs')
const settingUtil = require('../settings/settingsUtil')
const Busboy = require('busboy')
const busboy = Busboy({
headers: req.headers,
limits: {
files: 1,
fileSize: 1024 * 1024 * 3 // 3mb
}
})

var object = {}
var error
const object = {}
let error

busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
busboy.on('file', function (name, file, info) {
const filename = info.filename
const mimetype = info.mimeType
if (mimetype.indexOf('image/') === -1) {
error = {
status: 400,
Expand All @@ -645,7 +651,7 @@ mainController.uploadLogo = function (req, res) {
return file.resume()
}

var savePath = path.join(__dirname, '../../public/uploads/assets')
const savePath = path.join(__dirname, '../../public/uploads/assets')
if (!fs.existsSync(savePath)) fs.mkdirSync(savePath)

object.filePath = path.join(savePath, 'topLogo' + path.extname(filename))
Expand Down Expand Up @@ -691,21 +697,24 @@ mainController.uploadLogo = function (req, res) {
}

mainController.uploadPageLogo = function (req, res) {
var fs = require('fs')
var settingUtil = require('../settings/settingsUtil')
var Busboy = require('busboy')
var busboy = new Busboy({
const fs = require('fs')
const settingUtil = require('../settings/settingsUtil')
const Busboy = require('busboy')
const busboy = Busboy({
headers: req.headers,
limits: {
files: 1,
fileSize: 1024 * 1024 * 3 // 3mb
}
})

var object = {}
var error
const object = {}
let error

busboy.on('file', function (name, file, info) {
const filename = info.filename
const mimetype = info.mimeType

busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
if (mimetype.indexOf('image/') === -1) {
error = {
status: 400,
Expand All @@ -715,7 +724,7 @@ mainController.uploadPageLogo = function (req, res) {
return file.resume()
}

var savePath = path.join(__dirname, '../../public/uploads/assets')
const savePath = path.join(__dirname, '../../public/uploads/assets')
if (!fs.existsSync(savePath)) fs.mkdirSync(savePath)

object.filePath = path.join(savePath, 'pageLogo' + path.extname(filename))
Expand Down

0 comments on commit cb48e79

Please sign in to comment.