mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-04 05:05:58 +00:00
fixed upload files in the nested levels of folders
This commit is contained in:
@@ -95,5 +95,57 @@
|
||||
"/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~81c8aec0.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~81c8aec0.js?id=ca3b57f70682c1c315f7",
|
||||
"/vendors~chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser~chunks/shared/single-file.js": "/vendors~chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser~chunks/shared/single-file.js?id=9d10953d3b088324dfe3",
|
||||
"/vendors~chunks/platform~chunks/shared.js": "/vendors~chunks/platform~chunks/shared.js?id=7d09e0b0658e140a7ffa",
|
||||
"/js/main.a83f71a86d057a96f520.hot-update.js": "/js/main.a83f71a86d057a96f520.hot-update.js"
|
||||
"/js/main.8e8ffd0ba81aeef33d6f.hot-update.js": "/js/main.8e8ffd0ba81aeef33d6f.hot-update.js",
|
||||
"/vendors~chunks/admin~chunks/admin-account~chunks/app-email~chunks/app-payments~chunks/app-setup~chun~81d257bc.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-email~chunks/app-payments~chunks/app-setup~chun~81d257bc.js?id=a355eeae70079483b2f0",
|
||||
"/js/main.8fd0f5c79feac51ca836.hot-update.js": "/js/main.8fd0f5c79feac51ca836.hot-update.js",
|
||||
"/js/main.ac850e26c803bc37d0e7.hot-update.js": "/js/main.ac850e26c803bc37d0e7.hot-update.js",
|
||||
"/js/main.56968d9590188828b974.hot-update.js": "/js/main.56968d9590188828b974.hot-update.js",
|
||||
"/js/main.6e507680ff9cb59d1812.hot-update.js": "/js/main.6e507680ff9cb59d1812.hot-update.js",
|
||||
"/js/main.bb5b2df46132303e47b2.hot-update.js": "/js/main.bb5b2df46132303e47b2.hot-update.js",
|
||||
"/js/main.d6df0407d927b0cee586.hot-update.js": "/js/main.d6df0407d927b0cee586.hot-update.js",
|
||||
"/js/main.c88ddf3ec445bc769421.hot-update.js": "/js/main.c88ddf3ec445bc769421.hot-update.js",
|
||||
"/js/main.2fb5fcc038d0efa54a55.hot-update.js": "/js/main.2fb5fcc038d0efa54a55.hot-update.js",
|
||||
"/js/main.5ec59b1f352833e8f6bc.hot-update.js": "/js/main.5ec59b1f352833e8f6bc.hot-update.js",
|
||||
"/js/main.fd1a83fe6260bd08a03b.hot-update.js": "/js/main.fd1a83fe6260bd08a03b.hot-update.js",
|
||||
"/js/main.feab5acc4212d336ac9f.hot-update.js": "/js/main.feab5acc4212d336ac9f.hot-update.js",
|
||||
"/chunks/files~chunks/shared/file-browser.746c001dd01b9429f0c6.hot-update.js": "/chunks/files~chunks/shared/file-browser.746c001dd01b9429f0c6.hot-update.js",
|
||||
"/chunks/files~chunks/shared/file-browser.6bc336ded13783aaf435.hot-update.js": "/chunks/files~chunks/shared/file-browser.6bc336ded13783aaf435.hot-update.js",
|
||||
"/chunks/files~chunks/shared/file-browser.fe9a1e59dbe4d588314f.hot-update.js": "/chunks/files~chunks/shared/file-browser.fe9a1e59dbe4d588314f.hot-update.js",
|
||||
"/chunks/files~chunks/shared/file-browser.67532e7dcf43956a472c.hot-update.js": "/chunks/files~chunks/shared/file-browser.67532e7dcf43956a472c.hot-update.js",
|
||||
"/js/main.5a9727048bf1d93b00a8.hot-update.js": "/js/main.5a9727048bf1d93b00a8.hot-update.js",
|
||||
"/js/main.3b0b3a891a7097071040.hot-update.js": "/js/main.3b0b3a891a7097071040.hot-update.js",
|
||||
"/js/main.eb2c3d44bd70983275f2.hot-update.js": "/js/main.eb2c3d44bd70983275f2.hot-update.js",
|
||||
"/chunks/app-language~chunks/dashboard~chunks/invoices~chunks/pages~chunks/plans~chunks/settings~chunk~8e71da83.js": "/chunks/app-language~chunks/dashboard~chunks/invoices~chunks/pages~chunks/plans~chunks/settings~chunk~8e71da83.js?id=e4a472b95cf91533512c",
|
||||
"/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser.eb2c3d44bd70983275f2.hot-update.js": "/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser.eb2c3d44bd70983275f2.hot-update.js",
|
||||
"/chunks/files~chunks/shared/file-browser.eb2c3d44bd70983275f2.hot-update.js": "/chunks/files~chunks/shared/file-browser.eb2c3d44bd70983275f2.hot-update.js",
|
||||
"/chunks/platform~chunks/shared.eb2c3d44bd70983275f2.hot-update.js": "/chunks/platform~chunks/shared.eb2c3d44bd70983275f2.hot-update.js",
|
||||
"/chunks/platform~chunks/shared~chunks/shared/single-file.js": "/chunks/platform~chunks/shared~chunks/shared/single-file.js?id=b4399c659dbf9e871ddc",
|
||||
"/chunks/settings-subscription.eb2c3d44bd70983275f2.hot-update.js": "/chunks/settings-subscription.eb2c3d44bd70983275f2.hot-update.js",
|
||||
"/chunks/settings-subscription~chunks/user-subscription.js": "/chunks/settings-subscription~chunks/user-subscription.js?id=60b258958f6ccc222687",
|
||||
"/chunks/user-subscription.eb2c3d44bd70983275f2.hot-update.js": "/chunks/user-subscription.eb2c3d44bd70983275f2.hot-update.js",
|
||||
"/vendors~chunks/platform~chunks/shared~chunks/shared/single-file.js": "/vendors~chunks/platform~chunks/shared~chunks/shared/single-file.js?id=b00184c0940c415c5849",
|
||||
"/js/main.7dd28038776f414ab5d0.hot-update.js": "/js/main.7dd28038776f414ab5d0.hot-update.js",
|
||||
"/chunks/files.7dd28038776f414ab5d0.hot-update.js": "/chunks/files.7dd28038776f414ab5d0.hot-update.js",
|
||||
"/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser.7dd28038776f414ab5d0.hot-update.js": "/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser.7dd28038776f414ab5d0.hot-update.js",
|
||||
"/chunks/files~chunks/shared/file-browser.7dd28038776f414ab5d0.hot-update.js": "/chunks/files~chunks/shared/file-browser.7dd28038776f414ab5d0.hot-update.js",
|
||||
"/chunks/platform.7dd28038776f414ab5d0.hot-update.js": "/chunks/platform.7dd28038776f414ab5d0.hot-update.js",
|
||||
"/chunks/platform~chunks/shared.7dd28038776f414ab5d0.hot-update.js": "/chunks/platform~chunks/shared.7dd28038776f414ab5d0.hot-update.js",
|
||||
"/chunks/shared/single-file.7dd28038776f414ab5d0.hot-update.js": "/chunks/shared/single-file.7dd28038776f414ab5d0.hot-update.js",
|
||||
"/chunks/files~chunks/shared/file-browser.a3159c00aadb02c3f6b6.hot-update.js": "/chunks/files~chunks/shared/file-browser.a3159c00aadb02c3f6b6.hot-update.js",
|
||||
"/js/main.723db11ab0c0fa4414c1.hot-update.js": "/js/main.723db11ab0c0fa4414c1.hot-update.js",
|
||||
"/js/main.b260773e9944f6e8c0b0.hot-update.js": "/js/main.b260773e9944f6e8c0b0.hot-update.js",
|
||||
"/js/main.fdadae44626492668fc5.hot-update.js": "/js/main.fdadae44626492668fc5.hot-update.js",
|
||||
"/js/main.31a6a2a9ebf92e6d31ca.hot-update.js": "/js/main.31a6a2a9ebf92e6d31ca.hot-update.js",
|
||||
"/js/main.bb7d34653b773a8e6bd0.hot-update.js": "/js/main.bb7d34653b773a8e6bd0.hot-update.js",
|
||||
"/js/main.a258575aa03652d71a78.hot-update.js": "/js/main.a258575aa03652d71a78.hot-update.js",
|
||||
"/js/main.89b135af228a76b45177.hot-update.js": "/js/main.89b135af228a76b45177.hot-update.js",
|
||||
"/js/main.425b98bb22325c4e1104.hot-update.js": "/js/main.425b98bb22325c4e1104.hot-update.js",
|
||||
"/js/main.1316ccda17c905679bb0.hot-update.js": "/js/main.1316ccda17c905679bb0.hot-update.js",
|
||||
"/js/main.7330355487088a26b20e.hot-update.js": "/js/main.7330355487088a26b20e.hot-update.js",
|
||||
"/js/main.d2258ad33d25aaa8c46f.hot-update.js": "/js/main.d2258ad33d25aaa8c46f.hot-update.js",
|
||||
"/js/main.a480505cb3aa50f82a4f.hot-update.js": "/js/main.a480505cb3aa50f82a4f.hot-update.js",
|
||||
"/js/main.299e425d7c066bc6b7bc.hot-update.js": "/js/main.299e425d7c066bc6b7bc.hot-update.js",
|
||||
"/js/main.aa4c95d713f3e198d46d.hot-update.js": "/js/main.aa4c95d713f3e198d46d.hot-update.js",
|
||||
"/js/main.061e3452d4f227b98ded.hot-update.js": "/js/main.061e3452d4f227b98ded.hot-update.js",
|
||||
"/js/main.212f65475aa6c2d29f61.hot-update.js": "/js/main.212f65475aa6c2d29f61.hot-update.js"
|
||||
}
|
||||
|
||||
Vendored
+27
-33
@@ -185,16 +185,6 @@ const Helpers = {
|
||||
})
|
||||
}
|
||||
|
||||
// Push items to file queue
|
||||
// [...event.dataTransfer.items].map(item => {
|
||||
// console.log(item.getAsFile(), 'b')
|
||||
// this.$store.commit('ADD_FILES_TO_QUEUE', {
|
||||
// folder_id: parent_id ? parent_id : '',
|
||||
// file: item.getAsFile(),
|
||||
// })
|
||||
// });
|
||||
|
||||
|
||||
// Start uploading if uploading process isn't running
|
||||
if (this.$store.getters.filesInQueueTotal == 0)
|
||||
this.$handleUploading(this.$store.getters.fileQueue[0])
|
||||
@@ -203,6 +193,7 @@ const Helpers = {
|
||||
this.$store.commit('INCREASE_FILES_IN_QUEUES_TOTAL', items.length)
|
||||
}
|
||||
|
||||
// Get File from FileEntry
|
||||
Vue.prototype.$getFile = async function (fileEntry) {
|
||||
try {
|
||||
return await new Promise((resolve, reject) => fileEntry.file(resolve, reject));
|
||||
@@ -212,10 +203,11 @@ const Helpers = {
|
||||
}
|
||||
|
||||
Vue.prototype.$getAllFileEntries = async function (dataTransferItemList) {
|
||||
|
||||
let fileEntries = [];
|
||||
// Use BFS to traverse entire directory/file structure
|
||||
|
||||
let queue = [];
|
||||
// Unfortunately dataTransferItemList is not iterable i.e. no forEach
|
||||
|
||||
for (let i = 0; i < dataTransferItemList.length; i++) {
|
||||
queue.push(dataTransferItemList[i].webkitGetAsEntry());
|
||||
}
|
||||
@@ -224,32 +216,34 @@ const Helpers = {
|
||||
if (entry.isFile) {
|
||||
fileEntries.push(entry);
|
||||
} else if (entry.isDirectory) {
|
||||
queue.push(...await this.$readAllDirectoryEntries(entry.createReader()));
|
||||
queue.push(...await readAllDirectoryEntries(entry.createReader()));
|
||||
}
|
||||
}
|
||||
|
||||
async function readAllDirectoryEntries (directoryReader) {
|
||||
|
||||
let entries = [];
|
||||
let readEntries = await readEntriesPromise(directoryReader);
|
||||
while (readEntries.length > 0) {
|
||||
entries.push(...readEntries);
|
||||
readEntries = await readEntriesPromise(directoryReader);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
async function readEntriesPromise (directoryReader) {
|
||||
|
||||
try {
|
||||
return await new Promise((resolve, reject) => {
|
||||
directoryReader.readEntries(resolve, reject);
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
return fileEntries;
|
||||
}
|
||||
|
||||
Vue.prototype.$readAllDirectoryEntries = async function (directoryReader) {
|
||||
let entries = [];
|
||||
let readEntries = await this.$readEntriesPromise(directoryReader);
|
||||
while (readEntries.length > 0) {
|
||||
entries.push(...readEntries);
|
||||
readEntries = await this.$readEntriesPromise(directoryReader);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
Vue.prototype.$readEntriesPromise = async function (directoryReader) {
|
||||
try {
|
||||
return await new Promise((resolve, reject) => {
|
||||
directoryReader.readEntries(resolve, reject);
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
Vue.prototype.$handleUploading = async function (item) {
|
||||
|
||||
// Create ceil
|
||||
|
||||
+7
-2
@@ -164,7 +164,7 @@ const actions = {
|
||||
})
|
||||
.catch(() => Vue.prototype.$isSomethingWrong())
|
||||
},
|
||||
uploadFiles: ({commit, getters}, {form, fileSize, totalUploadedSize}) => {
|
||||
uploadFiles: ({commit, getters, dispatch}, {form, fileSize, totalUploadedSize}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// Get route
|
||||
@@ -222,8 +222,13 @@ const actions = {
|
||||
}
|
||||
|
||||
// Reset upload process
|
||||
if (!getters.fileQueue.length)
|
||||
if (!getters.fileQueue.length) {
|
||||
|
||||
commit('CLEAR_UPLOAD_PROGRESS')
|
||||
|
||||
// Reload files after upload is done
|
||||
dispatch('getFolder', [{folder: getters.currentFolder, back: true, init: false}])
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Domain\Files\Actions;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -11,7 +10,6 @@ use Domain\Files\Requests\UploadRequest;
|
||||
use Domain\Files\Models\File as UserFile;
|
||||
use Domain\Traffic\Actions\RecordUploadAction;
|
||||
use App\Users\Actions\CheckStorageCapacityAction;
|
||||
use Facade\Ignition\DumpRecorder\Dump;
|
||||
|
||||
class UploadFileAction
|
||||
{
|
||||
@@ -103,6 +101,9 @@ class UploadFileAction
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create structure fot the Folder upload
|
||||
*/
|
||||
private function create_folder_structure ($path, $parent, $user_id)
|
||||
{
|
||||
$folders = array_slice(explode('/', $path), 1, -1);
|
||||
@@ -113,47 +114,47 @@ class UploadFileAction
|
||||
|
||||
$structure = Folder::whereIn('name', $folders)->with('parent')->get();
|
||||
|
||||
try {
|
||||
if( count($folders) > 0) {
|
||||
|
||||
if( count($folders) > 0) {
|
||||
|
||||
if( !$structure->isEmpty() || count($folders) == count($structure) && $this->check_folder_structure($structure, $folders)) {
|
||||
if(count($folders) === count($structure) ) {
|
||||
|
||||
$last_folder = $this->check_folder_structure($structure, $folders);
|
||||
$last_folder = $this->check_folder_structure($structure, $folders);
|
||||
|
||||
} else if (count($folders) !== count($structure)) {
|
||||
|
||||
// dd($last_folder, $parent_id, $path, 'struc');
|
||||
|
||||
|
||||
} else if (count($folders) != count($structure)) {
|
||||
if(count($structure) > 0) {
|
||||
|
||||
foreach($folders as $folder) {
|
||||
|
||||
$new_folder = Folder::create([
|
||||
'name' => $folder,
|
||||
'parent_id' => $parent_id,
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
|
||||
$parent_id = $new_folder->id;
|
||||
|
||||
$last_folder = $new_folder->id;
|
||||
};
|
||||
$data = $this->check_exist_folders($structure, $folders);
|
||||
|
||||
$folders = $data[0];
|
||||
|
||||
$parent_id = $data[1];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// dd($last_folder, $parent_id, $path);
|
||||
// dd(count($folders), count($structure));
|
||||
}
|
||||
// else if ( count($folders) > 0 ) {
|
||||
// $test = Folder::whereName($folders[-1])->with('name', '=' , $folder[count($folder) - 1]);
|
||||
foreach($folders as $folder) {
|
||||
|
||||
// };
|
||||
$new_folder = Folder::create([
|
||||
'name' => $folder,
|
||||
'parent_id' => $parent_id,
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
|
||||
$parent_id = $new_folder->id;
|
||||
|
||||
$last_folder = $new_folder->id;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return $last_folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if is the structure correct
|
||||
*/
|
||||
private function check_folder_structure($structure, $folders)
|
||||
{
|
||||
|
||||
@@ -167,6 +168,7 @@ class UploadFileAction
|
||||
|
||||
$parent = $item->pluck('parent')->pluck('name')[0];
|
||||
|
||||
// Check if folder have valid parent name
|
||||
if( $parent && $folder === $parent_name || $parent_name == '') {
|
||||
|
||||
$parent_name = $parent;
|
||||
@@ -180,11 +182,35 @@ class UploadFileAction
|
||||
}
|
||||
|
||||
if($validate) {
|
||||
|
||||
return $structure->where('name', $folders[array_key_last($folders)])->first()->id;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the folders that is need to create in already created structure and last created parent
|
||||
*/
|
||||
private function check_exist_folders($structure, $folders)
|
||||
{
|
||||
|
||||
$create_folders = [];
|
||||
$last_parent = '';
|
||||
|
||||
foreach($folders as $folder) {
|
||||
|
||||
// Filter folders that is need to create
|
||||
if(! $structure->where('name', $folder)->first()) {
|
||||
array_push($create_folders, $folder);
|
||||
}else {
|
||||
|
||||
// Find last created folder
|
||||
$last_parent = $structure->where('name', $folder)->first()->id;
|
||||
}
|
||||
}
|
||||
|
||||
return [$create_folders, $last_parent];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user