-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from biensupernice/feature/support-episode-tracks
Support episode tracks
- Loading branch information
Showing
9 changed files
with
1,130 additions
and
418 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createDbConnection } from "@/server/db"; | ||
import { | ||
trackInputSchema, | ||
updateEpisodeDetailsBySoundcloudUrl, | ||
} from "@/server/update-episode-details"; | ||
import { set } from "date-fns"; | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import { z } from "zod"; | ||
|
||
const inputSchema = z.object({ | ||
soundCloudUrl: z.string(), | ||
releaseDate: z.coerce | ||
.date() | ||
.transform((v) => set(v, { hours: 12 })) | ||
.optional(), | ||
tracks: z.array(trackInputSchema), | ||
}); | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
try { | ||
if (req.method !== "POST") { | ||
return res.status(405).json({ error: "Method Not Allowed" }); | ||
} | ||
|
||
const parsedInput = inputSchema.safeParse(req.body); | ||
if (!parsedInput.success) { | ||
const { errors } = parsedInput.error; | ||
|
||
return res.status(400).json({ | ||
error: { message: "Invalid request", errors }, | ||
}); | ||
} | ||
|
||
const db = await createDbConnection(); | ||
const updateRes = await updateEpisodeDetailsBySoundcloudUrl( | ||
db, | ||
parsedInput.data.soundCloudUrl, | ||
{ | ||
releaseDate: parsedInput.data.releaseDate, | ||
tracks: parsedInput.data.tracks, | ||
} | ||
); | ||
|
||
if (!updateRes.ok) { | ||
return res.status(400).json({ | ||
error: { | ||
message: "Something went wrong ingesting episode tracks", | ||
errors: updateRes.reason, | ||
}, | ||
}); | ||
} | ||
|
||
res.status(200).json({ | ||
message: "Data processed successfully", | ||
}); | ||
} catch (err: any) { | ||
console.error(err); | ||
res.status(500).json({ msg: err.message }); | ||
} | ||
}; |
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
Oops, something went wrong.
1bdd367
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.
Deploy preview for soulector ready!
✅ Preview
https://soulector-qbsmimis6-jalvarado91.vercel.app
Built with commit 1bdd367.
This pull request is being automatically deployed with vercel-action