mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 05:14:23 +00:00
add logo upload
This commit is contained in:
@@ -49,6 +49,7 @@ module.exports = ( app ) => {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
app.post( '/admin/events/uploadImages', multer.array( 'image', 2 ), ( req, res ) => {
|
app.post( '/admin/events/uploadImages', multer.array( 'image', 2 ), ( req, res ) => {
|
||||||
|
if ( req.session.loggedInAdmin ) {
|
||||||
if ( req.query.event.includes( '/' ) || req.query.event.includes( '.' ) ) {
|
if ( req.query.event.includes( '/' ) || req.query.event.includes( '.' ) ) {
|
||||||
res.status( 400 ).send( 'fp_wrong' );
|
res.status( 400 ).send( 'fp_wrong' );
|
||||||
} else {
|
} else {
|
||||||
@@ -61,14 +62,30 @@ module.exports = ( app ) => {
|
|||||||
}
|
}
|
||||||
res.send( 'ok' );
|
res.send( 'ok' );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
res.status( 403 ).send( 'unauthorized' );
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
app.post( '/admin/pages/uploadImages', multer.array( 'image', 1 ), ( req, res ) => {
|
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( '.' ) ) {
|
if ( req.query.image.includes( '/' ) || req.query.image.includes( '.' ) || req.query.template.includes( '/' ) || req.query.template.includes( '.' ) ) {
|
||||||
res.status( 400 ).send( 'fp_wrong' );
|
res.status( 400 ).send( 'fp_wrong' );
|
||||||
} else {
|
} 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' );
|
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' );
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
@@ -26,7 +26,10 @@ module.exports = ( app, settings ) => {
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
app.get( '/startPage/preview/:template', ( req, res ) => {
|
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' ) );
|
res.sendFile( path.join( __dirname + '/../ui/home/templates/' + req.params.template + '/index.html' ) );
|
||||||
|
} else {
|
||||||
|
res.status( 403 ).send( 'unauthorized' );
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
3
src/server/ui/home/templates/default/assets/README.md
Normal file
3
src/server/ui/home/templates/default/assets/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Assets directory
|
||||||
|
|
||||||
|
Inside of the assets directory, the start page assets can be found.
|
||||||
3
src/server/ui/home/templates/fancy/assets/README.md
Normal file
3
src/server/ui/home/templates/fancy/assets/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Assets directory
|
||||||
|
|
||||||
|
Inside of the assets directory, the start page assets can be found.
|
||||||
3
src/server/ui/home/templates/modern/assets/README.md
Normal file
3
src/server/ui/home/templates/modern/assets/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Assets directory
|
||||||
|
|
||||||
|
Inside of the assets directory, the start page assets can be found.
|
||||||
@@ -15,6 +15,23 @@
|
|||||||
<select name="templateSel" id="templateSel" v-model="selectedTemplate">
|
<select name="templateSel" id="templateSel" v-model="selectedTemplate">
|
||||||
<option v-for="el in startPageTemplates" :value="el">{{ el }}</option>
|
<option v-for="el in startPageTemplates" :value="el">{{ el }}</option>
|
||||||
</select>
|
</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>
|
<h3>Change the settings of the start page here</h3>
|
||||||
<button @click="save()" class="button">Save</button>
|
<button @click="save()" class="button">Save</button>
|
||||||
<!-- Start page settings -> Defined by startPage.json file -->
|
<!-- Start page settings -> Defined by startPage.json file -->
|
||||||
@@ -157,11 +174,30 @@
|
|||||||
} );
|
} );
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
console.log( this.$refs[ image ][ 0 ] );
|
|
||||||
console.log( image );
|
|
||||||
return false;
|
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: {
|
watch: {
|
||||||
selectedTemplate( value ) {
|
selectedTemplate( value ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user