mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
@@ -2,6 +2,7 @@ import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
|
||||
import { useRequestsStore } from '@/stores/';
|
||||
import { LogoutReason, logout, refresh } from '@/auth';
|
||||
import { getRootPath } from '@/utils/get-root-path';
|
||||
import { addQueryToPath } from './utils/add-query-to-path';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: getRootPath(),
|
||||
@@ -96,10 +97,7 @@ function getToken() {
|
||||
|
||||
export function addTokenToURL(url: string, token?: string) {
|
||||
token = token || getToken();
|
||||
if (!token) return url;
|
||||
|
||||
if (url.includes('?')) {
|
||||
return (url += '&access_token=' + token);
|
||||
} else {
|
||||
return (url += '?access_token=' + token);
|
||||
}
|
||||
return addQueryToPath(url, { access_token: token });
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ import { getRootPath } from '@/utils/get-root-path';
|
||||
import { unexpectedError } from '@/utils/unexpected-error';
|
||||
import { addTokenToURL } from '@/api';
|
||||
import DrawerItem from '../../views/private/components/drawer-item';
|
||||
import { addQueryToPath } from '../../utils/add-query-to-path';
|
||||
|
||||
type FileInfo = {
|
||||
id: string;
|
||||
@@ -168,10 +169,9 @@ export default defineComponent({
|
||||
|
||||
const imageThumbnail = computed(() => {
|
||||
if (file.value === null || props.value === null) return null;
|
||||
if (file.value.type.includes('svg')) return addTokenToURL(assetURL.value);
|
||||
if (file.value.type.includes('svg')) return assetURL.value;
|
||||
if (file.value.type.includes('image') === false) return null;
|
||||
const url = assetURL.value + `?key=system-small-cover`;
|
||||
return addTokenToURL(url);
|
||||
return addQueryToPath(assetURL.value, { key: 'system-small-cover' });
|
||||
});
|
||||
|
||||
const { edits, stageEdits } = useEdits();
|
||||
|
||||
9
app/src/utils/add-query-to-path.ts
Normal file
9
app/src/utils/add-query-to-path.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function addQueryToPath(path: string, query: Record<string, string>) {
|
||||
const queryParams = [];
|
||||
|
||||
for (const [key, value] of Object.entries(query)) {
|
||||
queryParams.push(`${key}=${value}`);
|
||||
}
|
||||
|
||||
return path.includes('?') ? `${path}&${queryParams.join('&')}` : `${path}?${queryParams.join('&')}`;
|
||||
}
|
||||
Reference in New Issue
Block a user