feat: Add photo management features, duplicate detection, attempt limits, and admin deletion
CI / skip-ci-check (pull_request) Successful in 1m19s
CI / lint-and-type-check (pull_request) Failing after 1m37s
CI / test (pull_request) Successful in 2m16s
CI / build (pull_request) Failing after 1m46s
CI / secret-scanning (pull_request) Successful in 1m20s
CI / dependency-scan (pull_request) Successful in 1m27s
CI / sast-scan (pull_request) Successful in 2m29s
CI / workflow-summary (pull_request) Successful in 1m18s

- Add duplicate photo detection (file hash and URL checking)
- Add max attempts per photo with UI counter
- Simplify penalty system (auto-enable when points > 0)
- Prevent scores from going below 0
- Add admin photo deletion functionality
- Improve navigation with always-visible logout
- Prevent users from guessing their own photos
This commit is contained in:
2026-01-02 14:57:30 -05:00
commit 9640627972
69 changed files with 20858 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
output = "../node_modules/@prisma/client/.prisma/client"
}
datasource db {
provider = "postgresql"
}
// Seed configuration
// Run with: npm run db:seed
model User {
id String @id @default(cuid())
name String
email String @unique
passwordHash String
role Role @default(USER)
points Int @default(0)
createdAt DateTime @default(now())
uploadedPhotos Photo[] @relation("PhotoUploader")
guesses Guess[]
@@index([points])
}
model Photo {
id String @id @default(cuid())
uploaderId String
uploader User @relation("PhotoUploader", fields: [uploaderId], references: [id])
url String
fileHash String? // SHA256 hash of file content (null for URL uploads)
answerName String
points Int @default(1)
penaltyEnabled Boolean @default(false)
penaltyPoints Int @default(0)
maxAttempts Int? // Maximum number of guesses allowed per user (null = unlimited)
createdAt DateTime @default(now())
guesses Guess[]
@@index([uploaderId])
@@index([createdAt])
@@index([url])
@@index([fileHash])
}
model Guess {
id String @id @default(cuid())
userId String
user User @relation(fields: [userId], references: [id])
photoId String
photo Photo @relation(fields: [photoId], references: [id])
guessText String
correct Boolean @default(false)
createdAt DateTime @default(now())
@@index([userId])
@@index([photoId])
}
enum Role {
ADMIN
USER
}
+42
View File
@@ -0,0 +1,42 @@
import "dotenv/config"
import { prisma } from "../lib/prisma"
import bcrypt from "bcryptjs"
async function main() {
// Check if admin already exists
const existingAdmin = await prisma.user.findUnique({
where: { email: "admin@mirrormatch.com" },
})
if (existingAdmin) {
console.log("Admin user already exists. Skipping seed.")
return
}
// Create default admin user
const passwordHash = await bcrypt.hash("admin123", 10)
await prisma.user.create({
data: {
name: "Admin",
email: "admin@mirrormatch.com",
passwordHash,
role: "ADMIN",
points: 0,
},
})
console.log("✅ Created admin user:")
console.log(" Email: admin@mirrormatch.com")
console.log(" Password: admin123")
console.log(" ⚠️ Please change the password after first login!")
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})