import { env } from "~/env";

type Params = {
	cacheKey: string;
	mode: "download" | "inline";
	media: "image" | "video";
};

export function getStorageUrl({
	storageId,
	params,
	host = env.NEXT_PUBLIC_BASE_URL,
}: {
	storageId: string;
	params?: Partial<Params>;
	host?: string;
}) {
	const url = new URL(`${host}/storage-api/get/${storageId}`);
	if (params) {
		Object.entries(params).forEach(([key, value]) => {
			url.searchParams.append(key, value);
		});
	}

	return url.toString();
}
