Ability to manage media requests from the widget (#894)

* Ability to manage media requests from the widget

* 🚸 Improve UX & Design

---------

Co-authored-by: Manuel <manuel.ruwe@bluewin.ch>
This commit is contained in:
Thomas Camlong
2023-05-17 05:19:14 +09:00
committed by GitHub
parent d0180b1f87
commit 3e6413d9f2
3 changed files with 155 additions and 23 deletions

View File

@@ -118,6 +118,45 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
);
}
async function Put(req: NextApiRequest, res: NextApiResponse) {
// Get the slug of the request
const { id, action } = req.query as { id: string; action: string };
const configName = getCookie('config-name', { req });
const config = getConfig(configName?.toString() ?? 'default');
Consola.log('Got a request to approve or decline a request', id, action);
const app = config.apps.find(
(app) => app.integration?.type === 'overseerr' || app.integration?.type === 'jellyseerr'
);
if (!id) {
return res.status(400).json({ error: 'No id provided' });
}
if (action !== 'approve' && action !== 'decline') {
return res.status(400).json({ error: 'Action type undefined' });
}
const apiKey = app?.integration?.properties.find((x) => x.field === 'apiKey')?.value;
if (!apiKey) {
return res.status(400).json({ error: 'No app found' });
}
const appUrl = new URL(app.url);
return axios
.post(
`${appUrl.origin}/api/v1/request/${id}/${action}`,
{},
{
headers: {
'X-Api-Key': apiKey,
},
}
)
.then((axiosres) => res.status(200).json(axiosres.data))
.catch((err) =>
res.status(500).json({
message: err.message,
})
);
}
export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
return Post(req, res);
@@ -125,6 +164,9 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'GET') {
return Get(req, res);
}
if (req.method === 'PUT') {
return Put(req, res);
}
return res.status(405).json({
statusCode: 405,
message: 'Method not allowed',