1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Provide Content-Length header for WebDAV for better compatibility with more servers

This commit is contained in:
Laurent Cozic 2018-02-15 18:33:08 +00:00
parent 9347683fe3
commit 3a4bbd571e
8 changed files with 26 additions and 13 deletions

View File

@ -19,7 +19,7 @@ process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; // The first test is slow because the database needs to be built
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000 + 30000; // The first test is slow because the database needs to be built
async function allItems() {
let folders = await Folder.all();

View File

@ -51,12 +51,12 @@ SyncTargetRegistry.addClass(SyncTargetFilesystem);
SyncTargetRegistry.addClass(SyncTargetOneDrive);
SyncTargetRegistry.addClass(SyncTargetNextcloud);
//const syncTargetId_ = SyncTargetRegistry.nameToId('nextcloud');
const syncTargetId_ = SyncTargetRegistry.nameToId('memory');
const syncTargetId_ = SyncTargetRegistry.nameToId('nextcloud');
//const syncTargetId_ = SyncTargetRegistry.nameToId('memory');
//const syncTargetId_ = SyncTargetRegistry.nameToId('filesystem');
const syncDir = __dirname + '/../tests/sync';
const sleepTime = syncTargetId_ == SyncTargetRegistry.nameToId('filesystem') ? 1001 : 1;//400;
const sleepTime = syncTargetId_ == SyncTargetRegistry.nameToId('filesystem') ? 1001 : 100;//400;
console.info('Testing with sync target: ' + SyncTargetRegistry.idToName(syncTargetId_));
@ -264,6 +264,7 @@ function fileApi() {
fileApi_.setLogger(logger);
fileApi_.setSyncTargetId(syncTargetId_);
fileApi_.requestRepeatCount_ = 0;
return fileApi_;
}

View File

@ -227,11 +227,6 @@ class WebDavApi {
if (authToken) headers['Authorization'] = 'Basic ' + authToken;
// /!\ Doesn't work with UTF-8 strings as it results in truncated content. Content-Length
// /!\ should not be needed anyway, but was required by one service. If re-implementing this
// /!\ test with various content, including binary blobs.
// if (typeof body === 'string') headers['Content-Length'] = body.length;
const fetchOptions = {};
fetchOptions.headers = headers;
fetchOptions.method = method;
@ -246,8 +241,13 @@ class WebDavApi {
// console.info(this.requestToCurl_(url, fetchOptions));
if (options.source == 'file' && (method == 'POST' || method == 'PUT')) {
if (fetchOptions.path) {
const fileStat = await shim.fsDriver().stat(fetchOptions.path);
if (fileStat) fetchOptions.headers['Content-Length'] = fileStat.size + '';
}
response = await shim.uploadBlob(url, fetchOptions);
} else if (options.target == 'string') {
if (typeof body === 'string') fetchOptions.headers['Content-Length'] = shim.stringByteLength(body) + '';
response = await shim.fetch(url, fetchOptions);
} else { // file
response = await shim.fetchBlob(url, fetchOptions);

View File

@ -39,12 +39,14 @@ class FileApi {
this.syncTargetId_ = null;
this.tempDirName_ = null;
this.driver_.fileApi_ = this;
this.requestRepeatCount_ = null; // For testing purpose only - normally this value should come from the driver
}
// Ideally all requests repeating should be done at the FileApi level to remove duplicate code in the drivers, but
// historically some drivers (eg. OneDrive) are already handling request repeating, so this is optional, per driver,
// and it defaults to no repeating.
requestRepeatCount() {
if (this.requestRepeatCount_ !== null) return this.requestRepeatCount_;
if (this.driver_.requestRepeatCount) return this.driver_.requestRepeatCount();
return 0;
}

View File

@ -74,10 +74,10 @@ class DecryptionWorker {
const item = items[i];
// Temp hack
if (['edf44b7a0e4f8cbf248e206cd8dfa800', '2ccb3c9af0b1adac2ec6b66a5961fbb1'].indexOf(item.id) >= 0) {
excludedIds.push(item.id);
continue;
}
// if (['edf44b7a0e4f8cbf248e206cd8dfa800', '2ccb3c9af0b1adac2ec6b66a5961fbb1'].indexOf(item.id) >= 0) {
// excludedIds.push(item.id);
// continue;
// }
const ItemClass = BaseItem.itemClass(item);
this.logger().info('DecryptionWorker: decrypting: ' + item.id + ' (' + ItemClass.tableName() + ')');

View File

@ -172,6 +172,10 @@ function shimInit() {
return shim.fetch(url, options);
}
shim.stringByteLength = function(string) {
return Buffer.byteLength(string, 'utf-8');
}
}
module.exports = { shimInit };

View File

@ -5,6 +5,7 @@ const RNFetchBlob = require('react-native-fetch-blob').default;
const { generateSecureRandom } = require('react-native-securerandom');
const FsDriverRN = require('lib/fs-driver-rn.js').FsDriverRN;
const urlValidator = require('valid-url');
const { Buffer } = require('buffer');
function shimInit() {
shim.Geolocation = GeolocationReact;
@ -111,6 +112,10 @@ function shimInit() {
shim.readLocalFileBase64 = async function(path) {
return RNFetchBlob.fs.readFile(path, 'base64')
}
shim.stringByteLength = function(string) {
return Buffer.byteLength(string, 'utf-8');
}
}
module.exports = { shimInit };

View File

@ -118,6 +118,7 @@ shim.setInterval = function(fn, interval) {
shim.clearInterval = function(id) {
return clearInterval(id);
}
shim.stringByteLength = function(string) { throw new Error('Not implemented'); }
shim.detectAndSetLocale = null;
shim.attachFileToNote = async (note, filePath) => {}