add logo upload

This commit is contained in:
2023-09-30 14:01:34 +02:00
parent 9e9c4b0ec6
commit a84e4197d4
6 changed files with 81 additions and 16 deletions

View File

@@ -49,6 +49,7 @@ module.exports = ( app ) => {
} );
app.post( '/admin/events/uploadImages', multer.array( 'image', 2 ), ( req, res ) => {
if ( req.session.loggedInAdmin ) {
if ( req.query.event.includes( '/' ) || req.query.event.includes( '.' ) ) {
res.status( 400 ).send( 'fp_wrong' );
} else {
@@ -61,14 +62,30 @@ module.exports = ( app ) => {
}
res.send( 'ok' );
}
} else {
res.status( 403 ).send( 'unauthorized' );
}
} );
app.post( '/admin/pages/uploadImages', multer.array( 'image', 1 ), ( req, res ) => {
if ( req.session.loggedInAdmin ) {
if ( req.query.image.includes( '/' ) || req.query.image.includes( '.' ) || req.query.template.includes( '/' ) || req.query.template.includes( '.' ) ) {
res.status( 400 ).send( 'fp_wrong' );
} else {
fs.writeFileSync( path.join( __dirname + '/../ui/home/templates/' + req.query.template + '/' + req.query.image + '.jpg' ), req.files[ 0 ].buffer );
fs.writeFileSync( path.join( __dirname + '/../ui/home/templates/' + req.query.template + '/assets/' + req.query.image + '.jpg' ), req.files[ 0 ].buffer );
res.send( 'ok' );
}
} else {
res.status( 403 ).send( 'unauthorized' );
}
} );
app.post( '/admin/logo/upload', multer.array( 'image', 1 ), ( req, res ) => {
if ( req.session.loggedInAdmin ) {
fs.writeFileSync( path.join( __dirname + '/../assets/logo.png' ), req.files[ 0 ].buffer );
res.send( 'ok' );
} else {
res.status( 403 ).send( 'unauthorized' );
}
} );
};

View File

@@ -26,7 +26,10 @@ module.exports = ( app, settings ) => {
} );
app.get( '/startPage/preview/:template', ( req, res ) => {
// TODO: only allow when logged in
if ( req.session.loggedInAdmin ) {
res.sendFile( path.join( __dirname + '/../ui/home/templates/' + req.params.template + '/index.html' ) );
} else {
res.status( 403 ).send( 'unauthorized' );
}
} );
};

View File

@@ -0,0 +1,3 @@
# Assets directory
Inside of the assets directory, the start page assets can be found.

View File

@@ -0,0 +1,3 @@
# Assets directory
Inside of the assets directory, the start page assets can be found.

View File

@@ -0,0 +1,3 @@
# Assets directory
Inside of the assets directory, the start page assets can be found.

View File

@@ -15,6 +15,23 @@
<select name="templateSel" id="templateSel" v-model="selectedTemplate">
<option v-for="el in startPageTemplates" :value="el">{{ el }}</option>
</select>
<div>
<h4>Upload your website's logo here (png image)</h4>
<picture-input
ref="logoUpload"
width="350"
height="350"
:removable="false"
removeButtonClass="ui red button"
accept="image/png"
buttonClass="ui button primary"
:customStrings="{
upload: '<h1>Upload your image!</h1>',
drag: 'Drag and drop your image here'
}">
</picture-input><br>
<button @click="saveLogo()" class="button">Upload logo</button>
</div>
<h3>Change the settings of the start page here</h3>
<button @click="save()" class="button">Save</button>
<!-- Start page settings -> Defined by startPage.json file -->
@@ -157,11 +174,30 @@
} );
return true;
} else {
console.log( this.$refs[ image ][ 0 ] );
console.log( image );
return false;
}
},
saveLogo() {
if ( this.$refs.logoUpload.file ) {
let fd = new FormData();
fd.append( 'image', this.$refs.logoUpload.file );
let fetchOptions = {
method: 'post',
body: fd,
};
fetch( localStorage.getItem( 'url' ) + '/admin/logo/upload', fetchOptions ).then( res => {
if ( res.status === 200 ) {
this.$refs.notification.createNotification( 'Logo uploaded successfully', 5, 'ok', 'normal' );
} else {
this.$refs.notification.createNotification( 'There was an error uploading the image', 5, 'error', 'normal' );
}
} ).catch( err => {
console.error( err );
} );
} else {
this.$refs.notification.createNotification( 'No logo selected. Please select one and try again!', 10, 'error', 'normal' );
}
}
},
watch: {
selectedTemplate( value ) {