From 1ad3c5a5c8bc06c8c3de9712bf16130a45b7bd20 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 27 Mar 2026 11:33:21 -0700 Subject: [PATCH] On upload redirect to upload detail page --- api/handler.go | 13 ++++++- ts/components/CSVUpload.vue | 10 ++--- ts/router.ts | 42 ++++++++++----------- ts/view/configuration/UploadPoolFlyover.vue | 6 ++- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/api/handler.go b/api/handler.go index 339196d5..2bfa5f0b 100644 --- a/api/handler.go +++ b/api/handler.go @@ -125,6 +125,9 @@ func handlerJSONPost[ReqType any](f handlerFunctionPost[ReqType]) http.HandlerFu } } +type postMultipartResponse struct { + URI string `json:"uri"` +} func authenticatedHandlerPostMultipart(f handlerFunctionPostAuthenticated[[]file.Upload], collection file.Collection) http.Handler { return auth.NewEnsureAuth(func(w http.ResponseWriter, r *http.Request, u platform.User) { err := r.ParseMultipartForm(32 << 10) // 32 MB buffer @@ -151,7 +154,15 @@ func authenticatedHandlerPostMultipart(f handlerFunctionPostAuthenticated[[]file http.Error(w, e.Error(), e.Status) return } - http.Redirect(w, r, path, http.StatusFound) + body, err := json.Marshal(postMultipartResponse{ + URI: path, + }) + if err != nil { + log.Error().Err(err).Msg("failed to marshal json") + http.Error(w, "{\"message\": \"failed to marshal json\"}", http.StatusInternalServerError) + return + } + w.Write(body) }) } func respondError(w http.ResponseWriter, status int, format string, args ...any) { diff --git a/ts/components/CSVUpload.vue b/ts/components/CSVUpload.vue index d7c8762d..6113138b 100644 --- a/ts/components/CSVUpload.vue +++ b/ts/components/CSVUpload.vue @@ -250,12 +250,12 @@ const uploadFile = async () => { }); const response = await fetch(props.uploadUrl, { - method: 'POST', + body: formData, headers: { ...props.headers, // Don't set Content-Type - let browser set it with boundary }, - body: formData, + method: 'POST', }); if (!response.ok) { @@ -266,11 +266,7 @@ const uploadFile = async () => { uploadSuccess.value = true; emit('doSuccess', data); - // Reset after successful upload - setTimeout(() => { - resetUpload(); - }, 2000); - + resetUpload(); } catch (error) { errorMessage.value = error instanceof Error ? error.message : 'Upload failed'; emit('doError', error as Error); diff --git a/ts/router.ts b/ts/router.ts index ba3b91aa..400b7017 100644 --- a/ts/router.ts +++ b/ts/router.ts @@ -33,49 +33,49 @@ const routes: RouteRecordRaw[] = [ meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/communication", + path: "/_/communication", name: "Communication", component: Communication, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration", + path: "/_/configuration", name: "Configuration", component: ConfigurationRoot, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/integration", + path: "/_/configuration/integration", name: "Integration Configuration", component: ConfigurationIntegration, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/integration/arcgis", + path: "/_/configuration/integration/arcgis", name: "Arcgis Integration Configuration", component: ConfigurationIntegrationArcgis, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/organization", + path: "/_/configuration/organization", name: "Organization Configuration", component: ConfigurationOrganization, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/pesticide", + path: "/_/configuration/pesticide", name: "Pesticide Configuration", component: ConfigurationPesticide, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/pesticide/add", + path: "/_/configuration/pesticide/add", name: "Pesticide Add", component: ConfigurationPesticideAdd, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/upload", + path: "/_/configuration/upload", name: "Upload Configuration", component: ConfigurationUpload, meta: { requiresAuth: true, showSidebar: true }, @@ -84,71 +84,71 @@ const routes: RouteRecordRaw[] = [ component: ConfigurationUploadDetail, meta: { requiresAuth: true, showSidebar: true }, name: "Upload Detail", - path: "/configuration/upload/:id", + path: "/_/configuration/upload/:id", props: true, }, { - path: "/configuration/upload/pool", + path: "/_/configuration/upload/pool", name: "Pool Upload", component: ConfigurationUploadPool, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/upload/pool/flyover", + path: "/_/configuration/upload/pool/flyover", name: "Flyover Upload", component: ConfigurationUploadPoolFlyover, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/user", + path: "/_/configuration/user", name: "User Configuration", component: ConfigurationUser, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/configuration/user/add", + path: "/_/configuration/user/add", name: "User Add Configuration", component: ConfigurationUserAdd, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/intelligence", + path: "/_/intelligence", name: "Intelligence", component: Intelligence, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/oauth/refresh/arcgis", + path: "/_/oauth/refresh/arcgis", name: "Arcgis OAuth Refresh", component: OAuthRefreshArcgis, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/operations", + path: "/_/operations", name: "Operations", component: Operations, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/planning", + path: "/_/planning", name: "Planning", component: Planning, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/review", + path: "/_/review", name: "Review", component: Review, meta: { requiresAuth: true, showSidebar: true }, }, { - path: "/signin", + path: "/_/signin", name: "Signin", component: Signin, meta: { requiresAuth: false, showSidebar: false }, }, { - path: "/sudo", + path: "/_/sudo", name: "Sudo", component: Sudo, meta: { requiresAuth: true, showSidebar: true }, @@ -161,7 +161,7 @@ const routes: RouteRecordRaw[] = [ } ]; -const router = createRouter({ +export const router = createRouter({ history: createWebHistory("/"), routes, }); diff --git a/ts/view/configuration/UploadPoolFlyover.vue b/ts/view/configuration/UploadPoolFlyover.vue index 7df6b70d..afa43519 100644 --- a/ts/view/configuration/UploadPoolFlyover.vue +++ b/ts/view/configuration/UploadPoolFlyover.vue @@ -99,6 +99,7 @@