Fix some issues with Flow uploads.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-06-06 04:06:28 -05:00
parent c3dc771c02
commit 2cf2c8cd11
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
3 changed files with 30 additions and 41 deletions

View File

@ -2,7 +2,7 @@
<div class="flow-upload">
<div class="upload-progress">
<div class="uploading-file pt-1" v-for="(file, _) in files" :id="'file_upload_' + file.uniqueIdentifier"
:class="{ 'text-success': file.is_completed, 'text-danger': file.error }">
v-if="file.is_visible" :class="{ 'text-success': file.is_completed, 'text-danger': file.error }">
<h6 class="fileuploadname m-0">{{ file.name }}</h6>
<b-progress v-if="!file.is_completed" :value="file.progress_percent" :max="100"
show-progress class="h-15 my-1"></b-progress>
@ -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');
});
},

View File

@ -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');
}
}

View File

@ -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);
}
}
}