Skip to content

Commit 9e15632

Browse files
authored
chore: share links (#9)
* chore: share links * chore: clean up re-render * chore: cleanup * chore: more minimalg * chore: lint errors * chore: use vercel url
1 parent 7d21717 commit 9e15632

21 files changed

+1937
-65
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.idea
22
dist
3-
*.iml
3+
*.iml
4+
.vercel
5+
.env*.local

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
SOURCE=$(shell find . -iname "*.go")
33

4-
5-
64
web/src/assets/wasm/lib.wasm: $(SOURCE)
75
mkdir -p dist
86
rm -f dist/*

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/speakeasy-api/jsonpath
22

3-
go 1.21.0
4-
5-
toolchain go1.22.2
3+
go 1.22
64

75
require (
86
github.com/pmezard/go-difflib v1.0.0

pkg/overlay/parse_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package overlay_test
22

33
import (
4+
"github.com/speakeasy-api/jsonpath/pkg/overlay"
45
"github.com/stretchr/testify/assert"
56
"github.com/stretchr/testify/require"
67
"os"

pkg/overlay/testdata/overlay.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ actions:
3535
update:
3636
- name: Testing
3737
description: just a description
38-
- target: $.paths["/anything/selectGlobalServer"].x-my-ignore
38+
- target: $.paths["/anything/selectGlobalServer"]["x-my-ignore"]
3939
update:
4040
servers:
4141
- url: http://localhost:35123

web/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
.vercel

web/api/share.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { put } from "@vercel/blob";
2+
import { createHash } from "crypto";
3+
4+
const MAX_DATA_SIZE = 5 * 1024 * 1024; // 5MB
5+
const AllowedOrigin = process.env.VERCEL_URL ?? "http://localhost";
6+
7+
export function POST(request: Request) {
8+
const origin = request.headers.get("Origin");
9+
10+
if (!origin || !origin.includes(AllowedOrigin)) {
11+
return new Response("Unauthorized", { status: 403 });
12+
}
13+
14+
return new Promise<Response>((resolve, reject) => {
15+
const body: ReadableStream | null = request.body;
16+
if (!body) {
17+
reject(new Error("No body"));
18+
return;
19+
}
20+
21+
const reader = body.getReader();
22+
const chunks: Uint8Array[] = [];
23+
24+
const readData = (): void => {
25+
reader.read().then(({ done, value }) => {
26+
if (done) {
27+
processData(chunks).then(resolve).catch(reject);
28+
} else {
29+
chunks.push(value);
30+
if (
31+
chunks.reduce((acc, chunk) => acc + chunk.length, 0) > MAX_DATA_SIZE
32+
) {
33+
reject(new Error("Data exceeds the maximum allowed size of 5MB"));
34+
} else {
35+
readData();
36+
}
37+
}
38+
});
39+
};
40+
41+
readData();
42+
});
43+
}
44+
45+
async function processData(chunks: Uint8Array[]): Promise<Response> {
46+
const data = new Uint8Array(
47+
chunks.reduce((acc, chunk) => acc + chunk.length, 0),
48+
);
49+
let offset = 0;
50+
for (const chunk of chunks) {
51+
data.set(chunk, offset);
52+
offset += chunk.length;
53+
}
54+
55+
const hash = createHash("sha256").update(data).digest("hex");
56+
const key = `share-urls/${hash}`;
57+
58+
const result = await put(key, data, {
59+
addRandomSuffix: false,
60+
access: "public",
61+
});
62+
const downloadURL = result.downloadUrl;
63+
const encodedDownloadURL = Buffer.from(downloadURL).toString("base64");
64+
65+
return new Response(JSON.stringify(encodedDownloadURL), {
66+
status: 200,
67+
headers: { "Content-Type": "application/json" },
68+
});
69+
}

web/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
"packageManager": "[email protected]",
66
"type": "module",
77
"scripts": {
8+
"dev:vercel": "cd .. && vercel dev",
89
"dev": "vite",
910
"build": "tsc && vite build",
1011
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1112
"preview": "vite preview"
1213
},
1314
"dependencies": {
1415
"@monaco-editor/react": "^4.6.0",
16+
"@radix-ui/react-dropdown-menu": "^2.1.4",
1517
"@radix-ui/react-progress": "^1.1.1",
18+
"@radix-ui/react-slot": "^1.1.1",
1619
"@speakeasy-api/moonshine": "^0.52.3",
1720
"class-variance-authority": "^0.7.1",
1821
"clsx": "^2.1.1",
@@ -25,14 +28,17 @@
2528
"react-dom": "^18.2.0",
2629
"tailwind-merge": "^2.6.0",
2730
"tailwindcss-animate": "^1.0.7",
28-
"vite-plugin-svgr": "^4.3.0"
31+
"vite-plugin-svgr": "^4.3.0",
32+
"vite-plugin-vercel": "^9.0.4"
2933
},
3034
"devDependencies": {
3135
"@types/node": "^22.10.5",
3236
"@types/react": "^18.2.66",
3337
"@types/react-dom": "^18.2.22",
3438
"@typescript-eslint/eslint-plugin": "^7.2.0",
3539
"@typescript-eslint/parser": "^7.2.0",
40+
"@vercel/blob": "^0.27.0",
41+
"@vercel/node": "^5.0.2",
3642
"@vitejs/plugin-react": "^4.2.1",
3743
"autoprefixer": "^10.4.20",
3844
"eslint": "^8.57.0",

0 commit comments

Comments
 (0)