Adding max file size limit

This commit is contained in:
Jesús Espino 2022-03-29 13:09:39 +02:00
parent 8212e5401e
commit 837859838c
6 changed files with 26 additions and 4 deletions

View file

@ -219,6 +219,7 @@ func (p *Plugin) createBoardsConfig(mmconfig mmModel.Config, baseURL string, ser
FilesDriver: *mmconfig.FileSettings.DriverName,
FilesPath: *mmconfig.FileSettings.Directory,
FilesS3Config: filesS3Config,
MaxFileSize: *mmconfig.FileSettings.MaxFileSize,
Telemetry: enableTelemetry,
TelemetryID: serverID,
WebhookUpdate: []string{},

View file

@ -1981,9 +1981,13 @@ func (a *API) handleUploadFile(w http.ResponseWriter, r *http.Request) {
return
}
if a.app.GetConfig().MaxFileSize > 0 {
r.Body = http.MaxBytesReader(w, r.Body, a.app.GetConfig().MaxFileSize)
}
file, handle, err := r.FormFile(UploadFormFileKey)
if err != nil {
fmt.Fprintf(w, "%v", err)
a.errorResponse(w, r.URL.Path, http.StatusRequestEntityTooLarge, "", err)
return
}
defer file.Close()

View file

@ -53,6 +53,10 @@ func (a *App) SetConfig(config *config.Configuration) {
a.config = config
}
func (a *App) GetConfig() *config.Configuration {
return a.config
}
func New(config *config.Configuration, wsAdapter ws.Adapter, services Services) *App {
app := &App{
config: config,

View file

@ -37,6 +37,7 @@ type Configuration struct {
FilesDriver string `json:"filesdriver" mapstructure:"filesdriver"`
FilesS3Config AmazonS3Config `json:"filess3config" mapstructure:"filess3config"`
FilesPath string `json:"filespath" mapstructure:"filespath"`
MaxFileSize int64 `json:"maxfilesize" mapstructure:"mafilesize"`
Telemetry bool `json:"telemetry" mapstructure:"telemetry"`
TelemetryID string `json:"telemetryid" mapstructure:"telemetryid"`
PrometheusAddress string `json:"prometheus_address" mapstructure:"prometheus_address"`

View file

@ -4,6 +4,7 @@
import {useEffect, useCallback} from 'react'
import {ImageBlock, createImageBlock} from '../../blocks/imageBlock'
import {sendFlashMessage} from '../flashMessages'
import octoClient from '../../octoClient'
import mutator from '../../mutator'
@ -25,8 +26,10 @@ export default function useImagePaste(boardId: string, cardId: string, contentOr
const uploaded = await Promise.all(uploads)
const blocksToInsert: ImageBlock[] = []
let someFilesNotUploaded = false
for (const fileId of uploaded) {
if (!fileId) {
someFilesNotUploaded = true
continue
}
const block = createImageBlock()
@ -36,6 +39,10 @@ export default function useImagePaste(boardId: string, cardId: string, contentOr
blocksToInsert.push(block)
}
if (someFilesNotUploaded) {
sendFlashMessage({content: "Some files not uploaded. File size limit reached", severity: 'normal'})
}
mutator.performAsUndoGroup(async () => {
const newContentBlocks = await mutator.insertBlocks(boardId, blocksToInsert, 'pasted images')
const newContentOrder = JSON.parse(JSON.stringify(contentOrder))

View file

@ -7,6 +7,7 @@ import {ImageBlock, createImageBlock} from '../../blocks/imageBlock'
import octoClient from '../../octoClient'
import {Utils} from '../../utils'
import ImageIcon from '../../widgets/icons/image'
import {sendFlashMessage} from '../../components/flashMessages'
import {contentRegistry} from './contentRegistry'
@ -52,9 +53,13 @@ contentRegistry.registerContentType({
Utils.selectLocalFile(async (file) => {
const fileId = await octoClient.uploadFile(boardId, file)
const block = createImageBlock()
block.fields.fileId = fileId || ''
resolve(block)
if (fileId) {
const block = createImageBlock()
block.fields.fileId = fileId || ''
resolve(block)
} else {
sendFlashMessage({content: 'Unable to upload the file. File size limit reached.', severity: 'normal'})
}
},
'.jpg,.jpeg,.png,.gif')
},