This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
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
13 changed files
with
716 additions
and
417 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
Empty file.
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,88 @@ | ||
import { NextResponse } from "next/server"; | ||
import { jwtDecrypt } from "jose"; | ||
import { BW_SECRET_KEY } from "@/tools/tokens"; | ||
import { fetcher } from "@/tools/fetch"; | ||
import createClient from "@/supabase/server"; | ||
|
||
export const revalidate = 0; | ||
|
||
export async function POST(request: Request) { | ||
const body = await request.json(); | ||
|
||
const supabase = createClient(); | ||
|
||
const { | ||
data: { user: user }, | ||
error: userError, | ||
} = await supabase.auth.getUser(); | ||
|
||
if (userError) { | ||
return NextResponse.json({ error: userError }); | ||
} | ||
|
||
const { data, error } = await supabase | ||
.from("projects") | ||
.select("railway_project_id") | ||
.eq("id", body.projectId) | ||
.single(); | ||
|
||
if (error) { | ||
return NextResponse.json({ error }); | ||
} | ||
|
||
const { payload: railwayProjectId } = await jwtDecrypt( | ||
data.railway_project_id, | ||
BW_SECRET_KEY | ||
); | ||
|
||
const { payload: railwayApiToken } = await jwtDecrypt( | ||
user?.user_metadata["railwayApiToken"], | ||
BW_SECRET_KEY | ||
); | ||
|
||
const projectData = await fetcher( | ||
"https://backboard.railway.app/graphql/v2", | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${railwayApiToken.data}`, | ||
}, | ||
body: JSON.stringify({ | ||
query: ` | ||
query { | ||
project(id: "${railwayProjectId.data}") { | ||
services { | ||
edges { | ||
node { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
plugins { | ||
edges { | ||
node { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
}), | ||
} | ||
); | ||
|
||
if (projectData.errors) { | ||
return NextResponse.json({ error: projectData.errors[0].message }); | ||
} | ||
|
||
return NextResponse.json({ | ||
message: "Success", | ||
services: projectData.data.project.services.edges, | ||
plugins: projectData.data.project.plugins.edges, | ||
}); | ||
} |
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,17 @@ | ||
import React, { memo } from "react"; | ||
|
||
const NodeLoading = () => { | ||
return ( | ||
<div className="px-4 py-2 rounded-xl bg-secondary border-2 border-dashed border-gray-800"> | ||
<div className="animate-pulse flex"> | ||
<div className="rounded-full w-12 h-12 flex justify-center items-center bg-bwdefualt" /> | ||
<div className="ml-2 pt-1"> | ||
<div className="h-4 w-20 mb-3 bg-bwdefualt rounded" /> | ||
<div className="h-3 w-10 bg-bwdefualt rounded" /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default memo(NodeLoading); |
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.