Skip to content

Commit

Permalink
rollback, api version
Browse files Browse the repository at this point in the history
  • Loading branch information
nijmra committed Nov 18, 2024
1 parent 642c071 commit b4dd90c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions odpc.client/src/features/publicatie/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<string, MimeType> | null>(null);

(async () => {
Expand All @@ -10,21 +12,32 @@ const mimeTypesMap = ref<Map<string, MimeType> | null>(null);
mimeTypesMap.value = new Map(data.value?.map((type) => [type.mimeType, type]));
})();

const parseUrl = (url: string) => {
const regex = /\/documenten\/(?<docUuid>[a-f0-9-]+)\/bestandsdelen\/(?<partUuid>[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;

bestandsdelen.sort((a, b) => a.volgnummer - b.volgnummer);

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
});
Expand Down

0 comments on commit b4dd90c

Please sign in to comment.