This commit is contained in:
j3d1 2026-08-22 23:29:02 +02:00
parent 3299c97392
commit de7d9426be
10 changed files with 259 additions and 99 deletions

View file

@ -28,6 +28,7 @@ import Scan from "@/views/Scan.vue";
import Workflows from '@/views/Workflows.vue';
import WorkflowDetail from '@/views/WorkflowDetail.vue';
import ShortId from '@/views/ShortId.vue';
import {encodeShortId, serializeShortId,decodeShortId, deserializeShortId} from '@/short-id';
import Account from '@/views/settings/Account.vue';
import Password from '@/views/settings/Password.vue';
@ -46,6 +47,23 @@ export function decodeHandleFromUrl(segment) {
return segment.replace(/\+/g, "#");
}
const EXPANDED_ROUTE_BUILDERS = {
item: ({item_local_id}) => `/inventory/${item_local_id}`,
group_item: ({item_local_id}) => `/inventory/${item_local_id}`,
group: ({group_id}) => `/groups/${group_id}`,
storage_location: ({storage_location_id}) => `/storage-locations/${storage_location_id}`,
workflow: ({workflow_id}) => `/workflows/${workflow_id}`,
};
export function expandedRoute({kind, ...fields}) {
const buildRoute = EXPANDED_ROUTE_BUILDERS[kind];
return buildRoute ? buildRoute(fields) : null;
}
export function shortenedRoute(named) {
return '/' + encodeShortId(serializeShortId(named));
}
const routes = [{path: '/', component: Dashboard, meta: {requiresAuth: true}}, {
path: '/inventory',
component: Inventory,
@ -72,6 +90,16 @@ const routes = [{path: '/', component: Dashboard, meta: {requiresAuth: true}}, {
const {id} = to.params
return handle === store.state.user ? '/inventory/' + id : '/inventory/shared/' + encodeHandleForUrl(handle) + '/' + id
}
}, {
path: '/:short_id',
redirect: to => {
console.log(to)
const p = deserializeShortId(decodeShortId(to.params.short_id))
console.log(p)
const url = expandedRoute(p)
console.log(url)
return url;
}
}, {path: '/inventory/new', component: InventoryNew, meta: {requiresAuth: true}}, {
path: '/friends',
component: Friends,
@ -161,9 +189,14 @@ const routes = [{path: '/', component: Dashboard, meta: {requiresAuth: true}}, {
component: StorageLocationNew,
meta: {requiresAuth: true}
}, {
path: '/:short_id',
path: '/debug/:short_id',
component: ShortId,
props: true
}, {
path: '/:short_id',
redirect: to => {
}
}, {path: '/:pathMatch(.*)*', redirect: '/'}]
const router = createRouter({