sync webdav cors
This commit is contained in:
@@ -102,6 +102,7 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @connect githubusercontent.com
|
// @connect githubusercontent.com
|
||||||
// @connect kiss-translator.rayjar.com
|
// @connect kiss-translator.rayjar.com
|
||||||
// @connect ghproxy.com
|
// @connect ghproxy.com
|
||||||
|
// @connect dav.jianguoyun.com
|
||||||
// @connect localhost:3000
|
// @connect localhost:3000
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const fetchGM = async (input, { method = "GET", headers, body } = {}) =>
|
|||||||
headers,
|
headers,
|
||||||
data: body,
|
data: body,
|
||||||
onload: (response) => {
|
onload: (response) => {
|
||||||
if (response.status === 200) {
|
if (response.status < 300) {
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
response.responseHeaders.split("\n").forEach((line) => {
|
response.responseHeaders.split("\n").forEach((line) => {
|
||||||
const [name, value] = line.split(":").map((item) => item.trim());
|
const [name, value] = line.split(":").map((item) => item.trim());
|
||||||
@@ -66,7 +66,7 @@ const newCacheReq = async (request) => {
|
|||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const fetchApi = async ({ input, init = {}, translator, token }) => {
|
export const fetchApi = async ({ input, init = {}, translator, token }) => {
|
||||||
if (token) {
|
if (token) {
|
||||||
if (translator === OPT_TRANS_DEEPL) {
|
if (translator === OPT_TRANS_DEEPL) {
|
||||||
init.headers["Authorization"] = `DeepL-Auth-Key ${token}`; // DeepL
|
init.headers["Authorization"] = `DeepL-Auth-Key ${token}`; // DeepL
|
||||||
|
|||||||
@@ -16,7 +16,15 @@ import {
|
|||||||
} from "./storage";
|
} from "./storage";
|
||||||
import { apiSyncData } from "../apis";
|
import { apiSyncData } from "../apis";
|
||||||
import { sha256 } from "./utils";
|
import { sha256 } from "./utils";
|
||||||
import { createClient } from "webdav";
|
import { createClient, getPatcher } from "webdav";
|
||||||
|
import { fetchApi } from "./fetch";
|
||||||
|
|
||||||
|
getPatcher().patch("request", (opts) => {
|
||||||
|
return fetchApi({
|
||||||
|
input: opts.url,
|
||||||
|
init: { method: opts.method, headers: opts.headers, body: opts.data },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const syncByWebdav = async ({
|
const syncByWebdav = async ({
|
||||||
key,
|
key,
|
||||||
|
|||||||
Reference in New Issue
Block a user