Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Aug 21, 2024
1 parent 1ea8c46 commit 2407c2d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ui2/src/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ client.defaults.headers.common = defaultHeaders

export default client

function get_file_ext(file_name: string): string {
var arr = file_name.split(".")
return arr.pop()!
}

function get_file_basename(file_name: string): string {
var arr = file_name.split(".")
arr.pop()
return arr.join(".")
}

/*
download_file of specific document version
First gets the current `download_url`, as in case of S3 storage
(S3 private storage actually) there expiration keys are
valid for couple of minutes only
*/

async function download_file(doc_ver: DocumentVersion) {
const resp1 = await client.get(`/api/document-versions/${doc_ver.id}`)
const v = resp1.data as DocumentVersion
Expand All @@ -36,8 +46,11 @@ async function download_file(doc_ver: DocumentVersion) {
- https://stackoverflow.com/a/78401145
*/
let a = document.createElement("a")
const ext = get_file_ext(v.file_name)
const basename = get_file_basename(v.file_name)

a.href = url
a.download = doc_ver.file_name
a.download = `${basename}-v${v.number}-${v.short_description}.${ext}`
// we need to append the element to the dom -> otherwise it will not work in firefox
document.body.appendChild(a)
a.click()
Expand Down

0 comments on commit 2407c2d

Please sign in to comment.