mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
- Nova tabela `establishment_logos` no schema (userId + nameKey → domain) - Utilitários: `buildLogoDevUrl`, `toNameKey`, `logoQueryKeys`, `LOGO_DEV_TOKEN` - `EstablishmentLogo`: exibe logo via Logo.dev com fallback para iniciais; hover mostra ícone de edição - `EstablishmentLogoPicker`: popover para buscar e fixar domínio Logo.dev por estabelecimento - API routes: `GET /api/logo/mapping` e `GET /api/logo/search` - Server actions/queries para persistência do mapeamento por usuário - CSP: libera `https://img.logo.dev` em `img-src` - `.env.example`: variáveis `NEXT_PUBLIC_LOGO_DEV_TOKEN` e `LOGO_DEV_SECRET_KEY` Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
"use server";
|
|
|
|
import { and, eq } from "drizzle-orm";
|
|
import { establishmentLogos } from "@/db/schema";
|
|
import type { ActionResult } from "@/shared/lib/actions/helpers";
|
|
import {
|
|
handleActionError,
|
|
revalidateForEntity,
|
|
} from "@/shared/lib/actions/helpers";
|
|
import { getUserId } from "@/shared/lib/auth/server";
|
|
import { db } from "@/shared/lib/db";
|
|
import { toNameKey } from "@/shared/lib/logo";
|
|
|
|
/**
|
|
* Salva ou atualiza o domínio Logo.dev preferido para um estabelecimento.
|
|
*/
|
|
export async function saveEstablishmentLogoAction(
|
|
name: string,
|
|
domain: string,
|
|
): Promise<ActionResult> {
|
|
try {
|
|
const userId = await getUserId();
|
|
const nameKey = toNameKey(name);
|
|
|
|
await db
|
|
.insert(establishmentLogos)
|
|
.values({ userId, nameKey, domain })
|
|
.onConflictDoUpdate({
|
|
target: [establishmentLogos.userId, establishmentLogos.nameKey],
|
|
set: { domain, updatedAt: new Date() },
|
|
});
|
|
|
|
revalidateForEntity("establishments", userId);
|
|
return { success: true, message: "Logo salvo." };
|
|
} catch (error) {
|
|
return handleActionError(error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove o mapeamento salvo, voltando ao comportamento automático do Logo.dev.
|
|
*/
|
|
export async function removeEstablishmentLogoAction(
|
|
name: string,
|
|
): Promise<ActionResult> {
|
|
try {
|
|
const userId = await getUserId();
|
|
const nameKey = toNameKey(name);
|
|
|
|
await db
|
|
.delete(establishmentLogos)
|
|
.where(
|
|
and(
|
|
eq(establishmentLogos.userId, userId),
|
|
eq(establishmentLogos.nameKey, nameKey),
|
|
),
|
|
);
|
|
|
|
revalidateForEntity("establishments", userId);
|
|
return { success: true, message: "Logo restaurado." };
|
|
} catch (error) {
|
|
return handleActionError(error);
|
|
}
|
|
}
|