From ef2792a14829623c19d79fff1f582bf47e9d35d5 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 9 Jul 2018 09:22:11 +0200 Subject: [PATCH] Read mtime from both properties --- apps/files/js/file-upload.js | 20 ++++++++++++--- apps/files/tests/js/fileUploadSpec.js | 37 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 377f952fc672..1d70501f943e 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -114,6 +114,17 @@ OC.FileUpload.prototype = { return this.getFile().name; }, + getLastModified: function() { + var file = this.getFile(); + if (file.lastModifiedDate) { + return file.lastModifiedDate.getTime() / 1000; + } + if (file.lastModified) { + return file.lastModified / 1000; + } + return null; + }, + setTargetFolder: function(targetFolder) { this._targetFolder = targetFolder; }, @@ -238,9 +249,10 @@ OC.FileUpload.prototype = { this.data.headers['OC-Autorename'] = '1'; } - if (file.lastModified) { + var lastModified = this.getLastModified(); + if (lastModified) { // preserve timestamp - this.data.headers['X-OC-Mtime'] = file.lastModified / 1000; + this.data.headers['X-OC-Mtime'] = '' + lastModified; } var userName = this.uploader.davClient.getUserName(); @@ -287,11 +299,11 @@ OC.FileUpload.prototype = { } var uid = OC.getCurrentUser().uid; - var mtime = this.getFile().lastModified; + var mtime = this.getLastModified(); var size = this.getFile().size; var headers = {}; if (mtime) { - headers['X-OC-Mtime'] = mtime / 1000; + headers['X-OC-Mtime'] = mtime; } if (size) { headers['OC-Total-Length'] = size; diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js index 2f6d220dbd9e..6d65b8749235 100644 --- a/apps/files/tests/js/fileUploadSpec.js +++ b/apps/files/tests/js/fileUploadSpec.js @@ -273,4 +273,41 @@ describe('OC.Upload tests', function() { expect(upload.data.headers['OC-Autorename']).toEqual('1'); }); }); + describe('submitting uploads', function() { + describe('headers', function() { + function testHeaders(fileData) { + var uploadData = addFiles(uploader, [ + fileData + ]); + + return uploadData[0].headers; + } + it('sets request token', function() { + var oldToken = OC.requestToken; + OC.requestToken = 'abcd'; + var headers = testHeaders({ + name: 'headerstest.txt' + }); + + expect(headers['requesttoken']).toEqual('abcd'); + OC.requestToken = oldToken; + }); + it('sets the mtime header when lastModifiedDate is set', function() { + var headers = testHeaders({ + name: 'mtimetest.txt', + lastModifiedDate: new Date(Date.UTC(2018, 7, 26, 14, 55, 22, 500)) + }); + + expect(headers['X-OC-Mtime']).toEqual('1535295322.5'); + }); + it('sets the mtime header when lastModified is set', function() { + var headers = testHeaders({ + name: 'mtimetest.txt', + lastModified: 1535295322500 + }); + + expect(headers['X-OC-Mtime']).toEqual('1535295322.5'); + }); + }); + }); });