Tweaks to image upload . Now supports watermark as well. The api has changed. Dialog browses for Images.

This commit is contained in:
vexorian 2021-01-21 19:35:34 -04:00
parent 15f3da9434
commit 54a6f14ff6
4 changed files with 46 additions and 12 deletions

View File

@ -209,7 +209,8 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {
res.status(500).send("error");
}
})
router.post('/api/channel/logo', async (req, res) => {
router.post('/api/upload/image', async (req, res) => {
try {
if(!req.files) {
res.send({
@ -217,7 +218,7 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {
message: 'No file uploaded'
});
} else {
const logo = req.files.logo;
const logo = req.files.image;
logo.mv(path.join(process.env.DATABASE, '/images/uploads/', logo.name));
res.send({

View File

@ -1854,12 +1854,21 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions) {
scope.logoOnChange = (event) => {
const formData = new FormData();
formData.append('logo', event.target.files[0]);
dizquetv.addChannelLogo(formData).then((response) => {
formData.append('image', event.target.files[0]);
dizquetv.uploadImage(formData).then((response) => {
scope.channel.icon = response.data.fileUrl;
})
}
scope.watermarkOnChange = (event) => {
const formData = new FormData();
formData.append('image', event.target.files[0]);
dizquetv.uploadImage(formData).then((response) => {
scope.channel.watermark.url = response.data.fileUrl;
})
}
},
pre: function(scope) {

View File

@ -34,19 +34,24 @@
<div>
<span class="pull-right text-danger">{{error.icon}}</span>
<label for="channelIcon" class="small">Channel Icon</label>
<div class="input-group mb-1">
<input name="channelIcon" id="channelIcon" class="form-control form-control-sm" type="url" ng-model="channel.icon" />
<div class="input-group-append">
<input type="file"
accept="image/*"
class="form-control-file"
onchange="angular.element(this).scope().logoOnChange(event)"
name="logo"
id="logo">
</input>
</div>
</div>
<div>
<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>
@ -696,8 +701,19 @@
<label for="overlayURL">
Watermark Picture URL:
</label>
<input id='overlayURL' class='form-control' type='url' ng-model='channel.watermark.url' placeholder="Leave empty to use the channel&apos;s icon.">
</input>
<div class="input-group-append">
<input type="file"
accept="image/*"
class="form-control-file"
onchange="angular.element(this).scope().watermarkOnChange(event)"
name="logo"
id="logo">
</input>
</div>
</div>
<div class="form-group">

View File

@ -150,10 +150,18 @@ module.exports = function ($http) {
headers: { 'Content-Type': 'application/json; charset=utf-8' }
}).then((d) => { return d.data })
},
addChannelLogo: (file) => {
uploadImage: (file) => {
return $http({
method: 'POST',
url: '/api/channel/logo?logo',
url: '/api/upload/image',
data: file,
headers: { 'Content-Type': undefined }
}).then((d) => { return d.data })
},
addChannelWatermark: (file) => {
return $http({
method: 'POST',
url: '/api/channel/watermark',
data: file,
headers: { 'Content-Type': undefined }
}).then((d) => { return d.data })