-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move pdf download button to Document.vue (#948)
- Loading branch information
Showing
6 changed files
with
60 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/client/hmi-client/src/services/generate-download-link.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import API from '@/api/api'; | ||
import { logger } from '@/utils/logger'; | ||
import { toQueryString } from '@/utils/query-string'; | ||
|
||
export async function generatePdfDownloadLink(doi: string) { | ||
if (!doi) return null; | ||
|
||
const query = { doi }; | ||
const URL = `/download?${toQueryString(query)}`; | ||
|
||
try { | ||
const response = await API.get(URL, { responseType: 'arraybuffer' }); | ||
const blob = new Blob([response?.data], { type: 'application/pdf' }); | ||
const pdfLink = window.URL.createObjectURL(blob); | ||
return pdfLink ?? null; | ||
} catch (error) { | ||
logger.error(`Error: Unable to download pdf for doi ${doi}: ${error}`); | ||
return null; | ||
} | ||
} |