chore: Delayed deploy of direct uploads (#3966)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Tejaswini Chile 2022-02-15 16:16:54 +05:30 committed by GitHub
parent 2591a04c0b
commit 94a473c9f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 90 additions and 40 deletions

View file

@ -2,8 +2,11 @@
<file-upload
:size="4096 * 2048"
:accept="allowedFileTypes"
:data="{ direct_upload_url: '', direct_upload: true }"
@input-file="onDirectFileUpload"
:data="{
direct_upload_url: '/rails/active_storage/direct_uploads',
direct_upload: true,
}"
@input-file="onFileUpload"
>
<button class="icon-button flex items-center justify-center">
<fluent-icon v-if="!isUploading.image" icon="attach" />
@ -23,6 +26,7 @@ import {
import { BUS_EVENTS } from 'shared/constants/busEvents';
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
import { DirectUpload } from 'activestorage';
import { mapGetters } from 'vuex';
export default {
components: { FluentIcon, FileUpload, Spinner },
@ -36,6 +40,7 @@ export default {
return { isUploading: false };
},
computed: {
...mapGetters({ globalConfig: 'globalConfig/get' }),
fileUploadSizeLimit() {
return MAXIMUM_FILE_UPLOAD_SIZE;
},
@ -47,6 +52,13 @@ export default {
getFileType(fileType) {
return fileType.includes('image') ? 'image' : 'file';
},
async onFileUpload(file) {
if (this.globalConfig.directUploadsEnabled) {
this.onDirectFileUpload(file);
} else {
this.onIndirectFileUpload(file);
}
},
async onDirectFileUpload(file) {
if (!file) {
return;
@ -68,8 +80,8 @@ export default {
});
} else {
this.onAttach({
fileType: blob.content_type,
file: blob.signed_id,
...this.getLocalFileAttributes(file),
});
}
});
@ -85,18 +97,16 @@ export default {
}
this.isUploading = false;
},
async onFileUpload(file) {
async onIndirectFileUpload(file) {
if (!file) {
return;
}
this.isUploading = true;
try {
if (checkFileSizeLimit(file, MAXIMUM_FILE_UPLOAD_SIZE)) {
const thumbUrl = window.URL.createObjectURL(file.file);
await this.onAttach({
fileType: this.getFileType(file.type),
file: file.file,
thumbUrl,
...this.getLocalFileAttributes(file),
});
} else {
window.bus.$emit(BUS_EVENTS.SHOW_ALERT, {
@ -110,6 +120,12 @@ export default {
}
this.isUploading = false;
},
getLocalFileAttributes(file) {
return {
thumbUrl: window.URL.createObjectURL(file.file),
fileType: this.getFileType(file.type),
};
},
},
};
</script>