Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upload): fix upload for large files #467

Merged
merged 2 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/tailored/core/fileupload/FileUpload.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
:src="item.url"
v-bind:class="{ 'img-blur': item.nsfw.status }"
/>
<UiLoadersLogoLoader v-if="!item.url" :size="48" />
</div>
<file-icon
size="1x"
Expand Down
2 changes: 2 additions & 0 deletions components/tailored/core/fileupload/FileUpload.less
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
.img-wrapper {
max-width: 15vw;
max-height: 10vh;
min-width: 64px;
min-height: 64px;
border-radius: 2px;
margin-right: @normal-spacing;
overflow: hidden;
Expand Down
27 changes: 16 additions & 11 deletions components/tailored/core/fileupload/FileUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<script lang="ts">
import Vue from 'vue'
import { Config } from '~/config'

import {
FileIcon,
Expand Down Expand Up @@ -55,21 +56,27 @@ export default Vue.extend({
this.$data.files = [...files].map((file: File) => {
return {
file,
nsfw: { status: false, checking: false },
nsfw: { status: false, checking: false, tooLarge: false },
url: '',
}
})
/* nsfw checking after putting all files */
for (const file of this.$data.files) {
file.nsfw.checking = true
try {
file.nsfw.status = await this.$Security.isNSFW(file.file)
} catch (err) {
file.nsfw.status = true
// don't check nsfw for large files or webgl runs out of memory
if (file.file.size > Config.uploadByteLimit) {
file.nsfw.tooLarge = true
}
if (!file.nsfw.tooLarge) {
file.nsfw.checking = true
try {
file.nsfw.status = await this.$Security.isNSFW(file.file)
} catch (err) {
file.nsfw.status = true
file.nsfw.checking = false
return
}
file.nsfw.checking = false
return
}
file.nsfw.checking = false
this.loadPicture(file)
}
this.$data.uploadStatus = true
Expand Down Expand Up @@ -99,9 +106,7 @@ export default Vue.extend({
isEmbedableImage(filename: string): boolean {
if (!filename) return false
// eslint-disable-next-line prefer-regex-literals
const imageFormatsRegex = new RegExp(
'^.*.(apng|avif|gif|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp)$'
)
const imageFormatsRegex = new RegExp(Config.regex.image)
return imageFormatsRegex.test(filename.toLowerCase())
},
/**
Expand Down
7 changes: 3 additions & 4 deletions components/tailored/files/uploader/Uploader.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template src="./Uploader.html"></template>
<script lang="ts">
import Vue from 'vue'
import { Config } from '~/config'

import { FileIcon, SlashIcon } from 'satellite-lucide-icons'

Expand Down Expand Up @@ -33,7 +34,7 @@ export default Vue.extend({
nsfw: {
type: Object,
// eslint-disable-next-line vue/require-valid-default-prop
default: { status: false, checking: false },
default: { status: false, checking: false, tooLarge: false },
},
},
methods: {
Expand All @@ -50,9 +51,7 @@ export default Vue.extend({
*/
isEmbedableImage(filename: string): boolean {
// eslint-disable-next-line prefer-regex-literals
const imageFormatsRegex = new RegExp(
'^.*.(apng|avif|gif|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp)$'
)
const imageFormatsRegex = new RegExp(Config.regex.image)
return imageFormatsRegex.test(filename.toLowerCase())
},
},
Expand Down
4 changes: 4 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ export const Config = {
routingMiddleware: {
prerequisitesCheckBypass: ['auth', 'setup'],
},
uploadByteLimit: 1048576 * 8, // 8mb
InfamousVague marked this conversation as resolved.
Show resolved Hide resolved
regex: {
image: '^.*.(apng|avif|gif|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp)$',
},
}