chore: refine removal of redundant tusEndpoint in URL
This commit is contained in:
parent
d51e23080f
commit
ff6b248761
@ -1,7 +1,8 @@
|
|||||||
import { createURL, fetchURL, removePrefix } from "./utils";
|
import { createURL, fetchURL, removePrefix, removeTusEndpoint } from "./utils";
|
||||||
import { baseURL } from "@/utils/constants";
|
import { baseURL } from "@/utils/constants";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import { upload as postTus, useTus } from "./tus";
|
import { upload as postTus, useTus } from "./tus";
|
||||||
|
import {tusEndpoint} from "../utils/constants";
|
||||||
|
|
||||||
export async function fetch(url) {
|
export async function fetch(url) {
|
||||||
url = removePrefix(url);
|
url = removePrefix(url);
|
||||||
@ -88,7 +89,9 @@ export async function post(url, content = "", overwrite = false, onupload) {
|
|||||||
!["http:", "https:"].includes(window.location.protocol)) ||
|
!["http:", "https:"].includes(window.location.protocol)) ||
|
||||||
// Tus is disabled / not applicable
|
// Tus is disabled / not applicable
|
||||||
!(await useTus(content));
|
!(await useTus(content));
|
||||||
|
if (!useResourcesApi) {
|
||||||
|
url = removeTusEndpoint(tusEndpoint, url)
|
||||||
|
}
|
||||||
return useResourcesApi
|
return useResourcesApi
|
||||||
? postResources(url, content, overwrite, onupload)
|
? postResources(url, content, overwrite, onupload)
|
||||||
: postTus(url, content, overwrite, onupload);
|
: postTus(url, content, overwrite, onupload);
|
||||||
|
|||||||
@ -83,3 +83,10 @@ export function createURL(endpoint, params = {}, auth = true) {
|
|||||||
|
|
||||||
return url.toString();
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeTusEndpoint(tusEndpoint, url) {
|
||||||
|
if (url.startsWith(tusEndpoint)) {
|
||||||
|
return url.substring(tusEndpoint.length);
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user