Create a upload for channel logos

This commit is contained in:
Rafael Vieira 2021-01-20 00:30:46 -03:00
parent e64dc93dca
commit 3bf63be768
7 changed files with 1171 additions and 348 deletions

View File

@ -4,6 +4,7 @@ const fs = require('fs')
const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const fileUpload = require('express-fileupload');
const api = require('./src/api')
const dbMigration = require('./src/database-migration');
@ -151,6 +152,9 @@ xmltvInterval.startInterval()
let hdhr = HDHR(db, channelDB)
let app = express()
app.use(fileUpload({
createParentPath: true
}));
app.use(bodyParser.json({limit: '50mb'}))
app.get('/version.js', (req, res) => {
res.writeHead(200, {

1462
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,15 +19,16 @@
"angular": "^1.7.9",
"angular-router-browserify": "0.0.2",
"angular-vs-repeat": "2.0.13",
"random-js": "2.1.0",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"diskdb": "^0.1.17",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"node-graceful-shutdown": "1.1.0",
"node-ssdp": "^4.0.0",
"random-js": "2.1.0",
"request": "^2.88.2",
"uuid": "^8.0.0",
"node-graceful-shutdown": "1.1.0",
"xml-writer": "^1.7.0"
},
"bin": "dist/index.js",

View File

@ -209,6 +209,32 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {
res.status(500).send("error");
}
})
router.post('/api/channel/logo', async (req, res) => {
try {
if(!req.files) {
res.send({
status: false,
message: 'No file uploaded'
});
} else {
const logo = req.files.logo;
logo.mv(path.join(process.env.DATABASE, '/images/uploads/', logo.name));
res.send({
status: true,
message: 'File is uploaded',
data: {
name: logo.name,
mimetype: logo.mimetype,
size: logo.size,
fileUrl: `${req.protocol}://${req.get('host')}/images/uploads/${logo.name}`
}
});
}
} catch (err) {
res.status(500).send(err);
}
})
// Filler
router.get('/api/fillers', async (req, res) => {

View File

@ -1852,6 +1852,14 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions) {
scope.timeSlots.startDialog(scope.channel.programs, scope.maxSize, scope.channel.scheduleBackup );
}
scope.logoOnChange = (event) => {
const formData = new FormData();
formData.append('logo', event.target.files[0]);
dizquetv.addChannelLogo(formData).then((response) => {
scope.channel.icon = response.data.fileUrl;
})
}
},
pre: function(scope) {

View File

@ -41,6 +41,12 @@
<h6>Channel Icon Preview</h6>
<img ng-if="channel.icon !== ''" ng-src="{{channel.icon}}" alt="{{channel.name}}" style="max-height: 120px;"/>
<span ng-if="channel.icon === ''">{{channel.name}}</span>
<fieldset>
<input type="file"
onchange="angular.element(this).scope().logoOnChange(event)"
name="logo"
id="logo">
</fieldset>
</div>
</div>
</div>

View File

@ -150,6 +150,14 @@ module.exports = function ($http) {
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}).then((d) => { return d.data })
},
addChannelLogo: (file) => {
return $http({
method: 'POST',
url: '/api/channel/logo?logo',
data: file,
headers: { 'Content-Type': undefined }
}).then((d) => { return d.data })
},
updateChannel: (channel) => {
return $http({
method: 'PUT',