Fix query param handling in file interface (#3977)

Fixes #3944
This commit is contained in:
Rijk van Zanten
2021-02-08 17:44:36 -05:00
committed by GitHub
parent 239c021f12
commit f3cb3ddc2b
3 changed files with 15 additions and 8 deletions

View File

@@ -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 });
}

View File

@@ -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();

View 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('&')}`;
}