-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: generated api * feat: Added endpoint to download files. Added button to download files * chore: Removed a space
- Loading branch information
1 parent
d84ff24
commit 99c0fdb
Showing
4 changed files
with
203 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { AnalogueModelDetail, OpenAPI, UploadFileType } from '../api/generated'; | ||
import axios from 'axios'; | ||
|
||
export const getFetchIniFileAxios = async ( | ||
analogueModel: AnalogueModelDetail, | ||
): Promise<string> => { | ||
const token = OpenAPI.TOKEN; // replace with your bearer token | ||
const base = OpenAPI.BASE; | ||
|
||
const response = await axios.get( | ||
`/api/downloads/${analogueModel.analogueModelId}/ini`, | ||
{ | ||
headers: { Authorization: `Bearer ${token}` }, | ||
responseType: 'blob', // response type of blob to handle images | ||
baseURL: base, | ||
}, | ||
); | ||
|
||
if (response.data) { | ||
const fileURL = window.URL.createObjectURL(response.data); | ||
|
||
const link = document.createElement('a'); | ||
link.href = fileURL; | ||
link.download = | ||
analogueModel.fileUploads.find( | ||
(x) => x.uploadFileType === UploadFileType.INI_DATA, | ||
)?.originalFileName || 'file.ini'; | ||
|
||
document.body.appendChild(link); | ||
link.click(); | ||
|
||
document.body.removeChild(link); | ||
URL.revokeObjectURL(fileURL); | ||
} | ||
|
||
// create an object URL for the image blob and return it | ||
return URL.createObjectURL(response.data); | ||
}; | ||
|
||
export const getFetchNcFileAxios = async ( | ||
analogueModel: AnalogueModelDetail, | ||
): Promise<string> => { | ||
const token = OpenAPI.TOKEN; // replace with your bearer token | ||
const base = OpenAPI.BASE; | ||
|
||
const response = await axios.get( | ||
`/api/downloads/${analogueModel.analogueModelId}/nc`, | ||
{ | ||
headers: { Authorization: `Bearer ${token}` }, | ||
responseType: 'blob', // response type of blob to handle images | ||
baseURL: base, | ||
}, | ||
); | ||
|
||
if (response.data) { | ||
const fileURL = window.URL.createObjectURL(response.data); | ||
|
||
const link = document.createElement('a'); | ||
link.href = fileURL; | ||
link.download = | ||
analogueModel.fileUploads.find( | ||
(x) => x.uploadFileType === UploadFileType.NET_CDF, | ||
)?.originalFileName || 'file.nc'; | ||
|
||
document.body.appendChild(link); | ||
link.click(); | ||
|
||
document.body.removeChild(link); | ||
URL.revokeObjectURL(fileURL); | ||
} | ||
|
||
// create an object URL for the image blob and return it | ||
return URL.createObjectURL(response.data); | ||
}; | ||
|
||
export const getFetchResqmlFileAxios = async ( | ||
analogueModel: AnalogueModelDetail, | ||
): Promise<string> => { | ||
const token = OpenAPI.TOKEN; // replace with your bearer token | ||
const base = OpenAPI.BASE; | ||
|
||
const response = await axios.get( | ||
`/api/downloads/${analogueModel.analogueModelId}/resqml`, | ||
{ | ||
headers: { Authorization: `Bearer ${token}` }, | ||
responseType: 'blob', // response type of blob to handle images | ||
baseURL: base, | ||
}, | ||
); | ||
|
||
if (response.data) { | ||
const fileURL = window.URL.createObjectURL(response.data); | ||
|
||
const link = document.createElement('a'); | ||
link.href = fileURL; | ||
link.download = 'Resqml.zip'; | ||
|
||
document.body.appendChild(link); | ||
link.click(); | ||
|
||
document.body.removeChild(link); | ||
URL.revokeObjectURL(fileURL); | ||
} | ||
|
||
// create an object URL for the image blob and return it | ||
return URL.createObjectURL(response.data); | ||
}; |
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