Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
botway(core): format files, and update code editor api
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Jul 1, 2023
1 parent 3ceed50 commit 245c016
Show file tree
Hide file tree
Showing 29 changed files with 248 additions and 300 deletions.
2 changes: 1 addition & 1 deletion ce
84 changes: 79 additions & 5 deletions core/app/api/ce/enable/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ export async function POST(request: Request) {

const { payload: password } = await jwtDecrypt(body.password, BW_SECRET_KEY);

const { payload: projectId } = await jwtDecrypt(
body.projectId,
const { data, error: ceError } = await supabase
.from("projects")
.select("railway_project_id, lang")
.eq("id", body.projectId)
.single();

if (ceError) {
return NextResponse.json({ error: ceError });
}

const { payload: railwayProjectId } = await jwtDecrypt(
data.railway_project_id,
BW_SECRET_KEY
);

Expand All @@ -45,6 +55,69 @@ export async function POST(request: Request) {

const ghu = await (await octokit.request("GET /user", {})).data;

let pkgs = "cmake ";

switch (data.lang) {
case "crystal":
pkgs += "crystal";

break;

case "csharp":
pkgs += "dotnet";

break;

case "dart":
pkgs += "dart-lang/dart/dart";

break;

case "deno":
pkgs += "deno";

break;

case "go":
pkgs += "go";

break;

case "java":
pkgs += "java gradle";

break;
case "kotlin":
pkgs += "kotlin java gradle";

break;

case "nim":
pkgs += "nim";

break;

case "php":
pkgs += "composer";

break;

case "python":
pkgs += "poetry pipenv";

break;

case "rust":
pkgs += "rust rustup-init";

break;

case "swift":
pkgs += "swift";

break;
}

const query = `
mutation {
templateDeploy(input: {
Expand All @@ -60,17 +133,18 @@ export async function POST(request: Request) {
GIT_REPO: "https://github.com/${body.repo}"
GITHUB_TOKEN: "${githubApiToken.data}"
PASSWORD: "${password.data}"
PKGS: "${pkgs}"
}
volumes: [
{
mountPath: "/root"
projectId: "${projectId.data}"
projectId: "${railwayProjectId.data}"
}
]
}
]
projectId: "${projectId.data}"
projectId: "${railwayProjectId.data}"
}) {
projectId
}
Expand Down Expand Up @@ -99,7 +173,7 @@ export async function POST(request: Request) {
.update({
enable_ce: true,
})
.eq("railway_project_id", body.projectId);
.eq("id", body.projectId);

if (error) {
return NextResponse.json({ error });
Expand Down
6 changes: 3 additions & 3 deletions core/app/api/ce/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export async function POST(request: Request) {
BW_SECRET_KEY
);

const { payload: projectId } = await jwtDecrypt(
body.projectId,
const { payload: railwayProjectId } = await jwtDecrypt(
body.railwayProjectId,
BW_SECRET_KEY
);

const query = `
query {
project(id: "${projectId.data}") {
project(id: "${railwayProjectId.data}") {
services {
edges {
node {
Expand Down
2 changes: 1 addition & 1 deletion core/app/api/projects/config/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from "next/server";
import { EncryptJWT, jwtDecrypt } from "jose";
import { jwtDecrypt } from "jose";
import { BW_SECRET_KEY } from "@/tools/tokens";
import { fetcher } from "@/tools/fetch";
import { Octokit } from "octokit";
Expand Down
18 changes: 9 additions & 9 deletions core/app/api/projects/env/update/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ export async function POST(request: Request) {
},
body: JSON.stringify({
query: `
mutation {
variableUpsert(input: {
environmentId: "${envId}"
name: "${body.key}"
projectId: "${railwayProjectId.data}"
serviceId: "${railwayServiceId.data}"
value: "${value.data}"
})
}
mutation {
variableUpsert(input: {
environmentId: "${envId}"
name: "${body.key}"
projectId: "${railwayProjectId.data}"
serviceId: "${railwayServiceId.data}"
value: "${value.data}"
})
}
`,
}),
});
Expand Down
1 change: 0 additions & 1 deletion core/app/api/projects/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import createClient from "@/supabase/server";
import { exec } from "child_process";
import { stringify } from "ajv";

// export const runtime = "edge";
export const revalidate = 0;

export async function POST(request: Request) {
Expand Down
42 changes: 21 additions & 21 deletions core/app/api/projects/services/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,37 @@ export async function POST(request: Request) {
},
body: JSON.stringify({
query: `
query {
project(id: "${railwayProjectId.data}") {
services {
edges {
node {
id
name
query {
project(id: "${railwayProjectId.data}") {
services {
edges {
node {
id
name
}
}
}
}
plugins {
edges {
node {
id
friendlyName
name
plugins {
edges {
node {
id
friendlyName
name
}
}
}
}
volumes {
edges {
node {
id
name
volumes {
edges {
node {
id
name
}
}
}
}
}
}
`,
}),
}
Expand Down
12 changes: 8 additions & 4 deletions core/app/project/[id]/code-editor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ const CE = ({ user, projectId }: any) => {

if (project?.enable_ce) {
body = {
envId: project?.railway_env_id,
projectId: project?.railway_project_id,
railwayProjectId: project?.railway_project_id,
};

ce = await fetcher("/api/ce", {
Expand All @@ -96,7 +95,7 @@ const CE = ({ user, projectId }: any) => {
.encrypt(BW_SECRET_KEY),
repo: project?.repo,
slug: slug(project?.name, "-"),
projectId: project?.railway_project_id,
projectId,
};

ce = await fetcher("/api/ce/enable", {
Expand Down Expand Up @@ -134,13 +133,18 @@ const CE = ({ user, projectId }: any) => {
</div>
<div className="mx-6">
<div className="w-full h-60 grid lg:grid-cols-2 lt-md:!grid-cols-1 items-center justify-center gap-4">
<img src="https://cdn-botway.deno.dev/images/coder.svg" alt="" />
<img
src="https://cdn-botway.deno.dev/images/coder.svg"
alt="Botway CE"
/>

<div className="pb-4">
<h2 className="text-md text-gray-400 text-center">
{project?.enable_ce
? "Botway CE is enabled 👍"
: "Your project needs to enable Botway CE"}
</h2>

<h2 className="text-sm text-gray-500 text-center">
Botway CE is a code editor that built on top of{" "}
<Link
Expand Down
7 changes: 7 additions & 0 deletions core/app/project/[id]/deployments/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const Project = ({ user, projectId }: any) => {
</span>
)}
</h2>

<h3 className="text-gray-500 mt-1 !leading-tight">
{deploy.node.status === "SUCCESS"
? "The deployment that is live on your production domains."
Expand All @@ -148,6 +149,7 @@ const Project = ({ user, projectId }: any) => {
: "Waiting..."}
</h3>
</hgroup>

{deployments.indexOf(deploy) === 0 ? (
<Link
className="h-8 px-3.5 text-white rounded-md inline-flex flex-shrink-0 bg-secondary whitespace-nowrap items-center gap-2 transition-colors duration-150 ease-in-out leading-none border border-gray-800 hover:border-gray-700 cursor-pointer"
Expand All @@ -168,6 +170,7 @@ const Project = ({ user, projectId }: any) => {
<label className="flex items-center mt-5 mb-1 text-sm text-gray-400">
Deployment Details
</label>

<div className="flex items-center gap-3 mt-2">
<span className="w-5 h-5 inline-flex items-center justify-center rounded-full flex-shrink-0 bg-fresh/15">
{deploy.node.status === "SUCCESS" ? (
Expand All @@ -188,20 +191,23 @@ const Project = ({ user, projectId }: any) => {
<ArchiveIcon className="fill-red-700" size={16} />
)}
</span>

<span className="flex items-center gap-1">
<img
src="https://cdn-botway.deno.dev/icons/docker.svg"
width={18}
className="mr-1"
/>
</span>

<span className="flex items-center gap-1">
<FileDirectoryIcon
size={16}
className="fill-gray-600 mr-1 font-mono"
/>
{deploy.node.meta.rootDirectory}
</span>

<span className="hidden md:flex items-center gap-1">
<GitMergeIcon
size={16}
Expand All @@ -211,6 +217,7 @@ const Project = ({ user, projectId }: any) => {
{deploy.node.meta.branch}
</span>
</span>

<span className="inline-flex items-center gap-2 max-w-100">
<Link
className="text-gray-400 text-sm hover:text-gray-500 transition-all duration-200 hover:underline truncate"
Expand Down
4 changes: 4 additions & 0 deletions core/app/project/[id]/env/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const Env = ({ user, projectId }: any) => {
<h1 className="text-3xl text-white">
{project?.name} Environment Variables
</h1>

<button
onClick={openAtRailway}
className="border border-gray-800 transition-all bg-[#181622] hover:bg-[#1f132a] duration-200 rounded-2xl p-3 text-white flex flex-col items-center"
Expand All @@ -224,6 +225,7 @@ const Env = ({ user, projectId }: any) => {
<h1 className="text-lg text-white">
{Object.keys(vars?.vars).length} Service Variables
</h1>

<button
type="button"
onClick={() => setIsOpenAdd(true)}
Expand All @@ -238,6 +240,7 @@ const Env = ({ user, projectId }: any) => {
</span>
</button>
</div>

<div className="overflow-x-auto flex-grow rounded-lg border border-gray-800">
<table className="w-full border-collapse select-auto bg-secondary">
<tbody>
Expand All @@ -255,6 +258,7 @@ const Env = ({ user, projectId }: any) => {
{key}
</div>
</td>

<td
className={`py-3 px-4 overflow-hidden hidden md:table-cell overflow-ellipsis whitespace-nowrap ${
index != Object.keys(vars?.vars).length - 1
Expand Down
Loading

0 comments on commit 245c016

Please sign in to comment.