зеркало из https://github.com/nextcloud/spreed.git
Clear input after getting the files
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
This commit is contained in:
Родитель
86780541ed
Коммит
3c6b7f3b02
|
@ -24,7 +24,7 @@
|
|||
class="wrapper">
|
||||
<!--native file picker, hidden -->
|
||||
<input id="file-upload"
|
||||
ref="file-upload-input"
|
||||
ref="fileUploadInput"
|
||||
multiple
|
||||
type="file"
|
||||
class="hidden-visually"
|
||||
|
@ -262,7 +262,7 @@ export default {
|
|||
* thus opening the file-picker
|
||||
*/
|
||||
clickImportInput() {
|
||||
this.$refs['file-upload-input'].click()
|
||||
this.$refs.fileUploadInput.click()
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -277,6 +277,8 @@ export default {
|
|||
const uploadId = new Date().getTime()
|
||||
// The selected files array coming from the input
|
||||
const files = Object.values(event.target.files)
|
||||
// Clear the input for the next uploads
|
||||
this.$refs.fileUploadInput.value = ''
|
||||
// Process these files in the store
|
||||
await this.$store.dispatch('uploadFiles', { uploadId, token, files })
|
||||
// Get the files that have successfully been uploaded from the store
|
||||
|
|
|
@ -127,19 +127,19 @@ const actions = {
|
|||
// Mark file as uploading to prevent a second function call to start a
|
||||
// second upload for the same file
|
||||
commit('markFileAsUploading', { uploadId, index })
|
||||
// Get the current user id
|
||||
const userId = getters.getUserId()
|
||||
// currentFile to be uploaded
|
||||
const currentFile = state.uploads[uploadId].files[index].file
|
||||
// Destination path on the server
|
||||
const path = '/files/' + userId + getters.getAttachmentFolder() + '/' + currentFile.name
|
||||
const uniquePath = await findUniquePath(client, path)
|
||||
// userRoot path
|
||||
const userRoot = '/files/' + getters.getUserId()
|
||||
// Candidate rest of the path
|
||||
const path = getters.getAttachmentFolder() + '/' + currentFile.name
|
||||
// Get a unique relative path based on the previous path variable
|
||||
const uniquePath = await findUniquePath(client, userRoot, path)
|
||||
try {
|
||||
// Upload the file
|
||||
await client.putFileContents(uniquePath, currentFile)
|
||||
// Compute the sharePath by removing the first part of the upload path
|
||||
const partOfPathToRemove = '/files/' + userId
|
||||
const sharePath = uniquePath.substring(partOfPathToRemove.length, uniquePath.length)
|
||||
await client.putFileContents(userRoot + uniquePath, currentFile)
|
||||
// Path for the sharing request
|
||||
const sharePath = '/' + uniquePath
|
||||
// Mark the file as uploaded in the store
|
||||
commit('markFileAsSuccessUpload', { uploadId, index, sharePath })
|
||||
} catch (exception) {
|
||||
|
|
|
@ -29,13 +29,11 @@
|
|||
* @returns {string} The unique path
|
||||
*/
|
||||
|
||||
const findUniquePath = async function(client, inputPath) {
|
||||
const findUniquePath = async function(client, userRoot, path) {
|
||||
// Return the input path if it doesn't exist in the destination folder
|
||||
if (await client.exists(inputPath) === false) {
|
||||
return inputPath
|
||||
if (await client.exists(userRoot + path) === false) {
|
||||
return path
|
||||
}
|
||||
// Store the input path into a new path variable to operate on it
|
||||
let path = inputPath
|
||||
// Get the file extension (if any)
|
||||
const fileExtension = path.match(/\.[0-9a-z]+$/i) ? path.match(/\.[0-9a-z]+$/i)[0] : ''
|
||||
// If there's a file extention, remove it from the path string
|
||||
|
@ -53,7 +51,7 @@ const findUniquePath = async function(client, inputPath) {
|
|||
// Loop untile a unique path is found
|
||||
for (let number = 2; true; number++) {
|
||||
const uniquePath = pathWithoutSuffix + ` (${number})` + (fileExtension)
|
||||
if (await client.exists(uniquePath) === false) {
|
||||
if (await client.exists(userRoot + uniquePath) === false) {
|
||||
return uniquePath
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче