mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
iOS: Fixes #2103: Fix issue when WebDAV server redirects certain API calls
This commit is contained in:
parent
7baeb223f3
commit
40753296c4
@ -120,153 +120,8 @@ class FileApiDriverWebDav {
|
||||
}
|
||||
|
||||
async list(path) {
|
||||
// const relativeBaseUrl = this.api().relativeBaseUrl();
|
||||
|
||||
// function parsePropFindXml(xmlString) {
|
||||
// return new Promise(async (resolve, reject) => {
|
||||
// const saxOptions = {};
|
||||
// const saxParser = require('sax').parser(false, { position: false });
|
||||
|
||||
// let stats = [];
|
||||
// let currentStat = null;
|
||||
// let currentText = '';
|
||||
|
||||
// // When this is on, the tags from the bloated XML string are replaced by shorter ones,
|
||||
// // which makes parsing about 25% faster. However it's a bit of a hack so keep it as
|
||||
// // an option so that it can be disabled if it causes problems.
|
||||
// const optimizeXml = true;
|
||||
|
||||
// const tagResponse = optimizeXml ? 'd:r' : 'd:response';
|
||||
// const tagGetLastModified = optimizeXml ? 'd:glm' : 'd:getlastmodified';
|
||||
// const tagPropStat = optimizeXml ? 'd:ps' : 'd:propstat';
|
||||
// const replaceUrls = optimizeXml;
|
||||
|
||||
// saxParser.onerror = function (error) {
|
||||
// reject(new Error(e.toString()));
|
||||
// };
|
||||
|
||||
// saxParser.ontext = function (t) {
|
||||
// currentText += t;
|
||||
// };
|
||||
|
||||
// saxParser.onopentag = function (node) {
|
||||
// const tagName = node.name.toLowerCase();
|
||||
|
||||
// currentText = '';
|
||||
|
||||
// if (tagName === tagResponse) {
|
||||
// currentStat = { isDir: false };
|
||||
// }
|
||||
// };
|
||||
|
||||
// saxParser.onclosetag = function(tagName) {
|
||||
// tagName = tagName.toLowerCase();
|
||||
|
||||
// if (tagName === tagResponse) {
|
||||
// if (currentStat.path) { // The list of resources includes the root dir too, which we don't want
|
||||
// if (!currentStat.updated_time) throw new Error('Resource does not have a getlastmodified prop');
|
||||
// stats.push(currentStat);
|
||||
// }
|
||||
// currentStat = null;
|
||||
// }
|
||||
|
||||
// if (tagName === 'd:href') {
|
||||
// const href = currentText;
|
||||
|
||||
// if (replaceUrls) {
|
||||
// currentStat.path = rtrimSlashes(ltrimSlashes(href));
|
||||
// } else {
|
||||
// if (href.indexOf(relativeBaseUrl) < 0) throw new Error('Path not inside base URL: ' + relativeBaseUrl); // Normally not possible
|
||||
// currentStat.path = rtrimSlashes(ltrimSlashes(href.substr(relativeBaseUrl.length)));
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (tagName === tagGetLastModified) {
|
||||
// const lastModifiedDate = new Date(currentText);
|
||||
// if (isNaN(lastModifiedDate.getTime())) throw new Error('Invalid date: ' + currentText);
|
||||
// currentStat.updated_time = lastModifiedDate.getTime();
|
||||
// currentStat.created_time = currentStat.updated_time;
|
||||
// }
|
||||
|
||||
// if (tagName === 'd:collection') {
|
||||
// currentStat.isDir = true;
|
||||
// }
|
||||
|
||||
// currentText = '';
|
||||
// }
|
||||
|
||||
// saxParser.onend = function () {
|
||||
// resolve(stats);
|
||||
// };
|
||||
|
||||
// if (optimizeXml) {
|
||||
// xmlString = xmlString.replace(/<d:status>HTTP\/1\.1 200 OK<\/d:status>/ig, '');
|
||||
// xmlString = xmlString.replace(/<d:resourcetype\/>/ig, '');
|
||||
// xmlString = xmlString.replace(/d:getlastmodified/ig, tagGetLastModified);
|
||||
// xmlString = xmlString.replace(/d:response/ig, tagResponse);
|
||||
// xmlString = xmlString.replace(/d:propstat/ig, tagPropStat);
|
||||
// if (replaceUrls) xmlString = xmlString.replace(new RegExp(relativeBaseUrl, 'gi'), '');
|
||||
// }
|
||||
|
||||
// let idx = 0;
|
||||
// let size = 1024 * 100;
|
||||
// while (true) {
|
||||
// sub = xmlString.substr(idx, size);
|
||||
// if (!sub.length) break;
|
||||
// saxParser.write(sub);
|
||||
// idx += size;
|
||||
// //await time.msleep(500);
|
||||
// }
|
||||
|
||||
// saxParser.close();
|
||||
|
||||
// //saxParser.write(xmlString).close();
|
||||
// });
|
||||
// }
|
||||
|
||||
// For performance reasons, the response of the PROPFIND call is manually parsed with a regex below
|
||||
// instead of being processed by xml2json like the other WebDAV responses. This is over 2 times faster
|
||||
// and it means the mobile app does not freeze during sync.
|
||||
|
||||
// async function parsePropFindXml2(xmlString) {
|
||||
// const regex = /<d:response>[\S\s]*?<d:href>([\S\s]*?)<\/d:href>[\S\s]*?<d:getlastmodified>(.*?)<\/d:getlastmodified>/g;
|
||||
|
||||
// let output = [];
|
||||
// let match = null;
|
||||
|
||||
// while (match = regex.exec(xmlString)) {
|
||||
// const href = html_entity_decode(match[1]);
|
||||
// if (href.indexOf(relativeBaseUrl) < 0) throw new Error('Path not inside base URL: ' + relativeBaseUrl); // Normally not possible
|
||||
// const path = rtrimSlashes(ltrimSlashes(href.substr(relativeBaseUrl.length)));
|
||||
|
||||
// if (!path) continue; // The list of resources includes the root dir too, which we don't want
|
||||
|
||||
// const lastModifiedDate = new Date(match[2]);
|
||||
// if (isNaN(lastModifiedDate.getTime())) throw new Error('Invalid date: ' + match[2]);
|
||||
|
||||
// output.push({
|
||||
// path: path,
|
||||
// updated_time: lastModifiedDate.getTime(),
|
||||
// created_time: lastModifiedDate.getTime(),
|
||||
// isDir: !BaseItem.isSystemPath(path),
|
||||
// });
|
||||
// }
|
||||
|
||||
// return output;
|
||||
// }
|
||||
|
||||
// const resultXml = await this.api().execPropFind(path, 1, [
|
||||
// 'd:getlastmodified',
|
||||
// //'d:resourcetype', // Include this to use parsePropFindXml()
|
||||
// ], { responseFormat: 'text' });
|
||||
|
||||
// const stats = await parsePropFindXml2(resultXml);
|
||||
|
||||
// return {
|
||||
// items: stats,
|
||||
// hasMore: false,
|
||||
// context: null,
|
||||
// };
|
||||
// See mkdir() call for explanation
|
||||
if (!path.endsWith('/')) path = `${path}/`;
|
||||
|
||||
const result = await this.api().execPropFind(path, 1, ['d:getlastmodified', 'd:resourcetype']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user