Skip to content

Commit cf26cd1

Browse files
committed
fix: address deploy typecheck
1 parent 82b426c commit cf26cd1

File tree

6 files changed

+29
-36
lines changed

6 files changed

+29
-36
lines changed

convex/httpApiV1.handlers.test.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ beforeEach(() => {
3838
vi.mocked(publishVersionForUser).mockReset()
3939
})
4040

41-
if (typeof File === 'undefined') {
42-
class NodeFile extends Blob {
43-
name: string
44-
constructor(parts: BlobPart[], name: string, options?: BlobPropertyBag) {
45-
super(parts, options)
46-
this.name = name
47-
}
48-
}
49-
const globalFile = globalThis as typeof globalThis & { File?: typeof File }
50-
globalFile.File = NodeFile
51-
}
52-
5341
describe('httpApiV1 handlers', () => {
5442
it('search returns empty results for blank query', async () => {
5543
const runAction = vi.fn()
@@ -425,7 +413,7 @@ describe('httpApiV1 handlers', () => {
425413
tags: ['latest'],
426414
}),
427415
)
428-
form.append('files', new File(['hello'], 'SKILL.md', { type: 'text/plain' }))
416+
form.append('files', new Blob(['hello'], { type: 'text/plain' }), 'SKILL.md')
429417
const response = await __handlers.publishSkillV1Handler(
430418
makeCtx({ runMutation, storage: { store: vi.fn().mockResolvedValue('storage:1') } }),
431419
new Request('https://example.com/api/v1/skills', {

convex/httpApiV1.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,15 @@ type FileLike = {
375375
arrayBuffer: () => Promise<ArrayBuffer>
376376
}
377377

378-
function isFileLike(entry: FormDataEntryValue): entry is FileLike {
379-
if (typeof entry === 'string') return false
380-
if (typeof File !== 'undefined' && entry instanceof File) return true
378+
type FileLikeEntry = FormDataEntryValue & FileLike
379+
380+
function toFileLike(entry: FormDataEntryValue): FileLikeEntry | null {
381+
if (typeof entry === 'string') return null
381382
const candidate = entry as Partial<FileLike>
382-
return (
383-
typeof candidate.name === 'string' &&
384-
typeof candidate.size === 'number' &&
385-
typeof candidate.type === 'string' &&
386-
typeof candidate.arrayBuffer === 'function'
387-
)
383+
if (typeof candidate.name !== 'string') return null
384+
if (typeof candidate.size !== 'number') return null
385+
if (typeof candidate.arrayBuffer !== 'function') return null
386+
return entry as FileLikeEntry
388387
}
389388

390389
async function skillsPostRouterV1Handler(ctx: ActionCtx, request: Request) {
@@ -496,13 +495,14 @@ async function parseMultipartPublish(
496495
}> = []
497496

498497
for (const entry of form.getAll('files')) {
499-
if (!isFileLike(entry)) continue
500-
const path = entry.name
501-
const size = entry.size
502-
const contentType = entry.type || undefined
503-
const buffer = new Uint8Array(await entry.arrayBuffer())
498+
const file = toFileLike(entry)
499+
if (!file) continue
500+
const path = file.name
501+
const size = file.size
502+
const contentType = file.type || undefined
503+
const buffer = new Uint8Array(await file.arrayBuffer())
504504
const sha256 = await sha256Hex(buffer)
505-
const storageId = await ctx.storage.store(entry)
505+
const storageId = await ctx.storage.store(file as Blob)
506506
files.push({ path, size, storageId, sha256, contentType })
507507
}
508508

@@ -685,8 +685,8 @@ function toOptionalNumber(value: string | null) {
685685
}
686686

687687
async function sha256Hex(bytes: Uint8Array) {
688-
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)
689-
const digest = await crypto.subtle.digest('SHA-256', buffer)
688+
const normalized = new Uint8Array(bytes)
689+
const digest = await crypto.subtle.digest('SHA-256', normalized.buffer)
690690
return toHex(new Uint8Array(digest))
691691
}
692692

e2e/clawdhub.e2e.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ describe('clawdhub e2e', () => {
319319
)
320320
expect(update.status).toBe(0)
321321

322-
const metaRes = await fetch(`${registry}${ApiRoutes.skills}/${slug}`, {
322+
const metaUrl = new URL(`${ApiRoutes.skills}/${slug}`, registry)
323+
const metaRes = await fetch(metaUrl.toString(), {
323324
headers: { Accept: 'application/json' },
324325
})
325326
expect(metaRes.status).toBe(200)

src/components/Header.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export default function Header() {
6363
>
6464
Skills
6565
</Link>
66-
<Link to="/upload">Upload</Link>
66+
<Link to="/upload" search={{ updateSlug: undefined }}>
67+
Upload
68+
</Link>
6769
<Link to="/search" search={{ q: undefined, highlighted: undefined }}>
6870
Search
6971
</Link>
@@ -94,7 +96,9 @@ export default function Header() {
9496
</Link>
9597
</DropdownMenuItem>
9698
<DropdownMenuItem asChild>
97-
<Link to="/upload">Upload</Link>
99+
<Link to="/upload" search={{ updateSlug: undefined }}>
100+
Upload
101+
</Link>
98102
</DropdownMenuItem>
99103
<DropdownMenuItem asChild>
100104
<Link to="/search" search={{ q: undefined, highlighted: undefined }}>

src/routes/dashboard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Dashboard() {
2929
<h1 className="section-title" style={{ margin: 0 }}>
3030
My Skills
3131
</h1>
32-
<Link to="/upload" className="btn btn-primary">
32+
<Link to="/upload" search={{ updateSlug: undefined }} className="btn btn-primary">
3333
<Plus className="h-4 w-4" aria-hidden="true" />
3434
Upload New Skill
3535
</Link>
@@ -40,7 +40,7 @@ function Dashboard() {
4040
<Package className="dashboard-empty-icon" aria-hidden="true" />
4141
<h2>No skills yet</h2>
4242
<p>Upload your first skill to share it with the community.</p>
43-
<Link to="/upload" className="btn btn-primary">
43+
<Link to="/upload" search={{ updateSlug: undefined }} className="btn btn-primary">
4444
<Upload className="h-4 w-4" aria-hidden="true" />
4545
Upload a Skill
4646
</Link>

src/routes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function Home() {
9393
vectors. No gatekeeping, just signal.
9494
</p>
9595
<div style={{ display: 'flex', gap: 12, marginTop: 20 }}>
96-
<Link to="/upload" className="btn btn-primary">
96+
<Link to="/upload" search={{ updateSlug: undefined }} className="btn btn-primary">
9797
Publish a skill
9898
</Link>
9999
<Link to="/search" search={{ q: undefined, highlighted: undefined }} className="btn">

0 commit comments

Comments
 (0)