|
|
|
@ -3,13 +3,14 @@ import path from "path";
|
|
|
|
|
|
|
|
|
|
import { avatarFileFormat } from "./constants";
|
|
|
|
|
|
|
|
|
|
import { cache } from "react";
|
|
|
|
|
|
|
|
|
|
import Landing, { LandingModel } from "@models/landing";
|
|
|
|
|
|
|
|
|
|
import exists from "@utils/fileExists";
|
|
|
|
|
|
|
|
|
|
export const readLandingJson = async (
|
|
|
|
|
dataDirLocation: string
|
|
|
|
|
): Promise<Landing> => {
|
|
|
|
|
export const readLandingJson = cache(
|
|
|
|
|
async (dataDirLocation: string): Promise<Landing> => {
|
|
|
|
|
const landingJsonLocation = path.join(dataDirLocation, "landing.json");
|
|
|
|
|
|
|
|
|
|
const fileExists = await exists(landingJsonLocation);
|
|
|
|
@ -28,11 +29,11 @@ export const readLandingJson = async (
|
|
|
|
|
throw new Error(`Failed to parse landing json: ${landingResult.error}`);
|
|
|
|
|
|
|
|
|
|
return landingResult.data;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const readAvatarFile = async (
|
|
|
|
|
dataDirLocation: string
|
|
|
|
|
): Promise<string> => {
|
|
|
|
|
export const readAvatarFile = cache(
|
|
|
|
|
async (dataDirLocation: string): Promise<string> => {
|
|
|
|
|
const avatarFileLocation = path.join(
|
|
|
|
|
dataDirLocation,
|
|
|
|
|
`avatar.${avatarFileFormat}`
|
|
|
|
@ -43,4 +44,5 @@ export const readAvatarFile = async (
|
|
|
|
|
const base64Image = Buffer.from(imageData).toString("base64");
|
|
|
|
|
|
|
|
|
|
return `data:image/${avatarFileFormat};base64,${base64Image}`;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|