mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
added format command and added trailing commas to reduce conflicts
This commit is contained in:
@@ -3,7 +3,7 @@ import {
|
||||
type BaseModuleApiOptions,
|
||||
ModuleApi,
|
||||
type PrimaryFieldType,
|
||||
type TInput
|
||||
type TInput,
|
||||
} from "modules/ModuleApi";
|
||||
import type { FileWithPath } from "ui/elements/media/file-selector";
|
||||
|
||||
@@ -12,7 +12,7 @@ export type MediaApiOptions = BaseModuleApiOptions & {};
|
||||
export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
protected override getDefaultOptions(): Partial<MediaApiOptions> {
|
||||
return {
|
||||
basepath: "/api/media"
|
||||
basepath: "/api/media",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
getFile(filename: string) {
|
||||
return this.get<ReadableStream<Uint8Array>>(["file", filename], undefined, {
|
||||
headers: {
|
||||
Accept: "*/*"
|
||||
}
|
||||
Accept: "*/*",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
|
||||
getUploadHeaders(): Headers {
|
||||
return new Headers({
|
||||
Authorization: `Bearer ${this.options.token}`
|
||||
Authorization: `Bearer ${this.options.token}`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
filename?: string;
|
||||
path?: TInput;
|
||||
_init?: Omit<RequestInit, "body">;
|
||||
}
|
||||
},
|
||||
) {
|
||||
const headers = {
|
||||
"Content-Type": "application/octet-stream",
|
||||
...(opts?._init?.headers || {})
|
||||
...(opts?._init?.headers || {}),
|
||||
};
|
||||
let name: string = opts?.filename || "";
|
||||
try {
|
||||
@@ -87,7 +87,7 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
|
||||
const init = {
|
||||
...(opts?._init || {}),
|
||||
headers
|
||||
headers,
|
||||
};
|
||||
if (opts?.path) {
|
||||
return this.post(opts.path, body, init);
|
||||
@@ -106,7 +106,7 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
filename?: string;
|
||||
_init?: Omit<RequestInit, "body">;
|
||||
path?: TInput;
|
||||
} = {}
|
||||
} = {},
|
||||
) {
|
||||
if (item instanceof Request || typeof item === "string") {
|
||||
const res = await this.fetcher(item);
|
||||
@@ -124,9 +124,9 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
...(opts._init ?? {}),
|
||||
headers: {
|
||||
...(opts._init?.headers ?? {}),
|
||||
"Content-Type": item.headers.get("Content-Type") || "application/octet-stream"
|
||||
}
|
||||
}
|
||||
"Content-Type": item.headers.get("Content-Type") || "application/octet-stream",
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -140,11 +140,11 @@ export class MediaApi extends ModuleApi<MediaApiOptions> {
|
||||
item: Request | Response | string | File | ReadableStream,
|
||||
opts?: {
|
||||
_init?: Omit<RequestInit, "body">;
|
||||
}
|
||||
},
|
||||
) {
|
||||
return this.upload(item, {
|
||||
...opts,
|
||||
path: ["entity", entity, id, field]
|
||||
path: ["entity", entity, id, field],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ export class MediaController extends Controller {
|
||||
return c.json({
|
||||
type: file?.type,
|
||||
name: file?.name,
|
||||
size: file?.size
|
||||
size: file?.size,
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -82,7 +82,7 @@ export class MediaController extends Controller {
|
||||
if (body.size > maxSize) {
|
||||
return c.json(
|
||||
{ error: `Max size (${maxSize} bytes) exceeded` },
|
||||
HttpStatus.PAYLOAD_TOO_LARGE
|
||||
HttpStatus.PAYLOAD_TOO_LARGE,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ export class MediaController extends Controller {
|
||||
tb(
|
||||
"query",
|
||||
Type.Object({
|
||||
overwrite: Type.Optional(booleanLike)
|
||||
})
|
||||
overwrite: Type.Optional(booleanLike),
|
||||
}),
|
||||
),
|
||||
async (c) => {
|
||||
const entity_name = c.req.param("entity");
|
||||
@@ -124,7 +124,7 @@ export class MediaController extends Controller {
|
||||
const mediaRef = {
|
||||
scope: field_name,
|
||||
reference,
|
||||
entity_id: entity_id
|
||||
entity_id: entity_id,
|
||||
};
|
||||
|
||||
// check max items
|
||||
@@ -140,7 +140,7 @@ export class MediaController extends Controller {
|
||||
if (!overwrite) {
|
||||
return c.json(
|
||||
{ error: `Max items (${max_items}) reached` },
|
||||
HttpStatus.BAD_REQUEST
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ export class MediaController extends Controller {
|
||||
if (count > max_items) {
|
||||
return c.json(
|
||||
{ error: `Max items (${max_items}) exceeded already with ${count} items.` },
|
||||
HttpStatus.UNPROCESSABLE_ENTITY
|
||||
HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,9 +159,9 @@ export class MediaController extends Controller {
|
||||
where: mediaRef,
|
||||
sort: {
|
||||
by: "id",
|
||||
dir: "asc"
|
||||
dir: "asc",
|
||||
},
|
||||
limit: count - max_items + 1
|
||||
limit: count - max_items + 1,
|
||||
});
|
||||
|
||||
if (deleteRes.data && deleteRes.data.length > 0) {
|
||||
@@ -175,7 +175,7 @@ export class MediaController extends Controller {
|
||||
if (!exists) {
|
||||
return c.json(
|
||||
{ error: `Entity "${entity_name}" with ID "${entity_id}" doesn't exist found` },
|
||||
HttpStatus.NOT_FOUND
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ export class MediaController extends Controller {
|
||||
if (file.size > maxSize) {
|
||||
return c.json(
|
||||
{ error: `Max size (${maxSize} bytes) exceeded` },
|
||||
HttpStatus.PAYLOAD_TOO_LARGE
|
||||
HttpStatus.PAYLOAD_TOO_LARGE,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ export class MediaController extends Controller {
|
||||
mutator.__unstable_toggleSystemEntityCreation(false);
|
||||
const result = await mutator.insertOne({
|
||||
...this.media.uploadedEventDataToMediaPayload(info),
|
||||
...mediaRef
|
||||
...mediaRef,
|
||||
} as any);
|
||||
mutator.__unstable_toggleSystemEntityCreation(true);
|
||||
|
||||
@@ -210,7 +210,7 @@ export class MediaController extends Controller {
|
||||
}
|
||||
|
||||
return c.json({ ok: true, result: result.data, ...info }, HttpStatus.CREATED);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return hono.all("*", (c) => c.notFound());
|
||||
|
||||
Reference in New Issue
Block a user