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