diff --git a/web-app/packages/lib/src/modules/project/components/FileDetailSidebar.vue b/web-app/packages/lib/src/modules/project/components/FileDetailSidebar.vue index 9aec4dfa..4dcec5ee 100644 --- a/web-app/packages/lib/src/modules/project/components/FileDetailSidebar.vue +++ b/web-app/packages/lib/src/modules/project/components/FileDetailSidebar.vue @@ -56,15 +56,23 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-MerginMaps-Commercial - + +

+ File too large to preview — download to view instead. +

- +
{{ content }}
@@ -104,6 +112,7 @@ enum State { UPDATED = 'updated' } +const MAX_PREVIEW_FILE_SIZE = 40000000 // 20MB export default defineComponent({ name: 'FileDetailSidebar', props: { @@ -164,6 +173,9 @@ export default defineComponent({ filePath(): string { return this.$route.query.file_path as string }, + isOverLimit() { + return this.file.size > MAX_PREVIEW_FILE_SIZE + }, sidebarVisible: { get() { return !!this.filePath && !!this.file @@ -194,13 +206,19 @@ export default defineComponent({ this.txtPreview() return } - this.sidebarVisible = false + this.cleanup() } } }, methods: { ...mapActions(useProjectStore, ['deleteFiles']), txtPreview() { + if (this.isOverLimit) { + this.content = null + this.mimetype = null + return + } + ProjectApi.getProjectFileByUrl(this.downloadUrl).then((resp) => { this.mimetype = resp.headers['content-type'] if (resp.headers['content-type'].match('text')) { @@ -225,6 +243,11 @@ export default defineComponent({ }, downloadFile() { window.location.href = this.downloadUrl + }, + cleanup() { + this.sidebarVisible = false + this.content = null + this.mimetype = null } }, components: { AppSidebarRight, FileIcon }