Truncate file size on the grid, validate extension in the attachment API.
This commit is contained in:
parent
5539ff9c9c
commit
f1aa32e446
|
@ -159,8 +159,10 @@
|
|||
{#if selectedImage.size}
|
||||
<div class="filesize">
|
||||
{#if selectedImage.size <= BYTES_IN_MB}
|
||||
{`${selectedImage.size / BYTES_IN_KB} KB`}
|
||||
{:else}{`${selectedImage.size / BYTES_IN_MB} MB`}{/if}
|
||||
{`${(selectedImage.size / BYTES_IN_KB).toFixed(1)} KB`}
|
||||
{:else}{`${(selectedImage.size / BYTES_IN_MB).toFixed(
|
||||
1
|
||||
)} MB`}{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if !disabled}
|
||||
|
@ -203,8 +205,8 @@
|
|||
{#if file.size}
|
||||
<div class="filesize">
|
||||
{#if file.size <= BYTES_IN_MB}
|
||||
{`${file.size / BYTES_IN_KB} KB`}
|
||||
{:else}{`${file.size / BYTES_IN_MB} MB`}{/if}
|
||||
{`${(file.size / BYTES_IN_KB).toFixed(1)} KB`}
|
||||
{:else}{`${(file.size / BYTES_IN_MB).toFixed(1)} MB`}{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if !disabled}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
import LinkedRowSelector from "components/common/LinkedRowSelector.svelte"
|
||||
import Editor from "../../integration/QueryEditor.svelte"
|
||||
import { ValidFileExtensions } from "@budibase/shared-core"
|
||||
import { admin } from "stores/portal"
|
||||
|
||||
export let defaultValue
|
||||
export let meta
|
||||
|
@ -21,7 +22,9 @@
|
|||
export let readonly
|
||||
export let error
|
||||
|
||||
let validExtensions = ValidFileExtensions.map(ext => `.${ext}`).join(", ")
|
||||
let validExtensions = $admin.cloud
|
||||
? ValidFileExtensions.map(ext => `.${ext}`).join(", ")
|
||||
: "*"
|
||||
|
||||
const resolveTimeStamp = timestamp => {
|
||||
if (!timestamp) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { ValidFileExtensions } from "@budibase/shared-core"
|
||||
|
||||
require("svelte/register")
|
||||
|
||||
import { join } from "../../../utilities/centralPath"
|
||||
|
@ -17,6 +19,7 @@ import fs from "fs"
|
|||
import sdk from "../../../sdk"
|
||||
import * as pro from "@budibase/pro"
|
||||
import { App, Ctx } from "@budibase/types"
|
||||
import environment from "../../../environment"
|
||||
|
||||
const send = require("koa-send")
|
||||
|
||||
|
@ -78,6 +81,17 @@ export const uploadFile = async function (ctx: Ctx) {
|
|||
|
||||
const uploads = files.map(async (file: any) => {
|
||||
const fileExtension = [...file.name.split(".")].pop()
|
||||
if (
|
||||
!environment.SELF_HOSTED &&
|
||||
!ValidFileExtensions.includes(fileExtension)
|
||||
) {
|
||||
ctx.throw(
|
||||
400,
|
||||
`Invalid file extension. Valid extensions are: ${ValidFileExtensions.join(
|
||||
", "
|
||||
)}`
|
||||
)
|
||||
}
|
||||
// filenames converted to UUIDs so they are unique
|
||||
const processedFileName = `${uuid.v4()}.${fileExtension}`
|
||||
|
||||
|
|
Loading…
Reference in New Issue