On upload redirect to upload detail page

This commit is contained in:
Eli Ribble 2026-03-27 11:33:21 -07:00
parent 747544bb58
commit 1ad3c5a5c8
No known key found for this signature in database
4 changed files with 40 additions and 31 deletions

View file

@ -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) {

View file

@ -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);

View file

@ -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,
});

View file

@ -99,6 +99,7 @@
</template>
<script setup lang="ts">
import CSVUpload from "@/components/CSVUpload.vue";
import { router } from "@/router";
function onError(err) {
console.error("CSV upload error", err);
@ -106,7 +107,8 @@ function onError(err) {
function onFileSelected(file) {
console.log("file selected", file);
}
function onUploadSuccess(resp) {
console.log("upload success", resp);
function onUploadSuccess(data) {
console.log("upload success", data);
router.push("/_" + data.uri);
}
</script>