chore: refine removal of redundant tusEndpoint in URL

This commit is contained in:
이광오 2023-07-31 20:08:47 +09:00
parent d51e23080f
commit ff6b248761
2 changed files with 12 additions and 2 deletions

View File

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

View File

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