Merge remote-tracking branch 'origin/bulk-operations'

# Conflicts:
#	app/Http/Helpers/helpers.php
#	public/chunks/app-others.js
#	public/js/main.js
#	public/mix-manifest.json
#	resources/js/components/FilesView/FileItemList.vue
#	resources/js/components/FilesView/FilePreview.vue
#	resources/js/helpers.js
#	resources/js/store/modules/fileFunctions.js
This commit is contained in:
Peter Papp
2020-12-21 17:17:10 +01:00
9 changed files with 905 additions and 1140 deletions
+23
View File
@@ -355,6 +355,25 @@ function format_gigabytes($gigabytes)
} }
} }
/**
* Format string to formated megabytes string
*
* @param $megabytes
* @return string
*/
function format_megabytes($megabytes)
{
if ($megabytes >= 1000) {
return $megabytes / 1000 . 'GB';
}
if ($megabytes >= 1000000) {
return $megabytes / 1000000 . 'TB';
}
return $megabytes . 'MB';
}
/** /**
* Convert megabytes to bytes * Convert megabytes to bytes
* *
@@ -530,7 +549,11 @@ function get_pretty_name($basename, $name, $mimetype)
} }
/** /**
<<<<<<<<< Temporary merge branch 1
* Read exif data from jpeg image file
=========
* Get exif data from jpeg image * Get exif data from jpeg image
>>>>>>>>> Temporary merge branch 2
* *
* @param $file * @param $file
* @return array * @return array
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -1,6 +1,6 @@
{ {
"/chunks/files~chunks/shared-files~chunks/shared-page.js": "/chunks/files~chunks/shared-files~chunks/shared-page.js?id=557306a425c7c0085100", "/chunks/files~chunks/shared-files~chunks/shared-page.js": "/chunks/files~chunks/shared-files~chunks/shared-page.js?id=0c7dde0131eccc4e0f4f",
"/js/main.js": "/js/main.js?id=3e0d5147116744fbdb7c", "/js/main.js": "/js/main.js?id=3ba23e1e53e5d38fb356",
"/css/app.css": "/css/app.css?id=8f6d5dcb7110a726e142", "/css/app.css": "/css/app.css?id=8f6d5dcb7110a726e142",
"/chunks/admin.js": "/chunks/admin.js?id=60df31e17e9a453717dc", "/chunks/admin.js": "/chunks/admin.js?id=60df31e17e9a453717dc",
"/chunks/admin-account.js": "/chunks/admin-account.js?id=ab97f01586b286e0bba2", "/chunks/admin-account.js": "/chunks/admin-account.js?id=ab97f01586b286e0bba2",
@@ -8,7 +8,7 @@
"/chunks/app-billings.js": "/chunks/app-billings.js?id=2a85f4c8ad09b50f4358", "/chunks/app-billings.js": "/chunks/app-billings.js?id=2a85f4c8ad09b50f4358",
"/chunks/app-email.js": "/chunks/app-email.js?id=49806a5c914ca1a14bff", "/chunks/app-email.js": "/chunks/app-email.js?id=49806a5c914ca1a14bff",
"/chunks/app-index.js": "/chunks/app-index.js?id=ff6fb3cb1780d6ea76f2", "/chunks/app-index.js": "/chunks/app-index.js?id=ff6fb3cb1780d6ea76f2",
"/chunks/app-others.js": "/chunks/app-others.js?id=ebc9676ed26d701a599c", "/chunks/app-others.js": "/chunks/app-others.js?id=6eb162d433e0b9b8b7b2",
"/chunks/app-payments.js": "/chunks/app-payments.js?id=ad822a37d1d7c6e99a08", "/chunks/app-payments.js": "/chunks/app-payments.js?id=ad822a37d1d7c6e99a08",
"/chunks/app-settings.js": "/chunks/app-settings.js?id=e23a68dba034c047ff44", "/chunks/app-settings.js": "/chunks/app-settings.js?id=e23a68dba034c047ff44",
"/chunks/app-setup.js": "/chunks/app-setup.js?id=c1c6fcc091a248b10060", "/chunks/app-setup.js": "/chunks/app-setup.js?id=c1c6fcc091a248b10060",
@@ -1,30 +1,30 @@
<template> <template>
<div class="file-wrapper" @click.stop="clickedItem" @dblclick="goToItem" spellcheck="false"> <div class="file-wrapper" @click.stop="clickedItem" @dblclick="goToItem" spellcheck="false">
<!--List preview--> <!--List preview-->
<div :draggable="canDrag" @dragstart="$emit('dragstart')" @drop=" <div
drop() :draggable="canDrag"
area = false" @dragleave="dragLeave" @dragover.prevent="dragEnter" class="file-item" :class="{'is-clicked' : isClicked , 'no-clicked' : !isClicked && this.$isMobile(), 'is-dragenter': area }"> @dragstart="$emit('dragstart')"
<!-- MultiSelecting for the mobile version --> @drop="
<transition name="slide-from-left"> $emit('drop')
<div class="check-select" v-if="mobileMultiSelect"> area = false
<div class="select-box" :class="{'select-box-active' : isClicked } "> "
<CheckIcon v-if="isClicked" class="icon" size="17"/> @dragleave="dragLeave"
</div> @dragover.prevent="dragEnter"
</div> class="file-item"
</transition> :class="{ 'is-clicked': isClicked, 'is-dragenter': area }"
>
<!--Thumbnail for item--> <!--Thumbnail for item-->
<div class="icon-item"> <div class="icon-item">
<!--If is file or image, then link item--> <!--If is file or image, then link item-->
<span v-if="isFile" class="file-icon-text"> <span v-if="isFile || (isImage && !data.thumbnail)" class="file-icon-text">
{{ data.mimetype | limitCharacters }} {{ data.mimetype | limitCharacters }}
</span> </span>
<!--Folder thumbnail--> <!--Folder thumbnail-->
<FontAwesomeIcon v-if="isFile" class="file-icon" icon="file"/> <FontAwesomeIcon v-if="isFile || (isImage && !data.thumbnail)" class="file-icon" icon="file" />
<!--Image thumbnail--> <!--Image thumbnail-->
<img loading="lazy" v-if="isImage" class="image" :src="data.thumbnail" :alt="data.name"/> <img loading="lazy" v-if="isImage && data.thumbnail" class="image" :src="data.thumbnail" :alt="data.name" />
<!--Else show only folder icon--> <!--Else show only folder icon-->
<FontAwesomeIcon v-if="isFolder" :class="{ 'is-deleted': isDeleted }" class="folder-icon" icon="folder" /> <FontAwesomeIcon v-if="isFolder" :class="{ 'is-deleted': isDeleted }" class="folder-icon" icon="folder" />
@@ -32,7 +32,8 @@
<!--Name--> <!--Name-->
<div class="item-name"> <div class="item-name">
<b ref="name" @input="renameItem" @keydown.delete.stop :contenteditable="canEditName" class="name"> <!--Name-->
<b ref="name" @input="renameItem" :contenteditable="canEditName" class="name">
{{ itemName }} {{ itemName }}
</b> </b>
@@ -55,20 +56,18 @@
</div> </div>
</div> </div>
<!--Show item actions--> <!--Go Next icon-->
<transition name="slide-from-right"> <div class="actions" v-if="$isMobile() && !($checkPermission('visitor') && isFolder)">
<div class="actions" v-if="$isMobile() && !($checkPermission('visitor') && isFolder || mobileMultiSelect)">
<span @click.stop="showItemActions" class="show-actions"> <span @click.stop="showItemActions" class="show-actions">
<FontAwesomeIcon icon="ellipsis-v" class="icon-action"></FontAwesomeIcon> <FontAwesomeIcon icon="ellipsis-v" class="icon-action"></FontAwesomeIcon>
</span> </span>
</div> </div>
</transition>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { LinkIcon, UserPlusIcon, CheckIcon } from 'vue-feather-icons' import { LinkIcon, UserPlusIcon } from 'vue-feather-icons'
import { debounce } from 'lodash' import { debounce } from 'lodash'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { events } from '@/bus' import { events } from '@/bus'
@@ -78,15 +77,10 @@ export default {
props: ['data'], props: ['data'],
components: { components: {
UserPlusIcon, UserPlusIcon,
LinkIcon, LinkIcon
CheckIcon
}, },
computed: { computed: {
...mapGetters(['FilePreviewType', 'fileInfoDetail']), ...mapGetters(['FilePreviewType']),
...mapGetters({ allData: 'data' }),
isClicked() {
return this.fileInfoDetail.some(element => element.unique_id == this.data.unique_id)
},
isFolder() { isFolder() {
return this.data.type === 'folder' return this.data.type === 'folder'
}, },
@@ -133,18 +127,14 @@ export default {
}, },
data() { data() {
return { return {
isClicked: false,
area: false, area: false,
itemName: undefined, itemName: undefined
mobileMultiSelect: false
} }
}, },
methods: { methods: {
drop() {
events.$emit('drop')
},
showItemActions() { showItemActions() {
// Load file info detail // Load file info detail
this.$store.commit('CLEAR_FILEINFO_DETAIL')
this.$store.commit('GET_FILEINFO_DETAIL', this.data) this.$store.commit('GET_FILEINFO_DETAIL', this.data)
events.$emit('mobileMenu:show') events.$emit('mobileMenu:show')
@@ -158,47 +148,12 @@ export default {
this.area = false this.area = false
}, },
clickedItem(e) { clickedItem(e) {
events.$emit('unClick') events.$emit('contextMenu:hide')
events.$emit('fileItem:deselect')
if (!this.$isMobile()) { // Set clicked item
this.isClicked = true
if ((e.ctrlKey || e.metaKey) && !e.shiftKey) {
// Click + Ctrl
if (this.fileInfoDetail.some(item => item.unique_id === this.data.unique_id)) {
this.$store.commit('REMOVE_ITEM_FILEINFO_DETAIL', this.data)
} else {
this.$store.commit('GET_FILEINFO_DETAIL', this.data)
}
} else if (e.shiftKey) {
// Click + Shift
let lastItem = this.allData.indexOf(this.fileInfoDetail[this.fileInfoDetail.length - 1])
let clickedItem = this.allData.indexOf(this.data)
// If Click + Shift + Ctrl dont remove already selected items
if (!e.ctrlKey && !e.metaKey) {
this.$store.commit('CLEAR_FILEINFO_DETAIL')
}
//Shift selecting from top to bottom
if (lastItem < clickedItem) {
for (let i = lastItem; i <= clickedItem; i++) {
this.$store.commit('GET_FILEINFO_DETAIL', this.allData[i])
}
//Shift selecting from bottom to top
} else {
for (let i = lastItem; i >= clickedItem; i--) {
this.$store.commit('GET_FILEINFO_DETAIL', this.allData[i])
}
}
} else {
// Click
this.$store.commit('CLEAR_FILEINFO_DETAIL')
this.$store.commit('GET_FILEINFO_DETAIL', this.data)
}
}
if (!this.mobileMultiSelect && this.$isMobile()) {
// Open in mobile version on first click // Open in mobile version on first click
if (this.$isMobile() && this.isFolder) { if (this.$isMobile() && this.isFolder) {
// Go to folder // Go to folder
@@ -211,19 +166,12 @@ export default {
if (this.$isMobile()) { if (this.$isMobile()) {
if (this.isImage || this.isVideo || this.isAudio) { if (this.isImage || this.isVideo || this.isAudio) {
this.$store.commit('GET_FILEINFO_DETAIL', this.data)
events.$emit('fileFullPreview:show') events.$emit('fileFullPreview:show')
} }
} }
}
if (this.mobileMultiSelect && this.$isMobile()) { // Load file info detail
if (this.fileInfoDetail.some(item => item.unique_id === this.data.unique_id)) {
this.$store.commit('REMOVE_ITEM_FILEINFO_DETAIL', this.data)
} else {
this.$store.commit('GET_FILEINFO_DETAIL', this.data) this.$store.commit('GET_FILEINFO_DETAIL', this.data)
}
}
// Get target classname // Get target classname
let itemClass = e.target.className let itemClass = e.target.className
@@ -238,10 +186,6 @@ export default {
this.$downloadFile(this.data.file_url, this.data.name + '.' + this.data.mimetype) this.$downloadFile(this.data.file_url, this.data.name + '.' + this.data.mimetype)
} else if (this.isFolder) { } else if (this.isFolder) {
//Clear selected items after open another folder
this.$store.commit('CLEAR_FILEINFO_DETAIL')
if (this.$isThisLocation('public')) { if (this.$isThisLocation('public')) {
this.$store.dispatch('browseShared', [{ folder: this.data, back: false, init: false }]) this.$store.dispatch('browseShared', [{ folder: this.data, back: false, init: false }])
} else { } else {
@@ -263,14 +207,9 @@ export default {
created() { created() {
this.itemName = this.data.name this.itemName = this.data.name
events.$on('mobileSelecting:start', () => { events.$on('fileItem:deselect', () => {
this.mobileMultiSelect = true // Deselect file
this.$store.commit('CLEAR_FILEINFO_DETAIL') this.isClicked = false
})
events.$on('mobileSelecting:stop', () => {
this.mobileMultiSelect = false
this.$store.commit('CLEAR_FILEINFO_DETAIL')
}) })
// Change item name // Change item name
@@ -285,53 +224,6 @@ export default {
@import '@assets/vue-file-manager/_variables'; @import '@assets/vue-file-manager/_variables';
@import '@assets/vue-file-manager/_mixins'; @import '@assets/vue-file-manager/_mixins';
.slide-from-left-move {
transition: transform 300s ease;
}
.slide-from-left-enter-active,
.slide-from-right-enter-active,
.slide-from-left-leave-active,
.slide-from-right-leave-active {
transition: all 300ms;
}
.slide-from-left-enter,
.slide-from-left-leave-to {
opacity: 0;
transform: translateX(-100%);
}
.slide-from-right-enter,
.slide-from-right-leave-to {
opacity: 0;
transform: translateX(100%);
}
.check-select {
margin-right: 15px;
margin-left: 6px;
.select-box {
width: 20px;
height: 20px;
background-color: darken($light_background, 5%);
display: flex;
justify-content: center;
align-items: center;
border-radius: 5px;
}
.select-box-active {
background-color: #f4f5f6;
.icon {
stroke: $text;
}
}
}
.file-wrapper { .file-wrapper {
user-select: none; user-select: none;
position: relative; position: relative;
@@ -503,40 +395,19 @@ export default {
border-radius: 8px; border-radius: 8px;
} }
&.no-clicked {
background: white !important;
.item-name {
.name {
color: $text !important;
}
}
}
&:hover, &:hover,
&.is-clicked { &.is-clicked {
border-radius: 8px; border-radius: 8px;
background: $light_background; background: $light_background;
.item-name .name {
color: $theme;
}
} }
} }
} }
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
.check-select {
.select-box {
background-color: lighten($dark_mode_foreground, 10%);
}
.select-box-active {
background-color: lighten($dark_mode_foreground, 10%);
.icon {
stroke: $theme;
}
}
}
.file-wrapper { .file-wrapper {
.icon-item { .icon-item {
.file-icon { .file-icon {
@@ -556,33 +427,10 @@ export default {
} }
.file-item { .file-item {
&.no-clicked {
background: $dark_mode_background !important;
.file-icon {
path {
fill: $dark_mode_foreground !important;
stroke: #2F3C54;
}
}
.item-name {
.name {
color: $dark_mode_text_primary !important;
}
}
}
&:hover, &:hover,
&.is-clicked { &.is-clicked {
background: $dark_mode_foreground; background: $dark_mode_foreground;
.item-name .name {
color: $theme;
}
.file-icon { .file-icon {
path { path {
fill: $dark_mode_background; fill: $dark_mode_background;
@@ -1,9 +1,9 @@
<template> <template>
<div v-if="canBePreview" class="preview"> <div v-if="canBePreview" class="preview">
<img v-if="fileInfoDetail[0].type == 'image'" :src="fileInfoDetail[0].thumbnail" :alt="fileInfoDetail[0].name" /> <img v-if="fileInfoDetail.type == 'image' && fileInfoDetail.thumbnail" :src="fileInfoDetail.thumbnail" :alt="fileInfoDetail.name" />
<audio v-else-if="fileInfoDetail[0].type == 'audio'" :src="fileInfoDetail[0].file_url" controlsList="nodownload" controls></audio> <audio v-else-if="fileInfoDetail.type == 'audio'" :src="fileInfoDetail.file_url" controlsList="nodownload" controls></audio>
<video v-else-if="fileInfoDetail[0].type == 'video'" controlsList="nodownload" disablePictureInPicture playsinline controls> <video v-else-if="fileInfoDetail.type == 'video'" controlsList="nodownload" disablePictureInPicture playsinline controls>
<source :src="fileInfoDetail[0].file_url" type="video/mp4"> <source :src="fileInfoDetail.file_url" type="video/mp4">
</video> </video>
</div> </div>
</template> </template>
@@ -17,9 +17,9 @@
computed: { computed: {
...mapGetters(['fileInfoDetail']), ...mapGetters(['fileInfoDetail']),
canBePreview() { canBePreview() {
return this.fileInfoDetail[0] && ! includes([ return this.fileInfoDetail && ! includes([
'folder', 'file' 'folder', 'file'
], this.fileInfoDetail[0].type) ], this.fileInfoDetail.type)
} }
}, },
} }
+35 -42
View File
@@ -1,6 +1,6 @@
import i18n from '@/i18n/index' import i18n from '@/i18n/index'
import store from './store/index' import store from './store/index'
import { debounce, includes } from 'lodash' import {debounce, includes} from "lodash";
import {events} from './bus' import {events} from './bus'
import axios from 'axios' import axios from 'axios'
import router from '@/router' import router from '@/router'
@@ -10,7 +10,7 @@ const Helpers = {
Vue.prototype.$updateText = debounce(function (route, name, value) { Vue.prototype.$updateText = debounce(function (route, name, value) {
let enableEmptyInput = ['mimetypes_blacklist', 'google_analytics'] let enableEmptyInput = ['mimetypes_blacklist' , 'google_analytics' , 'upload_limit']
if (value === '' && !enableEmptyInput.includes(name)) return if (value === '' && !enableEmptyInput.includes(name)) return
@@ -18,7 +18,7 @@ const Helpers = {
.catch(error => { .catch(error => {
events.$emit('alert:open', { events.$emit('alert:open', {
title: this.$t('popup_error.title'), title: this.$t('popup_error.title'),
message: this.$t('popup_error.message') message: this.$t('popup_error.message'),
}) })
}) })
}, 150) }, 150)
@@ -35,13 +35,13 @@ const Helpers = {
axios.post(this.$store.getters.api + route, formData, { axios.post(this.$store.getters.api + route, formData, {
headers: { headers: {
'Content-Type': 'multipart/form-data' 'Content-Type': 'multipart/form-data',
} }
}) })
.catch(error => { .catch(error => {
events.$emit('alert:open', { events.$emit('alert:open', {
title: this.$t('popup_error.title'), title: this.$t('popup_error.title'),
message: this.$t('popup_error.message') message: this.$t('popup_error.message'),
}) })
}) })
} }
@@ -72,12 +72,16 @@ const Helpers = {
win.focus() win.focus()
} }
Vue.prototype.$createFolder = function (folderName) {
this.$store.dispatch('createFolder', folderName)
}
Vue.prototype.$handleUploading = async function (files, parent_id) { Vue.prototype.$handleUploading = async function (files, parent_id) {
let fileBuffer = [] let fileBuffer = []
// Append the file list to fileBuffer array // Append the file list to fileBuffer array
Array.prototype.push.apply(fileBuffer, files) Array.prototype.push.apply(fileBuffer, files);
let fileSucceed = 0 let fileSucceed = 0
@@ -101,13 +105,13 @@ const Helpers = {
// Calculate ceils // Calculate ceils
let size = this.$store.getters.config.chunkSize, let size = this.$store.getters.config.chunkSize,
chunksCeil = Math.ceil(file.size / size) chunksCeil = Math.ceil(file.size / size);
// Create chunks // Create chunks
for (let i = 0; i < chunksCeil; i++) { for (let i = 0; i < chunksCeil; i++) {
chunks.push(file.slice( chunks.push(file.slice(
i * size, Math.min(i * size + size, file.size), file.type i * size, Math.min(i * size + size, file.size), file.type
)) ));
} }
// Set Data // Set Data
@@ -123,9 +127,9 @@ const Helpers = {
attempts = 0 attempts = 0
// Set form data // Set form data
formData.set('file', chunk, filename) formData.set('file', chunk, filename);
formData.set('parent_id', rootFolder) formData.set('parent_id', rootFolder)
formData.set('is_last', isLast) formData.set('is_last', isLast);
// Upload chunks // Upload chunks
do { do {
@@ -144,8 +148,8 @@ const Helpers = {
if (error.response.status === 500) if (error.response.status === 500)
isNotGeneralError = false isNotGeneralError = false
//Break if mimetype of file is in blacklist //Break if mimetype of file is in blacklist or file size exceed upload limit
if (error.response.status === 415) if(error.response.status === 415 || 413)
isNotGeneralError = false isNotGeneralError = false
// Show Error // Show Error
@@ -173,7 +177,7 @@ const Helpers = {
if (files.length == 0) return if (files.length == 0) return
if (!this.$checkFileMimetype(files)) return if (!this.$checkFileMimetype(files) || !this.$checkUploadLimit(files)) return
this.$handleUploading(files, undefined) this.$handleUploading(files, undefined)
} }
@@ -184,7 +188,7 @@ const Helpers = {
if (event.dataTransfer.items.length == 0) return if (event.dataTransfer.items.length == 0) return
// Get files // Get files
let files = [...event.dataTransfer.items].map(item => item.getAsFile()) let files = [...event.dataTransfer.items].map(item => item.getAsFile());
this.$handleUploading(files, parent_id) this.$handleUploading(files, parent_id)
} }
@@ -272,9 +276,10 @@ const Helpers = {
} }
Vue.prototype.$isSomethingWrong = function () { Vue.prototype.$isSomethingWrong = function () {
events.$emit('alert:open', { events.$emit('alert:open', {
title: i18n.t('popup_error.title'), title: this.$t('popup_error.title'),
message: i18n.t('popup_error.message') message: this.$t('popup_error.message'),
}) })
} }
Vue.prototype.$checkFileMimetype = function(files) { Vue.prototype.$checkFileMimetype = function(files) {
@@ -294,40 +299,28 @@ const Helpers = {
events.$emit('alert:open', { events.$emit('alert:open', {
emoji: '😬😬😬', emoji: '😬😬😬',
title: i18n.t('popup_mimetypes_blacklist.title'), title: i18n.t('popup_mimetypes_blacklist.title'),
message: i18n.t('popup_mimetypes_blacklist.message', { mimetype: fileType[1] }) message: i18n.t('popup_mimetypes_blacklist.message', {mimetype: fileType[1]}),
}) })
} }
} }
return validated return validated
} }
Vue.prototype.$getDataByLocation = function() { Vue.prototype.$checkUploadLimit = function (files) {
let uploadLimit = store.getters.config.uploadLimit
let validate = true
let folder = store.getters.currentFolder for (let i = 0 ; i<files.length; i++ ) {
if(uploadLimit != 0 && files[i].size > uploadLimit) {
let actions = { validate = false
'base': ['getFolder', [{ folder: folder, back: true, init: false, sorting: true }]], events.$emit('alert:open', {
'public': ['browseShared', [{ folder: folder, back: true, init: false, sorting: true }]], emoji: '😟😟😟',
'trash': ['getFolder', [{ folder: folder, back: true, init: false, sorting: true }]], title: i18n.t('popup_upload_limit.title'),
'participant_uploads': ['getParticipantUploads'], message: i18n.t('popup_upload_limit.message', {uploadLimit: store.getters.config.uploadLimitFormatted}),
'trash-root': ['getTrash'], })
'latest': ['getLatest'], break
'shared': ['getShared']
} }
this.$store.dispatch(...actions[folder.location])
// Get dara of user with favourites tree
this.$store.dispatch('getAppData')
// Get data of Navigator tree
this.$store.dispatch('getFolderTree')
}
Vue.prototype.$checkOS = function() {
// Handle styled scrollbar for Windows
if (navigator.userAgent.indexOf('Windows') != -1) {
let body = document.body
body.classList.add('windows')
} }
return validate
} }
} }
} }
+45 -144
View File
@@ -3,81 +3,30 @@ import router from '@/router'
import {events} from '@/bus' import {events} from '@/bus'
import {last} from 'lodash' import {last} from 'lodash'
import axios from 'axios' import axios from 'axios'
import Vue from 'vue'
const defaultState = {
isZippingFiles: false,
}
const actions = { const actions = {
downloadFiles: ({ commit, getters }) => { moveItem: ({commit, getters, dispatch}, [item_from, to_item]) => {
let files = []
// get unique_ids of selected files
getters.fileInfoDetail.forEach(file => files.push(file.unique_id))
// Get route // Get route
let route = getters.sharedDetail && ! getters.sharedDetail.protected let route = getters.sharedDetail && ! getters.sharedDetail.protected
? '/api/zip/public/' + router.currentRoute.params.token ? '/api/move/' + item_from.unique_id + '/public/' + router.currentRoute.params.token
: '/api/zip' : '/api/move/' + item_from.unique_id
commit('ZIPPING_FILE_STATUS', true)
axios.post(route, {
files: files
})
.then(response => {
Vue.prototype.$downloadFile(response.data.url, response.data.name)
})
.catch(() => {
Vue.prototype.$isSomethingWrong()
})
.finally(() => {
commit('ZIPPING_FILE_STATUS', false)
})
},
moveItem: ({ commit, getters, dispatch }, { to_item, noSelectedItem }) => {
let itemsToMove = []
let items = [noSelectedItem]
// If coming no selected item dont get items to move from fileInfoDetail
if (!noSelectedItem)
items = getters.fileInfoDetail
items.forEach(data => itemsToMove.push({
'force_delete': data.deleted_at ? true : false,
'unique_id': data.unique_id,
'type': data.type
}))
// Remove file preview
if (!noSelectedItem)
commit('CLEAR_FILEINFO_DETAIL')
// Get route
let route = getters.sharedDetail && !getters.sharedDetail.protected
? '/api/move/public/' + router.currentRoute.params.token
: '/api/move'
axios axios
.post(route, { .post(route, {
_method: 'post', from_type: item_from.type,
to_unique_id: to_item.unique_id, to_unique_id: to_item.unique_id,
items: itemsToMove _method: 'patch'
}) })
.then(() => { .then(() => {
itemsToMove.forEach(item => { commit('REMOVE_ITEM', item_from.unique_id)
commit('REMOVE_ITEM', item.unique_id)
commit('INCREASE_FOLDER_ITEM', to_item.unique_id) commit('INCREASE_FOLDER_ITEM', to_item.unique_id)
if (item.type === 'folder') if (item_from.type === 'folder' && getters.currentFolder.location !== 'public')
dispatch('getAppData') dispatch('getAppData')
if (getters.currentFolder.location === 'public')
dispatch('getFolderTree')
}) })
}) .catch(() => isSomethingWrong())
.catch(() => Vue.prototype.$isSomethingWrong())
}, },
createFolder: ({commit, getters, dispatch}, folderName) => { createFolder: ({commit, getters, dispatch}, folderName) => {
@@ -96,13 +45,11 @@ const actions = {
events.$emit('scrollTop') events.$emit('scrollTop')
if (getters.currentFolder.location !== 'public') if ( getters.currentFolder.location !== 'public' ) {
dispatch('getAppData') dispatch('getAppData')
if (getters.currentFolder.location === 'public') }
dispatch('getFolderTree')
}) })
.catch(() => Vue.prototype.$isSomethingWrong()) .catch(() => isSomethingWrong())
}, },
renameItem: ({commit, getters, dispatch}, data) => { renameItem: ({commit, getters, dispatch}, data) => {
@@ -126,10 +73,8 @@ const actions = {
if (data.type === 'folder' && getters.currentFolder.location !== 'public') if (data.type === 'folder' && getters.currentFolder.location !== 'public')
dispatch('getAppData') dispatch('getAppData')
if (data.type === 'folder' && getters.currentFolder.location === 'public')
dispatch('getFolderTree')
}) })
.catch(() => Vue.prototype.$isSomethingWrong()) .catch(() => isSomethingWrong())
}, },
uploadFiles: ({commit, getters}, {form, fileSize, totalUploadedSize}) => { uploadFiles: ({commit, getters}, {form, fileSize, totalUploadedSize}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -139,13 +84,8 @@ const actions = {
? '/api/upload/public/' + router.currentRoute.params.token ? '/api/upload/public/' + router.currentRoute.params.token
: '/api/upload' : '/api/upload'
// Create cancel token for axios cancelation
const CancelToken = axios.CancelToken
const source = CancelToken.source()
axios axios
.post(route, form, { .post(route, form, {
cancelToken: source.token,
headers: { headers: {
'Content-Type': 'application/octet-stream' 'Content-Type': 'application/octet-stream'
}, },
@@ -181,41 +121,32 @@ const actions = {
title: i18n.t('popup_exceed_limit.title'), title: i18n.t('popup_exceed_limit.title'),
message: i18n.t('popup_exceed_limit.message') message: i18n.t('popup_exceed_limit.message')
}) })
break break;
case 415: case 415:
events.$emit('alert:open', { events.$emit('alert:open', {
emoji: '😬😬😬', emoji: '😬😬😬',
title: i18n.t('popup_mimetypes_blacklist.title'), title: i18n.t('popup_mimetypes_blacklist.title'),
message: i18n.t('popup_mimetypes_blacklist.message') message: i18n.t('popup_mimetypes_blacklist.message')
}) })
break break;
case 413: case 413:
events.$emit('alert:open', { events.$emit('alert:open', {
emoji: '😟😟😟', emoji: '😟😟😟',
title: i18n.t('popup_paylod_error.title'), title: i18n.t('popup_upload_limit.title'),
message: i18n.t('popup_paylod_error.message') message: i18n.t('popup_upload_limit.message', {uploadLimit: getters.config.uploadLimitFormatted})
}) })
break break;
default: default:
events.$emit('alert:open', { events.$emit('alert:open', {
title: i18n.t('popup_error.title'), title: i18n.t('popup_error.title'),
message: i18n.t('popup_error.message') message: i18n.t('popup_error.message'),
}) })
break break;
} }
// Reset uploader // Reset uploader
commit('UPDATE_FILE_COUNT_PROGRESS', undefined) commit('UPDATE_FILE_COUNT_PROGRESS', undefined)
}) })
// Cancel the upload request
events.$on('cancel-upload', () => {
source.cancel()
// Hide upload progress bar
commit('PROCESSING_FILE', false)
commit('UPDATE_FILE_COUNT_PROGRESS', undefined)
})
}) })
}, },
restoreItem: ({commit, getters}, item) => { restoreItem: ({commit, getters}, item) => {
@@ -238,23 +169,9 @@ const actions = {
to_home: restoreToHome, to_home: restoreToHome,
_method: 'patch' _method: 'patch'
}) })
.catch(() => Vue.prototype.$isSomethingWrong()) .catch(() => isSomethingWrong())
}, },
deleteItem: ({ commit, getters, dispatch }, noSelectedItem) => { deleteItem: ({commit, getters, dispatch}, data) => {
let itemsToDelete = []
let items = [noSelectedItem]
// If coming no selected item dont get items to move from fileInfoDetail
if (!noSelectedItem)
items = getters.fileInfoDetail
items.forEach(data => {
itemsToDelete.push({
'force_delete': data.deleted_at ? true : false,
'type': data.type,
'unique_id': data.unique_id
})
// Remove file // Remove file
commit('REMOVE_ITEM', data.unique_id) commit('REMOVE_ITEM', data.unique_id)
@@ -266,36 +183,24 @@ const actions = {
commit('REMOVE_ITEM_FROM_FAVOURITES', data) commit('REMOVE_ITEM_FROM_FAVOURITES', data)
} }
// Remove file
commit('REMOVE_ITEM', data.unique_id)
// Remove item from sidebar
if (getters.permission === 'master') {
if (data.type === 'folder')
commit('REMOVE_ITEM_FROM_FAVOURITES', data)
}
})
// Remove file preview // Remove file preview
if (!noSelectedItem) {
commit('CLEAR_FILEINFO_DETAIL') commit('CLEAR_FILEINFO_DETAIL')
}
// Get route // Get route
let route = getters.sharedDetail && ! getters.sharedDetail.protected let route = getters.sharedDetail && ! getters.sharedDetail.protected
? '/api/remove-item/public/' + router.currentRoute.params.token ? '/api/remove-item/' + data.unique_id + '/public/' + router.currentRoute.params.token
: '/api/remove-item' : '/api/remove-item/' + data.unique_id
axios axios
.post(route, { .post(route, {
_method: 'post', _method: 'delete',
data: itemsToDelete data: {
type: data.type,
force_delete: data.deleted_at ? true : false,
},
}) })
.then(() => { .then(() => {
itemsToDelete.forEach(data => {
// If is folder, update app data // If is folder, update app data
if (data.type === 'folder') { if (data.type === 'folder') {
@@ -307,17 +212,12 @@ const actions = {
dispatch('getFolder', [{folder: last(getters.browseHistory), back: true, init: false}]) dispatch('getFolder', [{folder: last(getters.browseHistory), back: true, init: false}])
} }
} }
}
})
if ( getters.currentFolder.location !== 'public' ) if ( getters.currentFolder.location !== 'public' )
dispatch('getAppData') dispatch('getAppData')
}
if (getters.currentFolder.location === 'public')
dispatch('getFolderTree')
}) })
.catch(() => Vue.prototype.$isSomethingWrong()) .catch(() => isSomethingWrong())
}, },
emptyTrash: ({commit, getters}) => { emptyTrash: ({commit, getters}) => {
@@ -334,24 +234,25 @@ const actions = {
// Remove file preview // Remove file preview
commit('CLEAR_FILEINFO_DETAIL') commit('CLEAR_FILEINFO_DETAIL')
// Show success message
events.$emit('success:open', {
title: i18n.t('popup_trashed.title'),
message: i18n.t('popup_trashed.message'),
}) })
.catch(() => Vue.prototype.$isSomethingWrong()) })
} .catch(() => isSomethingWrong())
},
} }
const mutations = { // Show error message
ZIPPING_FILE_STATUS(state, status) { function isSomethingWrong() {
state.isZippingFiles = status events.$emit('alert:open', {
} title: i18n.t('popup_error.title'),
} message: i18n.t('popup_error.message'),
})
const getters = {
isZippingFiles: state => state.isZippingFiles
} }
export default { export default {
state: defaultState,
mutations,
actions, actions,
getters
} }