mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-09 16:05:23 +02:00
refactor: remove unused api github routes
This commit is contained in:
58
apps/dokploy/pages/api/providers/github/setup.ts
Normal file
58
apps/dokploy/pages/api/providers/github/setup.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { createGithubProvider } from "@/server/api/services/git-provider";
|
||||
import { db } from "@/server/db";
|
||||
import { githubProvider } from "@/server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { Octokit } from "octokit";
|
||||
|
||||
type Query = {
|
||||
code: string;
|
||||
state: string;
|
||||
installation_id: string;
|
||||
setup_action: string;
|
||||
};
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse,
|
||||
) {
|
||||
const { code, state, installation_id, setup_action }: Query =
|
||||
req.query as Query;
|
||||
|
||||
if (!code) {
|
||||
return res.status(400).json({ error: "Missing code parameter" });
|
||||
}
|
||||
const [action, value] = state?.split(":");
|
||||
// Value could be the authId or the githubProviderId
|
||||
|
||||
if (action === "gh_init") {
|
||||
const octokit = new Octokit({});
|
||||
const { data } = await octokit.request(
|
||||
"POST /app-manifests/{code}/conversions",
|
||||
{
|
||||
code: code as string,
|
||||
},
|
||||
);
|
||||
|
||||
await createGithubProvider({
|
||||
name: data.name,
|
||||
githubAppName: data.html_url,
|
||||
githubAppId: data.id,
|
||||
githubClientId: data.client_id,
|
||||
githubClientSecret: data.client_secret,
|
||||
githubWebhookSecret: data.webhook_secret,
|
||||
githubPrivateKey: data.pem,
|
||||
authId: value as string,
|
||||
});
|
||||
} else if (action === "gh_setup") {
|
||||
await db
|
||||
.update(githubProvider)
|
||||
.set({
|
||||
githubInstallationId: installation_id,
|
||||
})
|
||||
.where(eq(githubProvider.githubId, value as string))
|
||||
.returning();
|
||||
}
|
||||
|
||||
res.redirect(307, "/dashboard/settings/git-providers");
|
||||
}
|
||||
Reference in New Issue
Block a user