From b4dd90ccd6fd255d6593cb49672964bde4050bfa Mon Sep 17 00:00:00 2001 From: nijmra Date: Mon, 18 Nov 2024 16:57:57 +0100 Subject: [PATCH] rollback, api version --- odpc.client/src/features/publicatie/service.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/odpc.client/src/features/publicatie/service.ts b/odpc.client/src/features/publicatie/service.ts index 067c47b..f229b74 100644 --- a/odpc.client/src/features/publicatie/service.ts +++ b/odpc.client/src/features/publicatie/service.ts @@ -2,6 +2,8 @@ import { ref } from "vue"; import { useFetchApi } from "@/api/use-fetch-api"; import type { Bestandsdeel, MimeType } from "./types"; +const API_URL = `/api/v1`; + const mimeTypesMap = ref | null>(null); (async () => { @@ -10,6 +12,17 @@ const mimeTypesMap = ref | null>(null); mimeTypesMap.value = new Map(data.value?.map((type) => [type.mimeType, type])); })(); +const parseUrl = (url: string) => { + const regex = /\/documenten\/(?[a-f0-9-]+)\/bestandsdelen\/(?[a-f0-9-]+)/; + const match = url.match(regex); + + if (match && match.groups) { + return match.groups; + } else { + throw new Error("Invalid URL format"); + } +}; + const uploadFile = async (file: File, bestandsdelen: Bestandsdeel[]) => { let blobStart = 0; @@ -17,14 +30,14 @@ const uploadFile = async (file: File, bestandsdelen: Bestandsdeel[]) => { try { for (const { url, omvang } of bestandsdelen) { - const { pathname } = new URL(url); + const { docUuid, partUuid } = parseUrl(url); const body = new FormData(); const blob = file.slice(blobStart, blobStart + omvang); body.append("inhoud", blob); - const { ok } = await fetch(pathname, { + const { ok } = await fetch(`${API_URL}/documenten/${docUuid}/bestandsdelen/${partUuid}`, { method: "PUT", body });