-
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.
* Added rename podcast endpoint * Added handling for response * Updated route
- Loading branch information
1 parent
63681fd
commit 9083ff7
Showing
3 changed files
with
41 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { AddResponseHeaders } from "./AddResponseHeaders"; | ||
import { Auth0ActionContext } from "./Auth0ActionContext"; | ||
import { Auth0JwtPayload } from "./Auth0JwtPayload"; | ||
import { buildFetchHeaders } from "./buildFetchHeaders"; | ||
|
||
export async function renamePodcast(c: Auth0ActionContext): Promise<Response> { | ||
const auth0Payload: Auth0JwtPayload = c.var.auth0('payload'); | ||
const podcastName = c.req.param('name'); | ||
const newName = c.req.param('newName'); | ||
AddResponseHeaders(c, { methods: ["POST", "GET", "OPTIONS"] }); | ||
if (auth0Payload?.permissions && auth0Payload.permissions.includes('admin')) { | ||
const url = `${c.env.securePodcastEndpoint}/name/${podcastName}`; | ||
const data: any = await c.req.json(); | ||
const body: string = JSON.stringify(data); | ||
const resp = await fetch(url, { | ||
headers: buildFetchHeaders(c.req, c.env.securePodcastEndpoint), | ||
method: "POST", | ||
body: body | ||
}); | ||
if (resp.status == 200) { | ||
console.log(`Successfully used secure-podcast-endpoint to rename podcast.`); | ||
return new Response(resp.body); | ||
} else if (resp.status == 400) { | ||
console.log(`Unable to find podcast to rename podcast.`); | ||
return new Response(resp.body, { status: resp.status }); | ||
} else if (resp.status == 404) { | ||
console.log(`Unable to find podcast to rename podcast. Podccast not found.`); | ||
return new Response(resp.body, { status: resp.status }); | ||
} else if (resp.status == 409) { | ||
console.log(`Unable to find podcast to rename podcast. Podcast exists with new-name.`); | ||
return new Response(resp.body, { status: resp.status }); | ||
} else { | ||
console.log(`Failed to use secure-podcast-endpoint to rename podcast. Response code: '${resp.status}'.`); | ||
return c.json({ error: "Error" }, 500); | ||
} | ||
} | ||
return c.json({ error: "Unauthorised" }, 403); | ||
} |
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