From 2cf2c8cd11db91c66bfa93e52177d29c44c4ac9e Mon Sep 17 00:00:00 2001 From: "Buster \"Silver Eagle\" Neece" Date: Mon, 6 Jun 2022 04:06:28 -0500 Subject: [PATCH] Fix some issues with Flow uploads. --- frontend/vue/components/Common/FlowUpload.vue | 7 ++- .../components/Stations/Media/FileUpload.vue | 11 ++-- src/Service/Flow.php | 53 +++++++------------ 3 files changed, 30 insertions(+), 41 deletions(-) diff --git a/frontend/vue/components/Common/FlowUpload.vue b/frontend/vue/components/Common/FlowUpload.vue index 4081fa8c8..7150a7939 100644 --- a/frontend/vue/components/Common/FlowUpload.vue +++ b/frontend/vue/components/Common/FlowUpload.vue @@ -2,7 +2,7 @@
+ v-if="file.is_visible" :class="{ 'text-success': file.is_completed, 'text-danger': file.error }">
{{ file.name }}
@@ -113,6 +113,7 @@ export default { uploadMethod: 'POST', testMethod: 'GET', method: 'multipart', + maxChunkRetries: 3, testChunks: false }; let config = _.defaultsDeep({}, this.flowConfiguration, defaultConfig); @@ -165,6 +166,10 @@ export default { }); this.flow.on('complete', () => { + _.forEach(this.files, (file) => { + file.is_visible = false; + }); + this.$emit('complete'); }); }, diff --git a/frontend/vue/components/Stations/Media/FileUpload.vue b/frontend/vue/components/Stations/Media/FileUpload.vue index 7ccbec8dc..7607d477f 100644 --- a/frontend/vue/components/Stations/Media/FileUpload.vue +++ b/frontend/vue/components/Stations/Media/FileUpload.vue @@ -10,28 +10,27 @@ import FlowUpload from '~/components/Common/FlowUpload'; export default { name: 'FileUpload', - components: { FlowUpload }, + components: {FlowUpload}, props: { uploadUrl: String, currentDirectory: String, searchPhrase: String, validMimeTypes: { type: Array, - default () { + default() { return ['audio/*']; } } }, - data () { + data() { return { flow: null, files: [] }; }, computed: { - flowConfiguration () { + flowConfiguration() { return { - testChunks: true, query: () => { return { 'currentDirectory': this.currentDirectory, @@ -42,7 +41,7 @@ export default { } }, methods: { - onFlowUpload () { + onFlowUpload() { this.$emit('relist'); } } diff --git a/src/Service/Flow.php b/src/Service/Flow.php index 4b3e35770..eb52921ab 100644 --- a/src/Service/Flow.php +++ b/src/Service/Flow.php @@ -120,14 +120,22 @@ class Flow $file->moveTo($chunkPath); - if ($flowChunkNumber === $targetChunks && self::allPartsExist($chunkBaseDir, $targetSize, $targetChunks)) { - return self::createFileFromChunks( - $tempDir, - $chunkBaseDir, - $flowIdentifier, - $flowFilename, - $targetChunks - ); + clearstatcache(); + + if ($flowChunkNumber === $targetChunks) { + // Handle last chunk. + if (self::allPartsExist($chunkBaseDir, $targetSize, $targetChunks)) { + return self::createFileFromChunks( + $tempDir, + $chunkBaseDir, + $flowIdentifier, + $flowFilename, + $targetChunks + ); + } + + // Upload succeeded, but re-trigger upload anyway for the above. + return $response->withStatus(204, 'No Content'); } // Return an OK status to indicate that the chunk upload itself succeeded. @@ -218,33 +226,10 @@ class Flow // rename the temporary directory (to avoid access from other // concurrent chunk uploads) and then delete it. - if (rename($chunkBaseDir, $chunkBaseDir . '_UNUSED')) { - self::rrmdir($chunkBaseDir . '_UNUSED'); - } else { - self::rrmdir($chunkBaseDir); - } + (new Filesystem())->remove([ + $chunkBaseDir, + ]); return $uploadedFile; } - - /** - * Delete a directory RECURSIVELY - * - * @param string $dir - directory path - * - * @link http://php.net/manual/en/function.rmdir.php - */ - protected static function rrmdir(string $dir): void - { - if (is_dir($dir)) { - foreach (array_diff(scandir($dir, SCANDIR_SORT_NONE) ?: [], ['.', '..']) as $object) { - if (is_dir($dir . '/' . $object)) { - self::rrmdir($dir . '/' . $object); - } else { - unlink($dir . '/' . $object); - } - } - rmdir($dir); - } - } }