-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
5651a98
commit 5a8ccda
Showing
13 changed files
with
240 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getBuildServerBaseUrl } from "@/lib/env"; | ||
import { unzipSync } from "fflate"; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const id = searchParams.get("id"); | ||
|
||
if (!id) { | ||
throw new Error("no id"); | ||
} | ||
|
||
const res = await fetch( | ||
`${getBuildServerBaseUrl()}/playground/share/get/${id}` | ||
); | ||
|
||
const data = await res.text(); | ||
|
||
const zipData = Buffer.from(data, "base64"); | ||
|
||
const unzipped = unzipSync(zipData); | ||
|
||
return Response.json(unzipped); | ||
} |
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,37 @@ | ||
import { FileContent } from "@/data/db"; | ||
import { getBuildServerBaseUrl } from "@/lib/env"; | ||
import { fileContentToZip } from "@/lib/file-content-to-zip"; | ||
import { type NextRequest } from "next/server"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const { files } = (await request.json()) as { files: FileContent[] }; | ||
|
||
const zippedData = fileContentToZip(files); | ||
|
||
const formData = new FormData(); | ||
const filePath = uuidv4() + ".zip"; | ||
formData.append( | ||
"file", | ||
new File([zippedData], filePath, { type: "application/zip" }), | ||
filePath | ||
); | ||
|
||
const requestInit: RequestInit = { | ||
method: "POST", | ||
body: formData, | ||
redirect: "follow", | ||
}; | ||
|
||
const response = await fetch( | ||
`${getBuildServerBaseUrl()}/playground/share/create`, | ||
requestInit | ||
); | ||
|
||
if (!response.ok) { | ||
const { message } = await response.json(); | ||
return Response.json({ error: message }, { status: response.status }); | ||
} | ||
|
||
return Response.json(await response.json()); | ||
} |
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
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,12 @@ | ||
"use client"; | ||
|
||
import { useShare } from "@/data/client"; | ||
|
||
export function SharePageComponent({ id }: { id: string }) { | ||
const { data, isLoading, error } = useShare(id); | ||
|
||
if (isLoading) return <p>Loading...</p>; | ||
else if (error) return <p>Error: {String(error)}</p>; | ||
|
||
return <p>{JSON.stringify(data)}</p>; | ||
} |
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,10 @@ | ||
import { SharePageComponent } from "./_sharepagecomponent"; | ||
|
||
|
||
|
||
export default function Page({ params: {id} }: { params: { id: string } }) { | ||
|
||
return ( | ||
<SharePageComponent id={id} /> | ||
); | ||
} |
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
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,45 @@ | ||
"use client"; | ||
import { Copy, CopyCheck } from "lucide-react"; | ||
import Link from "next/link"; | ||
import { useMemo, useState } from "react"; | ||
import { CopyToClipboard } from "react-copy-to-clipboard"; | ||
import { useToast } from "@/components/ui/use-toast"; | ||
|
||
export function ShareLink({ id }: { id: string }) { | ||
const { toast } = useToast(); | ||
const origin = | ||
typeof window !== "undefined" && window.location.origin | ||
? window.location.origin | ||
: ""; | ||
const [copied, setCopied] = useState(false); | ||
|
||
const url = useMemo(() => { | ||
return `${origin}/share/${id}`; | ||
}, [id, origin]); | ||
|
||
return ( | ||
<div className="flex"> | ||
<Link href={url} className="mr-4"> | ||
{url} | ||
</Link> | ||
<CopyToClipboard | ||
text={url} | ||
onCopy={() => { | ||
setCopied(true); | ||
|
||
toast({ | ||
title: "Link Copied", | ||
description: "Share link has been copied to your clipboard.", | ||
|
||
}); | ||
}} | ||
> | ||
{copied ? ( | ||
<CopyCheck className="w-4 h-4 cursor-pointer" /> | ||
) : ( | ||
<Copy className="w-4 h-4 cursor-pointer" /> | ||
)} | ||
</CopyToClipboard> | ||
</div> | ||
); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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