Let each install pick its app icon
Settings > General gets an App icon (super admin): one of the seven stones, or an uploaded image with the picked stone as a top-left corner mark (inside a round launcher's crop, clear of the browser's badge), previewed in both launcher crops before saving. Uploads are decoded and cropped to a stored square (no SVG); the set is drawn into DATA_DIR/install-icon/<version>/ and served publicly and immutable. The manifest, head icon links and push notifications point at it; the ember stone keeps the stock icons. The generator shares the icon renderer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import grabSuperAdminUser from "@/src/functions/backend/backups/grab-super-admin-user";
|
||||
import saveInstallIcon from "@/src/functions/backend/install-icon/save-install-icon";
|
||||
import logEvent, { grabRequestIP } from "@/src/functions/backend/logger";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import type { PwaInstallIcon } from "@/src/data/pwa-data";
|
||||
import type { BotHue } from "@/src/dict/bot-dict";
|
||||
import { SaveInstallIconRequestSchema } from "@/src/schemas/install-schema";
|
||||
import AppError from "@/src/utils/app-error";
|
||||
import bufferFromBase64 from "@/src/utils/buffer-from-base-64";
|
||||
import parseWithSchema from "@/src/utils/parse-with-schema";
|
||||
import safeErrorMessage from "@/src/utils/safe-error-message";
|
||||
import type { APIResponseObject, BunextAPIRouteHandler } from "@moduletrace/bunext/types";
|
||||
|
||||
/**
|
||||
* Super admin only: the icon this install goes by as an installed app, a
|
||||
* stone or an uploaded image with the stone in its corner.
|
||||
*/
|
||||
export const handler: BunextAPIRouteHandler<APIResponseObject<PwaInstallIcon>> = async ({
|
||||
req,
|
||||
body,
|
||||
}) => {
|
||||
try {
|
||||
if (req.method != "POST") throw new AppError(`Method not allowed`);
|
||||
|
||||
const user = await grabSuperAdminUser({ req });
|
||||
|
||||
if (!user?.id) throw new AppError(`Only a super admin can change the app icon.`);
|
||||
|
||||
const { mode, stone, mark, data_url } = parseWithSchema({
|
||||
schema: SaveInstallIconRequestSchema,
|
||||
data: body,
|
||||
});
|
||||
|
||||
const image = data_url ? (await bufferFromBase64(data_url)).buffer : null;
|
||||
|
||||
if (image && image.length > AppData.ProfileImageMaxBytes) {
|
||||
throw new AppError(
|
||||
`That image is too big. Images can be up to ${Math.round(AppData.ProfileImageMaxBytes / 1024 / 1024)} MB.`,
|
||||
);
|
||||
}
|
||||
|
||||
const icon = await saveInstallIcon({ mode, stone: stone as BotHue, mark, image });
|
||||
|
||||
await logEvent({
|
||||
title: "App icon changed",
|
||||
category: "system",
|
||||
user_id: user.id,
|
||||
plain_text: `User #${user.id} set the app icon to ${mode == "image" ? `an image${mark ? ` with the ${stone} mark` : ""}` : `the ${stone} stone`}.`,
|
||||
metadata: { mode, stone, mark, version: icon.version, new_image: Boolean(image) },
|
||||
ip_address: grabRequestIP(req),
|
||||
});
|
||||
|
||||
return { success: true, singleRes: icon };
|
||||
} catch (error: unknown) {
|
||||
return { success: false, msg: safeErrorMessage({ error }) };
|
||||
}
|
||||
};
|
||||
@@ -3,7 +3,7 @@ import grabInstallName from "@/src/functions/backend/db/app-settings/grab-instal
|
||||
import saveAppSetting from "@/src/functions/backend/db/app-settings/save-app-setting";
|
||||
import logEvent, { grabRequestIP } from "@/src/functions/backend/logger";
|
||||
import { PwaInstallNameSettingKey } from "@/src/data/pwa-data";
|
||||
import { SaveInstallNameRequestSchema } from "@/src/schemas/push-schema";
|
||||
import { SaveInstallNameRequestSchema } from "@/src/schemas/install-schema";
|
||||
import AppError from "@/src/utils/app-error";
|
||||
import parseWithSchema from "@/src/utils/parse-with-schema";
|
||||
import safeErrorMessage from "@/src/utils/safe-error-message";
|
||||
|
||||
Reference in New Issue
Block a user