Skip to content

Commit 870878d

Browse files
committed
Use UUIDs for addressing logos
1 parent df26c84 commit 870878d

File tree

9 files changed

+25
-7
lines changed

9 files changed

+25
-7
lines changed

app/components/sidebar-admin.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function SidebarAdmin() {
7878
>
7979
{activeProgram?.logo ? (
8080
<img
81-
src={`/view/logo/${activeProgram.logo.id}.svg`}
81+
src={`/view/logo/${activeProgram.logo.uuid}.svg`}
8282
alt=""
8383
role="presentation"
8484
className="w-8 aspect-square"
@@ -141,7 +141,7 @@ export function SidebarAdmin() {
141141
<Link to={`/org/program/${program.id}/batch`}>
142142
{program.logo ? (
143143
<img
144-
src={`/view/logo/${program.logo.id}.svg`}
144+
src={`/view/logo/${program.logo.uuid}.svg`}
145145
alt=""
146146
role="presentation"
147147
className="size-5 ml-1 aspect-square"

app/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function App() {
4444

4545
export function ErrorBoundary() {
4646
const error = useRouteError();
47-
console.error(error);
47+
//console.error(error);
4848
let errorInfo;
4949

5050
if (isRouteErrorResponse(error)) {

app/routes/org.program.$programId.settings.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ export default function ProgramSettings() {
142142
encType="multipart/form-data"
143143
className="grid grid-cols-2 gap-8 max-w-[505px]"
144144
>
145+
{/* @todo implement a preview -> save workflow for changing the logo */}
145146
<div>
146147
<div className="border rounded-lg aspect-square max-w-[200px] bg-white flex justify-center items-center">
147148
{program.logo ? (
148149
<img
149-
src={`/view/logo/${program.logo.id}.svg`}
150+
src={`/view/logo/${program.logo.uuid}.svg`}
150151
alt=""
151152
role="presentation"
152153
/>

app/routes/org.program.$programId.settings.upload.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ActionFunction } from "@remix-run/node";
2+
import { randomUUID } from "node:crypto";
23
import {
34
json,
45
unstable_createMemoryUploadHandler,
@@ -57,9 +58,11 @@ export const action: ActionFunction = async ({ request, params }) => {
5758
programId: Number(params.programId),
5859
},
5960
update: {
61+
uuid: randomUUID(),
6062
contentType: programLogo.type,
6163
},
6264
create: {
65+
uuid: randomUUID(),
6366
contentType: programLogo.type,
6467
program: {
6568
connect: { id: Number(params.programId) },

app/routes/org.program._index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function OrgIndex() {
8080
>
8181
{program.logo && (
8282
<img
83-
src={`/view/logo/${program.logo.id}.svg`}
83+
src={`/view/logo/${program.logo.uuid}.svg`}
8484
alt=""
8585
role="presentation"
8686
className="w-8 aspect-square"

app/routes/view.logo.$logoId[.svg].ts renamed to app/routes/view.logo.$logoUuid[.svg].ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { prisma } from "~/lib/prisma.server";
44
import { readProgramLogo } from "~/lib/program.server";
55

66
export const loader: LoaderFunction = async ({ params }) => {
7-
// @todo use UUID instead of ID (make it harder to guess and reveal internals)
87
const logo = await prisma.programLogo.findUnique({
98
where: {
10-
id: Number(params.logoId),
9+
uuid: params.logoUuid,
1110
},
1211
});
1312

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[uuid]` on the table `program_logos` will be added. If there are existing duplicate values, this will fail.
5+
- Added the required column `uuid` to the `program_logos` table without a default value. This is not possible if the table is not empty.
6+
7+
*/
8+
-- AlterTable
9+
ALTER TABLE "program_logos" ADD COLUMN "uuid" UUID NOT NULL DEFAULT gen_random_uuid ();
10+
11+
-- CreateIndex
12+
CREATE UNIQUE INDEX "program_logos_uuid_key" ON "program_logos"("uuid");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "program_logos" ALTER COLUMN "uuid" DROP DEFAULT;

prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ model Program {
9292

9393
model ProgramLogo {
9494
id Int @id @default(autoincrement())
95+
uuid String @unique @db.Uuid
9596
contentType String @db.VarChar(64)
9697
updatedAt DateTime @updatedAt
9798
program Program @relation(fields: [programId], references: [id])

0 commit comments

Comments
 (0)