Create a upload for channel logos
This commit is contained in:
parent
e64dc93dca
commit
3bf63be768
4
index.js
4
index.js
@ -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
1462
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||
|
||||
26
src/api.js
26
src/api.js
@ -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) => {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user