Skip to content

Commit

Permalink
Merge pull request #73 from fiit-tp7-2023/download-documents-through-api
Browse files Browse the repository at this point in the history
Use document API to download documents
  • Loading branch information
brano-hozza authored Dec 11, 2023
2 parents 1d4e137 + 2cb03a6 commit ec3970b
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions components/team-info/sections/DocumentsSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,18 @@ import type { ParsedContent } from '@nuxt/content/dist/runtime/types';
import { h } from 'vue';
import { NButton } from 'naive-ui';
import { Icon } from '#components';
import type { DocumentRequestDTO } from '~/types/dtos';
const selectedOptionPath = ref('');
const { data: documents } = await useAsyncData('minute-books', () => queryContent('/').find());
// TODO: Delete PDFs in public folder and use this code to generate PDFs when the document API will be completely funcional
// import type { DocumentRequestDTO } from '~/types/dtos';
// const downloadPdf = async (doc: ParsedContent) => {
// const query: DocumentRequestDTO = {
// contentRelativePath: doc._file,
// };
// const pdf = await $fetch<Blob>('/api/document', { query });
// const link = document.createElement('a');
// link.href = URL.createObjectURL(pdf);
// link.download = doc.title as string;
// link.target = '_blank';
// link.click();
// };
const downloadPdf = (doc: ParsedContent) => {
const downloadPdf = async (doc: ParsedContent) => {
const query: DocumentRequestDTO = {
contentRelativePath: doc._file,
};
const pdf = await $fetch<Blob>('/api/document', { query });
const link = document.createElement('a');
link.href = `${doc._path}.pdf`;
link.href = URL.createObjectURL(pdf);
link.download = doc.title as string;
link.target = '_blank';
link.click();
Expand Down

0 comments on commit ec3970b

Please sign in to comment.