This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
Files
scoresaber-reloadedv3/projects/website/src/common/image-utils.ts

30 lines
785 B
TypeScript
Raw Normal View History

import ky from "ky";
import { Colors } from "@/common/colors";
import { Config } from "@ssr/common/config";
2024-10-04 18:25:37 +01:00
/**
* Proxies all non-localhost images to make them load faster.
*
* @param originalUrl the original image url
* @returns the new image url
*/
export function getImageUrl(originalUrl: string) {
return `${!Config.websiteUrl.includes("localhost") ? "https://img.fascinated.cc/upload/q_70/" : ""}${originalUrl}`;
2024-10-04 18:25:37 +01:00
}
/**
* Gets the average color of an image
*
* @param src the image url
* @returns the average color
*/
2024-10-09 17:56:17 +01:00
export const getAverageColor = async (src: string) => {
try {
return await ky.get<{ color: string }>(`${Config.apiUrl}/image/averagecolor/${encodeURIComponent(src)}`).json();
} catch {
return {
2024-10-16 08:21:27 +01:00
color: Colors.primary,
};
}
2024-10-09 17:56:17 +01:00
};