-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
71 additions
and
118 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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import {authenticatedRequest} from "../lib/api"; | ||
import apiClient from "../lib/api"; | ||
|
||
export function Download(url, callback, errCallback) { | ||
authenticatedRequest({ | ||
url: '/downloads', | ||
method: 'POST', | ||
data: { | ||
url, | ||
}, | ||
}).then(() => callback()); | ||
apiClient.post('/downloads', { | ||
url, | ||
}).then(() => callback()).catch(errCallback); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import axios from "axios"; | ||
import config from '../config'; | ||
import {oauthClient} from "../oauth"; | ||
import {configureClientAuthentication, createHttpClient} from "@alchemy/auth"; | ||
|
||
export const apiClient = axios.create({ | ||
baseURL: config.baseUrl, | ||
}) | ||
const apiClient = createHttpClient(config.baseUrl); | ||
|
||
export function authenticatedRequest(config) { | ||
return oauthClient.wrapPromiseWithValidToken(async ({access_token, token_type}) => { | ||
return (await apiClient.request({ | ||
...config, | ||
headers: { | ||
Authorization: `${token_type} ${access_token}`, | ||
...(config.headers ?? {}), | ||
}, | ||
})).data; | ||
}); | ||
} | ||
configureClientAuthentication(apiClient, oauthClient, () => { | ||
alert('Your session has expired'); | ||
}); | ||
|
||
export default apiClient; |
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 |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import {authenticatedRequest} from "./lib/api"; | ||
import apiClient from "./lib/api"; | ||
|
||
export function getFormSchema(targetId) { | ||
return authenticatedRequest({ | ||
url: `/targets/${targetId}/form-schema`, | ||
}); | ||
export async function getFormSchema(targetId) { | ||
return (await apiClient.get(`/targets/${targetId}/form-schema`)).data; | ||
} | ||
|
||
export async function getTargets() { | ||
return (await authenticatedRequest({ | ||
url: `/targets`, | ||
}))['hydra:member']; | ||
return (await apiClient.get(`/targets`)).data['hydra:member']; | ||
} | ||
|
||
export function getTarget(id) { | ||
return authenticatedRequest({ | ||
url: `/targets/${id}`, | ||
}); | ||
export async function getTarget(id) { | ||
return (await apiClient.get(`/targets/${id}`)).data; | ||
} | ||
|
||
export function getTargetParams(targetId) { | ||
return authenticatedRequest({ | ||
url: `/target-params`, | ||
export async function getTargetParams(targetId) { | ||
return (await apiClient.get(`/target-params`, { | ||
params: { | ||
target: targetId, | ||
}, | ||
}); | ||
})).data['hydra:member']; | ||
} |
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