mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
Merge pull request #272 from bknd-io/feat/media-add-body-max
feat: add media option to module to restrict body max size
This commit is contained in:
@@ -49,6 +49,8 @@ export function registerMedia(
|
|||||||
* @todo: add tests (bun tests won't work, need node native tests)
|
* @todo: add tests (bun tests won't work, need node native tests)
|
||||||
*/
|
*/
|
||||||
export class StorageR2Adapter extends StorageAdapter {
|
export class StorageR2Adapter extends StorageAdapter {
|
||||||
|
public keyPrefix: string = "";
|
||||||
|
|
||||||
constructor(private readonly bucket: R2Bucket) {
|
constructor(private readonly bucket: R2Bucket) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -175,7 +177,7 @@ export class StorageR2Adapter extends StorageAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getKey(key: string) {
|
protected getKey(key: string) {
|
||||||
return key;
|
return `${this.keyPrefix}/${key}`.replace(/^\/\//, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON(secrets?: boolean) {
|
toJSON(secrets?: boolean) {
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ declare module "bknd" {
|
|||||||
// @todo: current workaround to make it all required
|
// @todo: current workaround to make it all required
|
||||||
export class AppMedia extends Module<Required<TAppMediaConfig>> {
|
export class AppMedia extends Module<Required<TAppMediaConfig>> {
|
||||||
private _storage?: Storage;
|
private _storage?: Storage;
|
||||||
|
options = {
|
||||||
|
body_max_size: null as number | null,
|
||||||
|
};
|
||||||
|
|
||||||
override async build() {
|
override async build() {
|
||||||
if (!this.config.enabled) {
|
if (!this.config.enabled) {
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ export class MediaController extends Controller {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const maxSize = this.getStorage().getConfig().body_max_size ?? Number.POSITIVE_INFINITY;
|
const maxSize =
|
||||||
|
this.media.options.body_max_size ??
|
||||||
|
this.getStorage().getConfig().body_max_size ??
|
||||||
|
Number.POSITIVE_INFINITY;
|
||||||
|
|
||||||
if (isDebug()) {
|
if (isDebug()) {
|
||||||
hono.post(
|
hono.post(
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export function buildMediaSchema() {
|
|||||||
{
|
{
|
||||||
default: {},
|
default: {},
|
||||||
},
|
},
|
||||||
);
|
).strict();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mediaConfigSchema = buildMediaSchema();
|
export const mediaConfigSchema = buildMediaSchema();
|
||||||
|
|||||||
Reference in New Issue
Block a user