Skip to content

Commit

Permalink
refactor: No significant change
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed Jan 2, 2024
1 parent 681cafc commit d150a9c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
22 changes: 1 addition & 21 deletions src/runtime/server/api/mutation/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readMultipartFormData, createError } from 'h3'
import { normalizeKey, getKey, getMeta, verifySize, verifyType } from '../../utils'
import { defineEventHandler, useRuntimeConfig } from '#imports'
import { normalizeKey, getKey, getMeta } from '#s3'

export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
Expand Down Expand Up @@ -28,23 +28,3 @@ export default defineEventHandler(async (event) => {

throw createError('invalid-file')
})

function verifyType (type: string | undefined, accept: string) {
const regex = new RegExp(accept)

if (!type || !regex.test(type)) {
throw createError({
message: 'invalid-type',
status: 400
})
}
}

function verifySize (size: number, maxSizeMb: number) {
if (maxSizeMb && size > maxSizeMb * 1000000) {
throw createError({
message: 'invalid-size',
status: 400
})
}
}
2 changes: 1 addition & 1 deletion src/runtime/server/api/mutation/delete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getKey, normalizeKey } from '../../utils'
import { defineEventHandler } from '#imports'
import { getKey, normalizeKey } from '#s3'

export default defineEventHandler(async (event) => {
const key = getKey(event)
Expand Down
22 changes: 21 additions & 1 deletion src/runtime/server/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,24 @@ async function getMeta (event: H3Event) {
}
}

export { normalizeKey, denormalizeKey, getKey, getMeta }
function verifyType (type: string | undefined, accept: string) {
const regex = new RegExp(accept)

if (!type || !regex.test(type)) {
throw createError({
message: 'invalid-type',
status: 400
})
}
}

function verifySize (size: number, maxSizeMb: number) {
if (maxSizeMb && size > maxSizeMb * 1000000) {
throw createError({
message: 'invalid-size',
status: 400
})
}
}

export { normalizeKey, denormalizeKey, getKey, getMeta, verifySize, verifyType }

0 comments on commit d150a9c

Please sign in to comment.