mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
optimize adapter imports to deduplicate
This commit is contained in:
@@ -1,6 +1,37 @@
|
||||
export * from "./node.adapter";
|
||||
export {
|
||||
StorageLocalAdapter,
|
||||
type LocalAdapterConfig
|
||||
import type { IncomingMessage } from "node:http";
|
||||
import { registries } from "bknd";
|
||||
import {
|
||||
type LocalAdapterConfig,
|
||||
StorageLocalAdapter
|
||||
} from "../../media/storage/adapters/StorageLocalAdapter";
|
||||
export { registerLocalMediaAdapter } from "../index";
|
||||
|
||||
export * from "./node.adapter";
|
||||
export { StorageLocalAdapter, type LocalAdapterConfig };
|
||||
|
||||
export function nodeRequestToRequest(req: IncomingMessage): Request {
|
||||
let protocol = "http";
|
||||
try {
|
||||
protocol = req.headers["x-forwarded-proto"] as string;
|
||||
} catch (e) {}
|
||||
const host = req.headers.host;
|
||||
const url = `${protocol}://${host}${req.url}`;
|
||||
const headers = new Headers();
|
||||
|
||||
for (const [key, value] of Object.entries(req.headers)) {
|
||||
if (Array.isArray(value)) {
|
||||
headers.append(key, value.join(", "));
|
||||
} else if (value) {
|
||||
headers.append(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
const method = req.method || "GET";
|
||||
return new Request(url, {
|
||||
method,
|
||||
headers
|
||||
});
|
||||
}
|
||||
|
||||
export function registerLocalMediaAdapter() {
|
||||
registries.media.register("local", StorageLocalAdapter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user