Skip to content

Commit

Permalink
Merge pull request #32013 from owncloud/js-upload-mtime
Browse files Browse the repository at this point in the history
[stable10] Read mtime from both properties
  • Loading branch information
DeepDiver1975 authored Jul 31, 2018
2 parents 071e12d + ef2792a commit 05870fb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
20 changes: 16 additions & 4 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions apps/files/tests/js/fileUploadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
});

0 comments on commit 05870fb

Please sign in to comment.