Skip to content

Commit 1172351

Browse files
committed
fix: upload on non-new postings
1 parent 5c8fc27 commit 1172351

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/lib/server/filesystem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export const fetchImage = async (postingId: string, filename: string) => {
3838
}
3939
}
4040

41-
export const saveImage = async (file: File, postingId: string|undefined) => {
42-
const directoryPart = postingId && postingId.length > 0 ? postingId : 'new';
41+
export const saveImage = async (file: File, postingId: string | undefined) => {
42+
const directoryPart = postingId && postingId.length > 0 ? postingId : 'new'
4343
const uploadDir = path.join(DATA_DIRECTORY, directoryPart)
4444

4545
if (!fs.existsSync(uploadDir)) {

src/routes/(admin)/api/upload/+server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IMAGE_MIME_TYPES, saveImage } from '$lib/server/filesystem.ts'
44

55
const fileSchema = z.object({
66
file: z.file().mime(IMAGE_MIME_TYPES),
7-
posting_id: z.union([z.string().nonempty(), z.undefined()])
7+
postingId: z.union([z.string().nonempty(), z.undefined()])
88
})
99

1010
export async function POST({ request }) {
@@ -16,7 +16,7 @@ export async function POST({ request }) {
1616

1717
try {
1818
const file = result.data.file
19-
await saveImage(file, result.data.posting_id)
19+
await saveImage(file, result.data.postingId)
2020

2121
return json({ success: true })
2222
} catch (err) {

src/routes/(admin)/posting/PostingForm.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
uploading = true
7979
const formData = new FormData()
8080
formData.append('file', file)
81+
formData.append('postingId', posting?.id ?? '')
8182
8283
try {
8384
// Use a consistent upload endpoint, or pass this as a prop if they strictly differ

0 commit comments

Comments
 (0)