Skip to content

Commit

Permalink
applied a migration, changed some other things
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutlope committed Mar 17, 2023
1 parent 6954332 commit 58a2e9b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 4 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"vercel-build": "prisma generate && next build",
"prisma:generate": "prisma generate"
"build": "prisma generate && prisma migrate deploy && next build",
"start": "next start"
},
"dependencies": {
"@headlessui/react": "^1.7.7",
Expand Down
4 changes: 4 additions & 0 deletions pages/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export default async function handler(
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}

// add the generated room to the Room Table in the User's account with Prisma
// get rid of rate limiting code and decrease the number of credits on the User's table

res.status(200).json(
generatedImage
? {
Expand Down
37 changes: 37 additions & 0 deletions pages/api/getReplicateInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { NextApiRequest, NextApiResponse } from "next";

export type GenerateResponseData = {
original: string | null;
generated: string | null;
id: string;
};

interface ExtendedNextApiRequest extends NextApiRequest {
body: {
imageUrl: string;
theme: string;
room: string;
};
}

export default async function handler(
req: ExtendedNextApiRequest,
res: NextApiResponse<GenerateResponseData | string>
) {
// POST request to Replicate to start the image restoration generation process
let predictonResponse = await fetch(
"https://api.replicate.com/v1/predictions/tfda4hdsgncrpafun4ikywjbve",
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: "Token " + process.env.REPLICATE_API_KEY,
},
}
);

let jsonStartResponse = await predictonResponse.json();

console.log({ jsonStartResponse });
res.status(200).json(jsonStartResponse);
}
23 changes: 23 additions & 0 deletions prisma/migrations/20230317200723_payments/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "boughtCredits" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "credits" INTEGER NOT NULL DEFAULT 5;

-- CreateTable
CREATE TABLE "Room" (
"id" TEXT NOT NULL,
"replicateId" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"inputImage" TEXT NOT NULL,
"outputImage" TEXT NOT NULL,
"prompt" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Room_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Room_replicateId_userId_key" ON "Room"("replicateId", "userId");

-- AddForeignKey
ALTER TABLE "Room" ADD CONSTRAINT "Room_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
17 changes: 17 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ model User {
email String? @unique
emailVerified DateTime?
image String?
credits Int @default(5)
boughtCredits Int @default(0)
accounts Account[]
sessions Session[]
rooms Room[]
}

model VerificationToken {
Expand All @@ -51,3 +54,17 @@ model VerificationToken {
@@unique([identifier, token])
}

model Room {
id String @id @default(cuid())
replicateId String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
inputImage String
outputImage String
prompt String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([replicateId, userId])
}
Binary file added public/original-living.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 58a2e9b

Please sign in to comment.