2022-12-26 10:35:52 -05:00
|
|
|
import { AxiosError, AxiosPromise } from 'axios';
|
|
|
|
|
import { api } from './api';
|
|
|
|
|
import { UserResponseDto } from './open-api';
|
|
|
|
|
|
2022-09-08 17:30:49 +02:00
|
|
|
const _basePath = '/api';
|
2022-08-24 10:21:41 +07:00
|
|
|
|
2023-01-09 14:16:08 -06:00
|
|
|
export function getFileUrl(assetId: string, isThumb?: boolean, isWeb?: boolean, key?: string) {
|
2022-11-16 00:11:16 -06:00
|
|
|
const urlObj = new URL(`${window.location.origin}${_basePath}/asset/file/${assetId}`);
|
2022-08-24 10:21:41 +07:00
|
|
|
|
2022-09-04 08:34:39 -05:00
|
|
|
if (isThumb !== undefined && isThumb !== null)
|
|
|
|
|
urlObj.searchParams.append('isThumb', `${isThumb}`);
|
|
|
|
|
if (isWeb !== undefined && isWeb !== null) urlObj.searchParams.append('isWeb', `${isWeb}`);
|
|
|
|
|
|
2023-01-09 14:16:08 -06:00
|
|
|
if (key !== undefined && key !== null) urlObj.searchParams.append('key', key);
|
2022-09-04 08:34:39 -05:00
|
|
|
return urlObj.href;
|
2022-08-24 10:21:41 +07:00
|
|
|
}
|
2022-12-26 10:35:52 -05:00
|
|
|
|
|
|
|
|
export type ApiError = AxiosError<{ message: string }>;
|
|
|
|
|
|
|
|
|
|
export const oauth = {
|
|
|
|
|
isCallback: (location: Location) => {
|
|
|
|
|
const search = location.search;
|
|
|
|
|
return search.includes('code=') || search.includes('error=');
|
|
|
|
|
},
|
|
|
|
|
getConfig: (location: Location) => {
|
|
|
|
|
const redirectUri = location.href.split('?')[0];
|
|
|
|
|
console.log(`OAuth Redirect URI: ${redirectUri}`);
|
|
|
|
|
return api.oauthApi.generateConfig({ redirectUri });
|
|
|
|
|
},
|
|
|
|
|
login: (location: Location) => {
|
|
|
|
|
return api.oauthApi.callback({ url: location.href });
|
|
|
|
|
},
|
|
|
|
|
link: (location: Location): AxiosPromise<UserResponseDto> => {
|
|
|
|
|
return api.oauthApi.link({ url: location.href });
|
|
|
|
|
},
|
|
|
|
|
unlink: () => {
|
|
|
|
|
return api.oauthApi.unlink();
|
|
|
|
|
}
|
|
|
|
|
};
|