finally a real working compat for webdav
This commit is contained in:
parent
2d7c33fb1a
commit
9519793860
@ -30,6 +30,7 @@ if (VALID_REQURL) {
|
|||||||
delete transformedHeaders["Host"];
|
delete transformedHeaders["Host"];
|
||||||
delete transformedHeaders["content-length"];
|
delete transformedHeaders["content-length"];
|
||||||
delete transformedHeaders["Content-Length"];
|
delete transformedHeaders["Content-Length"];
|
||||||
|
|
||||||
const r = await requestUrl({
|
const r = await requestUrl({
|
||||||
url: options.url,
|
url: options.url,
|
||||||
method: options.method,
|
method: options.method,
|
||||||
@ -47,48 +48,60 @@ if (VALID_REQURL) {
|
|||||||
if (contentType !== undefined) {
|
if (contentType !== undefined) {
|
||||||
contentType = contentType.toLowerCase();
|
contentType = contentType.toLowerCase();
|
||||||
}
|
}
|
||||||
// console.log(`contentType=${contentType}`)
|
// console.log(`requesting url=${options.url}`);
|
||||||
|
// console.log(`contentType=${contentType}`);
|
||||||
|
|
||||||
let r2: Response = undefined;
|
// let r2: Response = undefined;
|
||||||
if (contentType.includes("xml")) {
|
// if (contentType.includes("xml")) {
|
||||||
r2 = new Response(r.text, {
|
// r2 = new Response(r.text, {
|
||||||
status: r.status,
|
// status: r.status,
|
||||||
statusText: getReasonPhrase(r.status),
|
// statusText: getReasonPhrase(r.status),
|
||||||
headers: r.headers,
|
// headers: r.headers,
|
||||||
});
|
// });
|
||||||
} else if (
|
// } else if (
|
||||||
contentType.includes("json") ||
|
// contentType.includes("json") ||
|
||||||
contentType.includes("javascript")
|
// contentType.includes("javascript")
|
||||||
) {
|
// ) {
|
||||||
r2 = new Response(r.json, {
|
// console.log('inside json branch');
|
||||||
status: r.status,
|
// // const j = r.json;
|
||||||
statusText: getReasonPhrase(r.status),
|
// // console.log(j);
|
||||||
headers: r.headers,
|
// r2 = new Response(
|
||||||
});
|
// r.text, // yea, here is the text because Response constructor expects a text
|
||||||
} else if (contentType.includes("text")) {
|
// {
|
||||||
// avoid text/json,
|
// status: r.status,
|
||||||
// so we split this out from the above xml or json branch
|
// statusText: getReasonPhrase(r.status),
|
||||||
r2 = new Response(r.text, {
|
// headers: r.headers,
|
||||||
status: r.status,
|
// });
|
||||||
statusText: getReasonPhrase(r.status),
|
// } else if (contentType.includes("text")) {
|
||||||
headers: r.headers,
|
// // avoid text/json,
|
||||||
});
|
// // so we split this out from the above xml or json branch
|
||||||
} else if (
|
// r2 = new Response(r.text, {
|
||||||
contentType.includes("octet-stream") ||
|
// status: r.status,
|
||||||
contentType.includes("binary") ||
|
// statusText: getReasonPhrase(r.status),
|
||||||
contentType.includes("buffer")
|
// headers: r.headers,
|
||||||
) {
|
// });
|
||||||
// application/octet-stream
|
// } else if (
|
||||||
r2 = new Response(r.arrayBuffer, {
|
// contentType.includes("octet-stream") ||
|
||||||
status: r.status,
|
// contentType.includes("binary") ||
|
||||||
statusText: getReasonPhrase(r.status),
|
// contentType.includes("buffer")
|
||||||
headers: r.headers,
|
// ) {
|
||||||
});
|
// // application/octet-stream
|
||||||
} else {
|
// r2 = new Response(r.arrayBuffer, {
|
||||||
throw Error(
|
// status: r.status,
|
||||||
`do not know how to deal with requested content type = ${contentType}`
|
// statusText: getReasonPhrase(r.status),
|
||||||
);
|
// headers: r.headers,
|
||||||
}
|
// });
|
||||||
|
// } else {
|
||||||
|
// throw Error(
|
||||||
|
// `do not know how to deal with requested content type = ${contentType}`
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
const r2 = new Response(r.arrayBuffer, {
|
||||||
|
status: r.status,
|
||||||
|
statusText: getReasonPhrase(r.status),
|
||||||
|
headers: r.headers,
|
||||||
|
});
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -444,9 +457,9 @@ const downloadFromRemoteRaw = async (
|
|||||||
fileOrFolderPath: string
|
fileOrFolderPath: string
|
||||||
) => {
|
) => {
|
||||||
await client.init();
|
await client.init();
|
||||||
const buff = (await client.client.getFileContents(
|
const p = getWebdavPath(fileOrFolderPath, client.remoteBaseDir);
|
||||||
getWebdavPath(fileOrFolderPath, client.remoteBaseDir)
|
// console.log(`getWebdavPath=${p}`);
|
||||||
)) as BufferLike;
|
const buff = (await client.client.getFileContents(p)) as BufferLike;
|
||||||
if (buff instanceof ArrayBuffer) {
|
if (buff instanceof ArrayBuffer) {
|
||||||
return buff;
|
return buff;
|
||||||
} else if (buff instanceof Buffer) {
|
} else if (buff instanceof Buffer) {
|
||||||
@ -485,6 +498,7 @@ export const downloadFromRemote = async (
|
|||||||
downloadFile = remoteEncryptedKey;
|
downloadFile = remoteEncryptedKey;
|
||||||
}
|
}
|
||||||
downloadFile = getWebdavPath(downloadFile, client.remoteBaseDir);
|
downloadFile = getWebdavPath(downloadFile, client.remoteBaseDir);
|
||||||
|
// console.log(`downloadFile=${downloadFile}`);
|
||||||
const remoteContent = await downloadFromRemoteRaw(client, downloadFile);
|
const remoteContent = await downloadFromRemoteRaw(client, downloadFile);
|
||||||
let localContent = remoteContent;
|
let localContent = remoteContent;
|
||||||
if (password !== "") {
|
if (password !== "") {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user