Skip to content

Commit

Permalink
[Bugfix]: 'forbidden_chars' - the condition added for uploading via D…
Browse files Browse the repository at this point in the history
…rop or UploadPicker. nextcloud#43495

Signed-off-by: Andrii Rublov <airublev@outlook.com>
  • Loading branch information
Andrii Rublov committed Feb 10, 2024
1 parent b03199e commit bd483b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 15 additions & 5 deletions apps/files/src/services/DropService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import { getUploader } from '@nextcloud/upload'
import { joinPaths } from '@nextcloud/paths'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { loadState } from '@nextcloud/initial-state'

import logger from '../logger.js'

const forbiddenCharacters = loadState('files', 'forbiddenCharacters', '') as string

export const handleDrop = async (data: DataTransfer): Promise<Upload[]> => {
// TODO: Maybe handle `getAsFileSystemHandle()` in the future

Expand Down Expand Up @@ -67,11 +70,18 @@ export const handleDrop = async (data: DataTransfer): Promise<Upload[]> => {
const handleFileUpload = async (file: File, path: string = '') => {
const uploader = getUploader()

try {
return await uploader.upload(`${path}${file.name}`, file)
} catch (e) {
showError(t('files', 'Uploading "{filename}" failed', { filename: file.name }))
throw e
const forbidden = forbiddenCharacters.split('')
let forbiddenChar

if(forbiddenChar = forbidden.find(char => file.name.includes(char))){
showError(t('files', `"${forbiddenChar}" is not allowed inside a file name.`));
}else{
try {
return await uploader.upload(`${path}${file.name}`, file)
} catch (e) {
showError(t('files', 'Uploading "{filename}" failed', { filename: file.name }))
throw e
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions apps/files/src/views/FilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<UploadPicker v-else-if="currentFolder"
:content="dirContents"
:destination="currentFolder"
:forbiddenCharacters="forbiddenCharacters"
:multiple="true"
class="files-list__header-upload-button"
@failed="onUploadFail"
Expand Down Expand Up @@ -161,6 +162,7 @@ import logger from '../logger.js'
import DragAndDropNotice from '../components/DragAndDropNotice.vue'
const isSharingEnabled = (getCapabilities() as { files_sharing?: boolean })?.files_sharing !== undefined
const forbiddenCharacters = loadState('files', 'forbiddenCharacters', '') as string
export default defineComponent({
name: 'FilesList',
Expand Down Expand Up @@ -402,6 +404,10 @@ export default defineComponent({
return isSharingEnabled
&& this.currentFolder && (this.currentFolder.permissions & Permission.SHARE) !== 0
},
forbiddenCharacters(): string {
return forbiddenCharacters
},
},
watch: {
Expand Down

0 comments on commit bd483b7

Please sign in to comment.