-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: share links * chore: clean up re-render * chore: cleanup * chore: more minimalg * chore: lint errors * chore: use vercel url
- Loading branch information
1 parent
7d21717
commit 9e15632
Showing
21 changed files
with
1,937 additions
and
65 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea | ||
dist | ||
*.iml | ||
*.iml | ||
.vercel | ||
.env*.local |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
|
||
SOURCE=$(shell find . -iname "*.go") | ||
|
||
|
||
|
||
web/src/assets/wasm/lib.wasm: $(SOURCE) | ||
mkdir -p dist | ||
rm -f dist/* | ||
|
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
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 |
---|---|---|
|
@@ -22,3 +22,4 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
.vercel |
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,69 @@ | ||
import { put } from "@vercel/blob"; | ||
import { createHash } from "crypto"; | ||
|
||
const MAX_DATA_SIZE = 5 * 1024 * 1024; // 5MB | ||
const AllowedOrigin = process.env.VERCEL_URL ?? "http://localhost"; | ||
|
||
export function POST(request: Request) { | ||
const origin = request.headers.get("Origin"); | ||
|
||
if (!origin || !origin.includes(AllowedOrigin)) { | ||
return new Response("Unauthorized", { status: 403 }); | ||
} | ||
|
||
return new Promise<Response>((resolve, reject) => { | ||
const body: ReadableStream | null = request.body; | ||
if (!body) { | ||
reject(new Error("No body")); | ||
return; | ||
} | ||
|
||
const reader = body.getReader(); | ||
const chunks: Uint8Array[] = []; | ||
|
||
const readData = (): void => { | ||
reader.read().then(({ done, value }) => { | ||
if (done) { | ||
processData(chunks).then(resolve).catch(reject); | ||
} else { | ||
chunks.push(value); | ||
if ( | ||
chunks.reduce((acc, chunk) => acc + chunk.length, 0) > MAX_DATA_SIZE | ||
) { | ||
reject(new Error("Data exceeds the maximum allowed size of 5MB")); | ||
} else { | ||
readData(); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
readData(); | ||
}); | ||
} | ||
|
||
async function processData(chunks: Uint8Array[]): Promise<Response> { | ||
const data = new Uint8Array( | ||
chunks.reduce((acc, chunk) => acc + chunk.length, 0), | ||
); | ||
let offset = 0; | ||
for (const chunk of chunks) { | ||
data.set(chunk, offset); | ||
offset += chunk.length; | ||
} | ||
|
||
const hash = createHash("sha256").update(data).digest("hex"); | ||
const key = `share-urls/${hash}`; | ||
|
||
const result = await put(key, data, { | ||
addRandomSuffix: false, | ||
access: "public", | ||
}); | ||
const downloadURL = result.downloadUrl; | ||
const encodedDownloadURL = Buffer.from(downloadURL).toString("base64"); | ||
|
||
return new Response(JSON.stringify(encodedDownloadURL), { | ||
status: 200, | ||
headers: { "Content-Type": "application/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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,17 @@ | |
"packageManager": "[email protected]", | ||
"type": "module", | ||
"scripts": { | ||
"dev:vercel": "cd .. && vercel dev", | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@monaco-editor/react": "^4.6.0", | ||
"@radix-ui/react-dropdown-menu": "^2.1.4", | ||
"@radix-ui/react-progress": "^1.1.1", | ||
"@radix-ui/react-slot": "^1.1.1", | ||
"@speakeasy-api/moonshine": "^0.52.3", | ||
"class-variance-authority": "^0.7.1", | ||
"clsx": "^2.1.1", | ||
|
@@ -25,14 +28,17 @@ | |
"react-dom": "^18.2.0", | ||
"tailwind-merge": "^2.6.0", | ||
"tailwindcss-animate": "^1.0.7", | ||
"vite-plugin-svgr": "^4.3.0" | ||
"vite-plugin-svgr": "^4.3.0", | ||
"vite-plugin-vercel": "^9.0.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.10.5", | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"@typescript-eslint/eslint-plugin": "^7.2.0", | ||
"@typescript-eslint/parser": "^7.2.0", | ||
"@vercel/blob": "^0.27.0", | ||
"@vercel/node": "^5.0.2", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"autoprefixer": "^10.4.20", | ||
"eslint": "^8.57.0", | ||
|
Oops, something went wrong.