Skip to content

Commit b3ac520

Browse files
elemdosclaude
andcommitted
fix: add null-safety for assets array in file upload
Prevents 500 error when creating/updating records with images on projects where updated.assets may be null/undefined. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ed88109 commit b3ac520

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/routes/_tk/data/[project_id]/[collection]/+server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ async function upload_files_to_assets(
263263

264264
// Upload all files at once
265265
const updated = await pb.collection('_tk_projects').update(project_id, upload_form)
266-
const new_assets = (updated.assets as string[]).slice(before_count)
266+
const new_assets = (updated.assets as string[] || []).slice(before_count)
267267

268268
// Map uploaded filenames back to fields
269269
let new_index = 0

src/routes/_tk/data/[project_id]/[collection]/[id]/+server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ async function upload_files_to_assets(
226226
const before_count = (project.assets as string[] || []).length
227227

228228
const updated = await pb.collection('_tk_projects').update(project_id, upload_form)
229-
const new_assets = (updated.assets as string[]).slice(before_count)
229+
const new_assets = (updated.assets as string[] || []).slice(before_count)
230230

231231
let new_index = 0
232232
for (const [field_name, indices] of field_indices) {

0 commit comments

Comments
 (0)