-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
196 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- CreateEnum | ||
CREATE TYPE "HdStatus" AS ENUM ('NO', 'PENDING', 'PROCESSED'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "Shot" ADD COLUMN "hdStatus" "HdStatus" NOT NULL DEFAULT 'NO'; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20230114151121_hd_prediction_id/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Shot" ADD COLUMN "hdPredictionId" TEXT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Shot" ADD COLUMN "hdOutputUrl" TEXT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/pages/api/projects/[id]/predictions/[predictionId]/hd.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import replicateClient from "@/core/clients/replicate"; | ||
import db from "@/core/db"; | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import { getSession } from "next-auth/react"; | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const projectId = req.query.id as string; | ||
const predictionId = req.query.predictionId as string; | ||
|
||
const session = await getSession({ req }); | ||
|
||
if (!session?.user) { | ||
return res.status(401).json({ message: "Not authenticated" }); | ||
} | ||
|
||
const project = await db.project.findFirstOrThrow({ | ||
where: { id: projectId, userId: session.userId }, | ||
}); | ||
|
||
let shot = await db.shot.findFirstOrThrow({ | ||
where: { projectId: project.id, id: predictionId }, | ||
}); | ||
|
||
if (req.method === "POST") { | ||
if (shot.hdStatus !== "NO") { | ||
return res.status(400).json({ message: "4K already applied" }); | ||
} | ||
|
||
const { data } = await replicateClient.post( | ||
`https://api.replicate.com/v1/predictions`, | ||
{ | ||
input: { | ||
image: shot.outputUrl, | ||
upscale: 8, | ||
face_upsample: true, | ||
codeformer_fidelity: 1, | ||
}, | ||
version: process.env.REPLICATE_HD_VERSION_MODEL_ID, | ||
} | ||
); | ||
|
||
shot = await db.shot.update({ | ||
where: { id: shot.id }, | ||
data: { hdStatus: "PENDING", hdPredictionId: data.id }, | ||
}); | ||
|
||
return res.json({ shot }); | ||
} | ||
|
||
if (req.method === "GET") { | ||
if (shot.hdStatus !== "PENDING") { | ||
return res.status(400).json({ message: "4K already applied" }); | ||
} | ||
|
||
const { data: prediction } = await replicateClient.get( | ||
`https://api.replicate.com/v1/predictions/${shot.hdPredictionId}` | ||
); | ||
|
||
if (prediction.output) { | ||
shot = await db.shot.update({ | ||
where: { id: shot.id }, | ||
data: { | ||
hdStatus: "PROCESSED", | ||
hdOutputUrl: prediction.output, | ||
}, | ||
}); | ||
} | ||
|
||
return res.json({ shot }); | ||
} | ||
|
||
return res.status(405).json({ message: "Method not allowed" }); | ||
}; | ||
|
||
export default handler; |
File renamed without changes.
a3d64cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
photoshot – ./
photoshot.vercel.app
photoshot.app
photoshot-git-main-casasorbier.vercel.app
photoshot-casasorbier.vercel.app
www.photoshot.app