Added toggle to append timestamp to uploaded files

pull/6017/head
Sandu Rajapakse 2 years ago
parent 18ec8126dd
commit 576bebe1e1

@ -177,6 +177,19 @@
persistent-hint persistent-hint
) )
v-card.mt-5.animated.fadeInUp.wait-p6s
v-toolbar(color='primary', dark, dense, flat)
v-toolbar-title.subtitle-1 File Handling
v-card-text
v-switch.mt-0(
inset
label='Append timestamp to filenames'
color='indigo'
v-model='config.uploadAppendTimestampToFilename'
persistent-hint
hint='A timestamp will be appended to the end of the original filename to ensure each uploaded file will not overwrite others.'
)
v-card.mt-5.animated.fadeInUp.wait-p7s v-card.mt-5.animated.fadeInUp.wait-p7s
v-toolbar(color='primary', dark, dense, flat) v-toolbar(color='primary', dark, dense, flat)
v-toolbar-title.subtitle-1 {{$t('admin:general.editShortcuts')}} v-toolbar-title.subtitle-1 {{$t('admin:general.editShortcuts')}}
@ -293,7 +306,8 @@ export default {
editMenuExternalBtn: false, editMenuExternalBtn: false,
editMenuExternalName: '', editMenuExternalName: '',
editMenuExternalIcon: '', editMenuExternalIcon: '',
editMenuExternalUrl: '' editMenuExternalUrl: '',
uploadAppendTimestampToFilename: false
}, },
metaRobots: [ metaRobots: [
{ text: 'Index', value: 'index' }, { text: 'Index', value: 'index' },
@ -358,6 +372,7 @@ export default {
$editMenuExternalName: String $editMenuExternalName: String
$editMenuExternalIcon: String $editMenuExternalIcon: String
$editMenuExternalUrl: String $editMenuExternalUrl: String
$uploadAppendTimestampToFilename: Boolean
) { ) {
site { site {
updateConfig( updateConfig(
@ -381,6 +396,7 @@ export default {
editMenuExternalName: $editMenuExternalName editMenuExternalName: $editMenuExternalName
editMenuExternalIcon: $editMenuExternalIcon editMenuExternalIcon: $editMenuExternalIcon
editMenuExternalUrl: $editMenuExternalUrl editMenuExternalUrl: $editMenuExternalUrl
uploadAppendTimestampToFilename: $uploadAppendTimestampToFilename
) { ) {
responseResult { responseResult {
succeeded succeeded
@ -412,7 +428,8 @@ export default {
editMenuExternalBtn: _.get(this.config, 'editMenuExternalBtn', false), editMenuExternalBtn: _.get(this.config, 'editMenuExternalBtn', false),
editMenuExternalName: _.get(this.config, 'editMenuExternalName', ''), editMenuExternalName: _.get(this.config, 'editMenuExternalName', ''),
editMenuExternalIcon: _.get(this.config, 'editMenuExternalIcon', ''), editMenuExternalIcon: _.get(this.config, 'editMenuExternalIcon', ''),
editMenuExternalUrl: _.get(this.config, 'editMenuExternalUrl', '') editMenuExternalUrl: _.get(this.config, 'editMenuExternalUrl', ''),
uploadAppendTimestampToFilename: _.get(this.config, 'uploadAppendTimestampToFilename', false)
}, },
watchLoading (isLoading) { watchLoading (isLoading) {
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-site-update') this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-site-update')
@ -473,6 +490,7 @@ export default {
editMenuExternalName editMenuExternalName
editMenuExternalIcon editMenuExternalIcon
editMenuExternalUrl editMenuExternalUrl
uploadAppendTimestampToFilename
} }
} }
} }

@ -97,6 +97,7 @@ defaults:
maxFiles: 10 maxFiles: 10
scanSVG: true scanSVG: true
forceDownload: true forceDownload: true
appendTimestampToFilename: false
flags: flags:
ldapdebug: false ldapdebug: false
sqllog: false sqllog: false

@ -78,9 +78,11 @@ router.post('/u', (req, res, next) => {
// Sanitize filename // Sanitize filename
fileMeta.originalname = sanitize(fileMeta.originalname.toLowerCase().replace(/[\s,;#]+/g, '_')) fileMeta.originalname = sanitize(fileMeta.originalname.toLowerCase().replace(/[\s,;#]+/g, '_'))
// Prevent overwriting of pasted images // Append timestamp after the filename
if (fileMeta.originalname === 'image.png') { if (WIKI.config.uploads.appendTimestampToFilename) {
fileMeta.originalname = 'image_' + Date.now() + '.png' const parts = fileMeta.originalname.split('.')
const ext = parts.pop()
fileMeta.originalname = `${parts.join('.')}_${Date.now()}.${ext}`
} }
// Check if user can upload at path // Check if user can upload at path

@ -33,7 +33,8 @@ module.exports = {
uploadMaxFileSize: WIKI.config.uploads.maxFileSize, uploadMaxFileSize: WIKI.config.uploads.maxFileSize,
uploadMaxFiles: WIKI.config.uploads.maxFiles, uploadMaxFiles: WIKI.config.uploads.maxFiles,
uploadScanSVG: WIKI.config.uploads.scanSVG, uploadScanSVG: WIKI.config.uploads.scanSVG,
uploadForceDownload: WIKI.config.uploads.forceDownload uploadForceDownload: WIKI.config.uploads.forceDownload,
uploadAppendTimestampToFilename: WIKI.config.uploads.appendTimestampToFilename
} }
} }
}, },
@ -117,7 +118,8 @@ module.exports = {
maxFileSize: _.get(args, 'uploadMaxFileSize', WIKI.config.uploads.maxFileSize), maxFileSize: _.get(args, 'uploadMaxFileSize', WIKI.config.uploads.maxFileSize),
maxFiles: _.get(args, 'uploadMaxFiles', WIKI.config.uploads.maxFiles), maxFiles: _.get(args, 'uploadMaxFiles', WIKI.config.uploads.maxFiles),
scanSVG: _.get(args, 'uploadScanSVG', WIKI.config.uploads.scanSVG), scanSVG: _.get(args, 'uploadScanSVG', WIKI.config.uploads.scanSVG),
forceDownload: _.get(args, 'uploadForceDownload', WIKI.config.uploads.forceDownload) forceDownload: _.get(args, 'uploadForceDownload', WIKI.config.uploads.forceDownload),
appendTimestampToFilename: _.get(args, 'uploadAppendTimestampToFilename', WIKI.config.uploads.appendTimestampToFilename)
} }
await WIKI.configSvc.saveToDb(['host', 'title', 'company', 'contentLicense', 'seo', 'logoUrl', 'pageExtensions', 'auth', 'editShortcuts', 'features', 'security', 'uploads']) await WIKI.configSvc.saveToDb(['host', 'title', 'company', 'contentLicense', 'seo', 'logoUrl', 'pageExtensions', 'auth', 'editShortcuts', 'features', 'security', 'uploads'])

@ -64,6 +64,7 @@ type SiteMutation {
uploadMaxFiles: Int uploadMaxFiles: Int
uploadScanSVG: Boolean uploadScanSVG: Boolean
uploadForceDownload: Boolean uploadForceDownload: Boolean
uploadAppendTimestampToFilename: Boolean
): DefaultResponse @auth(requires: ["manage:system"]) ): DefaultResponse @auth(requires: ["manage:system"])
} }
@ -113,4 +114,5 @@ type SiteConfig {
uploadMaxFiles: Int uploadMaxFiles: Int
uploadScanSVG: Boolean uploadScanSVG: Boolean
uploadForceDownload: Boolean uploadForceDownload: Boolean
uploadAppendTimestampToFilename: Boolean
} }

@ -80,6 +80,9 @@ module.exports = () => {
tokenExpiration: '30m', tokenExpiration: '30m',
tokenRenewal: '14d' tokenRenewal: '14d'
}) })
_.set(WIKI.config, 'upload', {
appendTimestampToFilename: false
})
_.set(WIKI.config, 'company', '') _.set(WIKI.config, 'company', '')
_.set(WIKI.config, 'features', { _.set(WIKI.config, 'features', {
featurePageRatings: true, featurePageRatings: true,

Loading…
Cancel
Save