formidable: Add support for site-specific filesize
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
afde7fb89a
commit
d1bab7a929
3 changed files with 47 additions and 1 deletions
|
@ -39,6 +39,12 @@ export function uploadFile(ctx, siteName, noprefix = false) {
|
||||||
form.uploadDir = `${config.get('uploadFolder')}/${siteName}`
|
form.uploadDir = `${config.get('uploadFolder')}/${siteName}`
|
||||||
form.maxFileSize = config.get('fileSize')
|
form.maxFileSize = config.get('fileSize')
|
||||||
|
|
||||||
|
let siteSize = config.get(`sites:${siteName}:fileSize`)
|
||||||
|
|
||||||
|
if (siteSize && typeof(siteSize) === 'number') {
|
||||||
|
form.maxFileSize = siteSize
|
||||||
|
}
|
||||||
|
|
||||||
form.parse(ctx.req, function(err, fields, files) {
|
form.parse(ctx.req, function(err, fields, files) {
|
||||||
if (err) return rej(err)
|
if (err) return rej(err)
|
||||||
if (!files || !files.file) return rej(new HttpError(422, 'File in body was missing'))
|
if (!files || !files.file) return rej(new HttpError(422, 'File in body was missing'))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "storage-upload",
|
"name": "storage-upload",
|
||||||
"version": "2.2.11",
|
"version": "2.2.12",
|
||||||
"description": "Micro service for uploading and image resizing files to a storage server.",
|
"description": "Micro service for uploading and image resizing files to a storage server.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -99,6 +99,17 @@ t.timeout(10000).describe('Media (API)', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.describe('POST /media', function temp() {
|
t.describe('POST /media', function temp() {
|
||||||
|
let config
|
||||||
|
|
||||||
|
t.before(async () => {
|
||||||
|
config = (await import('../../api/config.mjs')).default
|
||||||
|
})
|
||||||
|
|
||||||
|
t.afterEach(function() {
|
||||||
|
config.sources[2].store.fileSize = 524288000
|
||||||
|
delete config.sources[1].store.sites.development.fileSize
|
||||||
|
})
|
||||||
|
|
||||||
t.test('should require authentication', async () => {
|
t.test('should require authentication', async () => {
|
||||||
resetLog()
|
resetLog()
|
||||||
assert.strictEqual(log.error.callCount, 0)
|
assert.strictEqual(log.error.callCount, 0)
|
||||||
|
@ -276,6 +287,35 @@ t.timeout(10000).describe('Media (API)', () => {
|
||||||
assert.strictEqual(img.height, 700)
|
assert.strictEqual(img.height, 700)
|
||||||
assert.strictEqual(img.format, 'png')
|
assert.strictEqual(img.format, 'png')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.test('should support site-specific fileSize', async () => {
|
||||||
|
let token = encode(null, { iss: 'development' }, secret)
|
||||||
|
|
||||||
|
config.sources[2].store.fileSize = 1000
|
||||||
|
|
||||||
|
let err = await assert.isRejected(
|
||||||
|
client.upload(
|
||||||
|
`/media?token=${token}`,
|
||||||
|
resolve('test.png')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert.match(err.message, /maxFileSize exceeded/)
|
||||||
|
|
||||||
|
config.sources[1].store.sites.development.fileSize = 524288000
|
||||||
|
|
||||||
|
let data = await assert.isFulfilled(
|
||||||
|
client.upload(
|
||||||
|
`/media?token=${token}`,
|
||||||
|
resolve('test.png')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
testFiles.push(data.path)
|
||||||
|
|
||||||
|
assert.ok(data)
|
||||||
|
assert.ok(data.filename)
|
||||||
|
assert.ok(data.filename.startsWith(currYear))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.describe('POST /media/noprefix', function temp() {
|
t.describe('POST /media/noprefix', function temp() {
|
||||||
|
|
Loading…
Reference in a new issue