mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
improve media mime type inferring + added uploadToEntity in media api
This commit is contained in:
@@ -14,10 +14,17 @@ export class EventListener<E extends Event = Event> {
|
||||
event: EventClass;
|
||||
handler: ListenerHandler<E>;
|
||||
once: boolean = false;
|
||||
id?: string;
|
||||
|
||||
constructor(event: EventClass, handler: ListenerHandler<E>, mode: ListenerMode = "async") {
|
||||
constructor(
|
||||
event: EventClass,
|
||||
handler: ListenerHandler<E>,
|
||||
mode: ListenerMode = "async",
|
||||
id?: string
|
||||
) {
|
||||
this.event = event;
|
||||
this.handler = handler;
|
||||
this.mode = mode;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ export type RegisterListenerConfig =
|
||||
| {
|
||||
mode?: ListenerMode;
|
||||
once?: boolean;
|
||||
id?: string;
|
||||
};
|
||||
|
||||
export interface EmitsEvents {
|
||||
@@ -124,6 +125,14 @@ export class EventManager<
|
||||
addListener(listener: EventListener) {
|
||||
this.throwIfEventNotRegistered(listener.event);
|
||||
|
||||
if (listener.id) {
|
||||
const existing = this.listeners.find((l) => l.id === listener.id);
|
||||
if (existing) {
|
||||
console.warn(`Listener with id "${listener.id}" already exists.`);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
this.listeners.push(listener);
|
||||
return this;
|
||||
}
|
||||
@@ -140,6 +149,9 @@ export class EventManager<
|
||||
if (config.once) {
|
||||
listener.once = true;
|
||||
}
|
||||
if (config.id) {
|
||||
listener.id = `${event.slug}-${config.id}`;
|
||||
}
|
||||
this.addListener(listener as any);
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ export async function blobToFile(
|
||||
if (isFile(blob)) return blob;
|
||||
if (!isBlob(blob)) throw new Error("Not a Blob");
|
||||
|
||||
const type = !isMimeType(overrides.type, ["application/octet-stream"])
|
||||
const type = isMimeType(overrides.type, ["application/octet-stream"])
|
||||
? overrides.type
|
||||
: await detectMimeType(blob);
|
||||
const ext = type ? extension(type) : "";
|
||||
|
||||
Reference in New Issue
Block a user