From 4d78ec025a32e3a5a25a9446efee53c3946f5c6c Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 4 Jan 2021 12:31:59 +0100 Subject: [PATCH 01/22] adding some logging --- dist/mobx-spine.cjs.js | 1 + dist/mobx-spine.es.js | 1 + src/Model.js | 1 + 3 files changed, 3 insertions(+) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index ba8a91d..9f61f60 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1468,6 +1468,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; + console.log('value!', value); value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index ab52885..0ff4251 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1462,6 +1462,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; + console.log('value!', value); value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/src/Model.js b/src/Model.js index f2769e8..d5bfc1b 100644 --- a/src/Model.js +++ b/src/Model.js @@ -715,6 +715,7 @@ export default class Model { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; + console.log('value!', value); value = `${URL.createObjectURL(value)}?content_type=${value.type}`; } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { From b2ca0aa561bffb997c376cd04237237c1b0f16e8 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 4 Jan 2021 13:31:45 +0100 Subject: [PATCH 02/22] isBase64 --- dist/mobx-spine.cjs.js | 15 ++++++++++++++- dist/mobx-spine.es.js | 15 ++++++++++++++- src/Model.js | 13 ++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 9f61f60..03955a0 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1456,6 +1456,18 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { throw err; }))); } + }, { + key: 'isBase64', + value: function isBase64(str) { + if (str === '' || str.trim() === '') { + return false; + } + try { + return btoa(atob(str)) == str; + } catch (err) { + return false; + } + } }, { key: 'setInput', value: function setInput(name, value) { @@ -1468,7 +1480,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', value); + console.log('value!', isBase64(value)); + value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 0ff4251..4093930 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1450,6 +1450,18 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { throw err; }))); } + }, { + key: 'isBase64', + value: function isBase64(str) { + if (str === '' || str.trim() === '') { + return false; + } + try { + return btoa(atob(str)) == str; + } catch (err) { + return false; + } + } }, { key: 'setInput', value: function setInput(name, value) { @@ -1462,7 +1474,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', value); + console.log('value!', isBase64(value)); + value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/src/Model.js b/src/Model.js index d5bfc1b..b54c865 100644 --- a/src/Model.js +++ b/src/Model.js @@ -700,6 +700,16 @@ export default class Model { ); } + isBase64(str) { + if (str ==='' || str.trim() ===''){ return false; } + try { + return btoa(atob(str)) == str; + } catch (err) { + return false; + } + } + + @action setInput(name, value) { invariant( @@ -715,7 +725,8 @@ export default class Model { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', value); + console.log('value!', isBase64(value)); + value = `${URL.createObjectURL(value)}?content_type=${value.type}`; } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { From 78d7ec2f0d6d8eb6c92107da80af87e95e6d7995 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 4 Jan 2021 13:41:31 +0100 Subject: [PATCH 03/22] this. --- dist/mobx-spine.cjs.js | 2 +- dist/mobx-spine.es.js | 2 +- src/Model.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 03955a0..a8ed087 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1480,7 +1480,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', isBase64(value)); + console.log('value!', this.isBase64(value)); value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 4093930..b4381f4 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1474,7 +1474,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', isBase64(value)); + console.log('value!', this.isBase64(value)); value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { diff --git a/src/Model.js b/src/Model.js index b54c865..47160d0 100644 --- a/src/Model.js +++ b/src/Model.js @@ -725,7 +725,7 @@ export default class Model { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', isBase64(value)); + console.log('value!', this.isBase64(value)); value = `${URL.createObjectURL(value)}?content_type=${value.type}`; } else { From e1fd33a5e23cee9205e878a33dca959d2d6d250f Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 4 Jan 2021 13:59:06 +0100 Subject: [PATCH 04/22] better base64 check --- dist/mobx-spine.cjs.js | 3 ++- dist/mobx-spine.es.js | 3 ++- src/Model.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index a8ed087..34f6377 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1462,8 +1462,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (str === '' || str.trim() === '') { return false; } + str = str.replace(/^[^,]+,/, ''); try { - return btoa(atob(str)) == str; + return btoa(atob(str)) === atob(btoa(str)); } catch (err) { return false; } diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index b4381f4..792403d 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1456,8 +1456,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (str === '' || str.trim() === '') { return false; } + str = str.replace(/^[^,]+,/, ''); try { - return btoa(atob(str)) == str; + return btoa(atob(str)) === atob(btoa(str)); } catch (err) { return false; } diff --git a/src/Model.js b/src/Model.js index 47160d0..d5a076e 100644 --- a/src/Model.js +++ b/src/Model.js @@ -702,8 +702,9 @@ export default class Model { isBase64(str) { if (str ==='' || str.trim() ===''){ return false; } + str = str.replace(/^[^,]+,/, ''); try { - return btoa(atob(str)) == str; + return btoa(atob(str)) === atob(btoa(str)); } catch (err) { return false; } From 2739bf8c935652b18cd287b0828eb37682552c53 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 9 Jan 2021 09:40:50 +0100 Subject: [PATCH 05/22] testin --- dist/mobx-spine.cjs.js | 9 +++++++-- dist/mobx-spine.es.js | 9 +++++++-- src/Model.js | 11 ++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 34f6377..ba85ac3 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1473,6 +1473,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { key: 'setInput', value: function setInput(name, value) { invariant(this.__attributes.includes(name) || this.__activeCurrentRelations.includes(name), 'Field `' + name + '` does not exist on the model.'); + this.isBase64File = false; + if (this.fileFields().includes(name)) { if (this.__fileExists[name] === undefined) { this.__fileExists[name] = this[name] !== null; @@ -1481,9 +1483,12 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', this.isBase64(value)); + // console.log('value!', this.isBase64(value)); + this.isBase64File = this.isBase64(value); - value = URL.createObjectURL(value) + '?content_type=' + value.type; + if (this.isBase64File) { + value = URL.createObjectURL(value) + '?content_type=' + value.type; + } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { this.__fileDeletions[name] = true; diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 792403d..ff11da7 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1467,6 +1467,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { key: 'setInput', value: function setInput(name, value) { invariant(this.__attributes.includes(name) || this.__activeCurrentRelations.includes(name), 'Field `' + name + '` does not exist on the model.'); + this.isBase64File = false; + if (this.fileFields().includes(name)) { if (this.__fileExists[name] === undefined) { this.__fileExists[name] = this[name] !== null; @@ -1475,9 +1477,12 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', this.isBase64(value)); + // console.log('value!', this.isBase64(value)); + this.isBase64File = this.isBase64(value); - value = URL.createObjectURL(value) + '?content_type=' + value.type; + if (this.isBase64File) { + value = URL.createObjectURL(value) + '?content_type=' + value.type; + } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { this.__fileDeletions[name] = true; diff --git a/src/Model.js b/src/Model.js index d5a076e..71d91a6 100644 --- a/src/Model.js +++ b/src/Model.js @@ -718,6 +718,8 @@ export default class Model { this.__activeCurrentRelations.includes(name), `Field \`${name}\` does not exist on the model.` ); + this.isBase64File = false; + if (this.fileFields().includes(name)) { if (this.__fileExists[name] === undefined) { this.__fileExists[name] = this[name] !== null; @@ -726,9 +728,12 @@ export default class Model { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - console.log('value!', this.isBase64(value)); - - value = `${URL.createObjectURL(value)}?content_type=${value.type}`; + // console.log('value!', this.isBase64(value)); + this.isBase64File = this.isBase64(value); + + if(this.isBase64File){ + value = `${URL.createObjectURL(value)}?content_type=${value.type}`; + } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { this.__fileDeletions[name] = true; From 50dc8d18cdbfad6ceb62154c9ec63259698c4407 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 9 Jan 2021 09:58:08 +0100 Subject: [PATCH 06/22] test 2 --- dist/mobx-spine.cjs.js | 2 +- dist/mobx-spine.es.js | 2 +- src/Model.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index ba85ac3..683c330 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1486,7 +1486,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); - if (this.isBase64File) { + if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; } } else { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index ff11da7..187ec06 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1480,7 +1480,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); - if (this.isBase64File) { + if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; } } else { diff --git a/src/Model.js b/src/Model.js index 71d91a6..0fe27a4 100644 --- a/src/Model.js +++ b/src/Model.js @@ -731,7 +731,7 @@ export default class Model { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); - if(this.isBase64File){ + if(!this.isBase64File){ value = `${URL.createObjectURL(value)}?content_type=${value.type}`; } } else { From 6054334cac55d94d4f7a040d7548188e1119fa7f Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 9 Jan 2021 12:20:58 +0100 Subject: [PATCH 07/22] let's try to fix it --- dist/mobx-spine.cjs.js | 2 ++ dist/mobx-spine.es.js | 2 ++ src/Model.js | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 683c330..1b0b9eb 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1486,6 +1486,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); + debugger; + if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; } diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 187ec06..9369e21 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1480,6 +1480,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); + debugger; + if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; } diff --git a/src/Model.js b/src/Model.js index 0fe27a4..d6ac0db 100644 --- a/src/Model.js +++ b/src/Model.js @@ -730,7 +730,9 @@ export default class Model { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); - + + debugger; + if(!this.isBase64File){ value = `${URL.createObjectURL(value)}?content_type=${value.type}`; } From 97a29f338db32d892bcd6c1c909aa87e2d99a245 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 9 Jan 2021 12:56:34 +0100 Subject: [PATCH 08/22] let's see if this works --- dist/mobx-spine.cjs.js | 14 ++++++++++++++ dist/mobx-spine.es.js | 14 ++++++++++++++ src/Model.js | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 1b0b9eb..a067152 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1469,6 +1469,17 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { return false; } } + }, { + key: 'dataURItoBlob', + value: function dataURItoBlob(dataURI) { + var mime = dataURI.split(',')[0].split(':')[1].split(';')[0]; + var binary = atob(dataURI.split(',')[1]); + var array = []; + for (var i = 0; i < binary.length; i++) { + array.push(binary.charCodeAt(i)); + } + return new Blob([new Uint8Array(array)], { type: mime }); + } }, { key: 'setInput', value: function setInput(name, value) { @@ -1490,6 +1501,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; + } else { + var blob = this.dataURItoBlob(value); + value = URL.createObjectURL(blob) + '?content_type=' + blob.type; } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 9369e21..fcc294f 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1463,6 +1463,17 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { return false; } } + }, { + key: 'dataURItoBlob', + value: function dataURItoBlob(dataURI) { + var mime = dataURI.split(',')[0].split(':')[1].split(';')[0]; + var binary = atob(dataURI.split(',')[1]); + var array = []; + for (var i = 0; i < binary.length; i++) { + array.push(binary.charCodeAt(i)); + } + return new Blob([new Uint8Array(array)], { type: mime }); + } }, { key: 'setInput', value: function setInput(name, value) { @@ -1484,6 +1495,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; + } else { + var blob = this.dataURItoBlob(value); + value = URL.createObjectURL(blob) + '?content_type=' + blob.type; } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/src/Model.js b/src/Model.js index d6ac0db..3389386 100644 --- a/src/Model.js +++ b/src/Model.js @@ -709,6 +709,17 @@ export default class Model { return false; } } + + dataURItoBlob(dataURI) { + var mime = dataURI.split(',')[0].split(':')[1].split(';')[0]; + var binary = atob(dataURI.split(',')[1]); + var array = []; + for (var i = 0; i < binary.length; i++) { + array.push(binary.charCodeAt(i)); + } + return new Blob([new Uint8Array(array)], {type: mime}); + } + @action @@ -735,6 +746,9 @@ export default class Model { if(!this.isBase64File){ value = `${URL.createObjectURL(value)}?content_type=${value.type}`; + }else { + var blob = this.dataURItoBlob(value); + value = `${URL.createObjectURL(blob)}?content_type=${blob.type}`; } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { From 63d420e43a3ad4568d1c2f63ef1cb20ac365ed4b Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 9 Jan 2021 13:26:04 +0100 Subject: [PATCH 09/22] fix link --- dist/mobx-spine.cjs.js | 2 +- dist/mobx-spine.es.js | 2 +- src/Model.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index a067152..5ef7bbb 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1503,7 +1503,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { var blob = this.dataURItoBlob(value); - value = URL.createObjectURL(blob) + '?content_type=' + blob.type; + value = '' + URL.createObjectURL(blob); } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index fcc294f..958618e 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1497,7 +1497,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { var blob = this.dataURItoBlob(value); - value = URL.createObjectURL(blob) + '?content_type=' + blob.type; + value = '' + URL.createObjectURL(blob); } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { diff --git a/src/Model.js b/src/Model.js index 3389386..9203e3a 100644 --- a/src/Model.js +++ b/src/Model.js @@ -748,7 +748,7 @@ export default class Model { value = `${URL.createObjectURL(value)}?content_type=${value.type}`; }else { var blob = this.dataURItoBlob(value); - value = `${URL.createObjectURL(blob)}?content_type=${blob.type}`; + value = `${URL.createObjectURL(blob)}`; } } else { if (!this.__fileChanges[name] || this.__fileChanges[name].existed) { From 1be842da134df7be4add3b6c2c7306de588950df Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 11 Jan 2021 10:32:57 +0100 Subject: [PATCH 10/22] add debugger --- dist/mobx-spine.cjs.js | 4 ++-- dist/mobx-spine.es.js | 4 ++-- src/Model.js | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 5ef7bbb..d835fe4 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1395,6 +1395,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (this.__fileChanges[name]) { var file = this.__fileChanges[name]; + debugger; + var data = new FormData(); data.append(name, file, file.name); @@ -1497,8 +1499,6 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); - debugger; - if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 958618e..23c83e6 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1389,6 +1389,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (this.__fileChanges[name]) { var file = this.__fileChanges[name]; + debugger; + var data = new FormData(); data.append(name, file, file.name); @@ -1491,8 +1493,6 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); - debugger; - if (!this.isBase64File) { value = URL.createObjectURL(value) + '?content_type=' + value.type; } else { diff --git a/src/Model.js b/src/Model.js index 9203e3a..21f8a5f 100644 --- a/src/Model.js +++ b/src/Model.js @@ -619,6 +619,8 @@ export default class Model { if (this.__fileChanges[name]) { const file = this.__fileChanges[name]; + debugger; + const data = new FormData(); data.append(name, file, file.name); @@ -742,11 +744,10 @@ export default class Model { // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); - debugger; - if(!this.isBase64File){ value = `${URL.createObjectURL(value)}?content_type=${value.type}`; - }else { + } + else { var blob = this.dataURItoBlob(value); value = `${URL.createObjectURL(blob)}`; } From b538a95ca8a2c1839530d5f0dfe43727b6552284 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 11 Jan 2021 12:04:57 +0100 Subject: [PATCH 11/22] Hope this works --- dist/mobx-spine.cjs.js | 19 +++++++++++++++++-- dist/mobx-spine.es.js | 19 +++++++++++++++++-- src/Model.js | 18 ++++++++++++++++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index d835fe4..418f2f9 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1385,6 +1385,13 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { } return value; } + }, { + key: 'uuidv4', + value: function uuidv4() { + return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) { + return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16); + }); + } }, { key: 'saveFile', value: function saveFile(name) { @@ -1395,10 +1402,18 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (this.__fileChanges[name]) { var file = this.__fileChanges[name]; - debugger; + // debugger; var data = new FormData(); - data.append(name, file, file.name); + + if (this.isBase64(file)) { + var newfile = this.dataURItoBlob(file); + // file = `${URL.createObjectURL(blob)}`; + var fname = this.uuidv4(); + data.append(name, newfile, fname); + } else { + data.append(name, file, file.name); + } return this.api.post('' + this.url + snakeName + '/', data, { headers: { 'Content-Type': 'multipart/form-data' } }).then(mobx.action(function (res) { _this10.__fileExists[name] = true; diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 23c83e6..796de30 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1379,6 +1379,13 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { } return value; } + }, { + key: 'uuidv4', + value: function uuidv4() { + return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) { + return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16); + }); + } }, { key: 'saveFile', value: function saveFile(name) { @@ -1389,10 +1396,18 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (this.__fileChanges[name]) { var file = this.__fileChanges[name]; - debugger; + // debugger; var data = new FormData(); - data.append(name, file, file.name); + + if (this.isBase64(file)) { + var newfile = this.dataURItoBlob(file); + // file = `${URL.createObjectURL(blob)}`; + var fname = this.uuidv4(); + data.append(name, newfile, fname); + } else { + data.append(name, file, file.name); + } return this.api.post('' + this.url + snakeName + '/', data, { headers: { 'Content-Type': 'multipart/form-data' } }).then(action(function (res) { _this10.__fileExists[name] = true; diff --git a/src/Model.js b/src/Model.js index 21f8a5f..f3a4346 100644 --- a/src/Model.js +++ b/src/Model.js @@ -612,6 +612,12 @@ export default class Model { } return value; } + + uuidv4() { + return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => + (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) + ); + } saveFile(name) { const snakeName = camelToSnake(name); @@ -619,10 +625,18 @@ export default class Model { if (this.__fileChanges[name]) { const file = this.__fileChanges[name]; - debugger; + // debugger; const data = new FormData(); - data.append(name, file, file.name); + + if(this.isBase64(file)){ + const newfile = this.dataURItoBlob(file); + // file = `${URL.createObjectURL(blob)}`; + const fname = this.uuidv4(); + data.append(name, newfile, fname ); + } else{ + data.append(name, file, file.name); + } return ( this.api.post( From 10a576c5a2efa2070a5fa5426bca8971682b2c96 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 11 Jan 2021 12:22:06 +0100 Subject: [PATCH 12/22] add extension to file --- dist/mobx-spine.cjs.js | 2 +- dist/mobx-spine.es.js | 2 +- src/Model.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 418f2f9..ab2a073 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1409,7 +1409,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (this.isBase64(file)) { var newfile = this.dataURItoBlob(file); // file = `${URL.createObjectURL(blob)}`; - var fname = this.uuidv4(); + var fname = this.uuidv4() + '.png'; data.append(name, newfile, fname); } else { data.append(name, file, file.name); diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 796de30..ea7aad3 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1403,7 +1403,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { if (this.isBase64(file)) { var newfile = this.dataURItoBlob(file); // file = `${URL.createObjectURL(blob)}`; - var fname = this.uuidv4(); + var fname = this.uuidv4() + '.png'; data.append(name, newfile, fname); } else { data.append(name, file, file.name); diff --git a/src/Model.js b/src/Model.js index f3a4346..7bbda9f 100644 --- a/src/Model.js +++ b/src/Model.js @@ -632,7 +632,7 @@ export default class Model { if(this.isBase64(file)){ const newfile = this.dataURItoBlob(file); // file = `${URL.createObjectURL(blob)}`; - const fname = this.uuidv4(); + const fname = `${this.uuidv4()}.png`; data.append(name, newfile, fname ); } else{ data.append(name, file, file.name); From e665042665603fc06ce686e6fb5c5b0b4b9babed Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 16 Jan 2021 15:27:09 +0100 Subject: [PATCH 13/22] trying to add file api endpoint --- dist/mobx-spine.cjs.js | 14 +++++++++++--- dist/mobx-spine.es.js | 14 +++++++++++--- src/Model.js | 8 ++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index ab2a073..88f9874 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -865,6 +865,14 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { } return this[this.constructor.primaryKey]; } + }, { + key: 'encodedFile', + value: function encodedFile(file) { + if (this.fileFields.includes(file)) { + return '' + lodash.result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; + } + return ''; + } }, { key: 'casts', value: function casts() { @@ -1667,9 +1675,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { var bname = this.constructor.backendResourceName; if (valErrors[bname]) { - var id = this.getInternalId(); + var _id = this.getInternalId(); // When there is no id or negative id, the backend may use the string 'null'. Bit weird, but eh. - var errorsForModel = valErrors[bname][id] || valErrors[bname]['null']; + var errorsForModel = valErrors[bname][_id] || valErrors[bname]['null']; if (errorsForModel) { var camelCasedErrors = lodash.mapKeys(errorsForModel, function (value, key) { return snakeToCamel(key); @@ -1848,7 +1856,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { initializer: function initializer() { return {}; } -}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); +}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'encodedFile', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'encodedFile'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); // Function ripped from Django docs. // See: https://docs.djangoproject.com/en/dev/ref/csrf/#ajax diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index ea7aad3..b749edf 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -859,6 +859,14 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { } return this[this.constructor.primaryKey]; } + }, { + key: 'encodedFile', + value: function encodedFile(file) { + if (this.fileFields.includes(file)) { + return '' + result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; + } + return ''; + } }, { key: 'casts', value: function casts() { @@ -1661,9 +1669,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { var bname = this.constructor.backendResourceName; if (valErrors[bname]) { - var id = this.getInternalId(); + var _id = this.getInternalId(); // When there is no id or negative id, the backend may use the string 'null'. Bit weird, but eh. - var errorsForModel = valErrors[bname][id] || valErrors[bname]['null']; + var errorsForModel = valErrors[bname][_id] || valErrors[bname]['null']; if (errorsForModel) { var camelCasedErrors = mapKeys(errorsForModel, function (value, key) { return snakeToCamel(key); @@ -1842,7 +1850,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { initializer: function initializer() { return {}; } -}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); +}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'encodedFile', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'encodedFile'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); // Function ripped from Django docs. // See: https://docs.djangoproject.com/en/dev/ref/csrf/#ajax diff --git a/src/Model.js b/src/Model.js index 7bbda9f..0568700 100644 --- a/src/Model.js +++ b/src/Model.js @@ -122,6 +122,14 @@ export default class Model { return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}`; } + @computed + encodedFile(file){ + if(this.fileFields.includes(file)){ + return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}/${file}?encode=true`; + } + return ''; + } + @computed get isNew() { return !this[this.constructor.primaryKey]; From 5c3db89f738beb15e131a54eed0bac8a6e091a49 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 16 Jan 2021 15:32:17 +0100 Subject: [PATCH 14/22] changed url --- dist/mobx-spine.cjs.js | 6 +++--- dist/mobx-spine.es.js | 6 +++--- src/Model.js | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 88f9874..0564f1e 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -866,8 +866,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { return this[this.constructor.primaryKey]; } }, { - key: 'encodedFile', - value: function encodedFile(file) { + key: 'getEncodedFile', + value: function getEncodedFile(file) { if (this.fileFields.includes(file)) { return '' + lodash.result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; } @@ -1856,7 +1856,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { initializer: function initializer() { return {}; } -}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'encodedFile', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'encodedFile'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); +}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [mobx.computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [mobx.action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); // Function ripped from Django docs. // See: https://docs.djangoproject.com/en/dev/ref/csrf/#ajax diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index b749edf..cd1ed0f 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -860,8 +860,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { return this[this.constructor.primaryKey]; } }, { - key: 'encodedFile', - value: function encodedFile(file) { + key: 'getEncodedFile', + value: function getEncodedFile(file) { if (this.fileFields.includes(file)) { return '' + result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; } @@ -1850,7 +1850,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { initializer: function initializer() { return {}; } -}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'encodedFile', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'encodedFile'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); +}), _applyDecoratedDescriptor$1(_class$1.prototype, 'url', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'url'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isNew', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isNew'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'isLoading', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'isLoading'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, '__parseRelations', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, '__parseRelations'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'hasUserChanges', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'hasUserChanges'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fieldFilter', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fieldFilter'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fromBackend', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fromBackend'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parse', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parse'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'save', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'save'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'setInput', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'setInput'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'saveAll', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'saveAll'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'parseValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'parseValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clearValidationErrors', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clearValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'backendValidationErrors', [computed], Object.getOwnPropertyDescriptor(_class$1.prototype, 'backendValidationErrors'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'delete', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'delete'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'fetch', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'fetch'), _class$1.prototype), _applyDecoratedDescriptor$1(_class$1.prototype, 'clear', [action], Object.getOwnPropertyDescriptor(_class$1.prototype, 'clear'), _class$1.prototype)), _class$1); // Function ripped from Django docs. // See: https://docs.djangoproject.com/en/dev/ref/csrf/#ajax diff --git a/src/Model.js b/src/Model.js index 0568700..7ba2f90 100644 --- a/src/Model.js +++ b/src/Model.js @@ -122,8 +122,7 @@ export default class Model { return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}`; } - @computed - encodedFile(file){ + getEncodedFile(file){ if(this.fileFields.includes(file)){ return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}/${file}?encode=true`; } From e37e7917c71c642184eb4e88698f925309b627b9 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 16 Jan 2021 15:50:41 +0100 Subject: [PATCH 15/22] I'm dumb --- dist/mobx-spine.cjs.js | 2 +- dist/mobx-spine.es.js | 2 +- src/Model.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 0564f1e..30ec32a 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -868,7 +868,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'getEncodedFile', value: function getEncodedFile(file) { - if (this.fileFields.includes(file)) { + if (this.fileFields().includes(file)) { return '' + lodash.result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; } return ''; diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index cd1ed0f..e9176a8 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -862,7 +862,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'getEncodedFile', value: function getEncodedFile(file) { - if (this.fileFields.includes(file)) { + if (this.fileFields().includes(file)) { return '' + result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; } return ''; diff --git a/src/Model.js b/src/Model.js index 7ba2f90..09b62c8 100644 --- a/src/Model.js +++ b/src/Model.js @@ -123,7 +123,7 @@ export default class Model { } getEncodedFile(file){ - if(this.fileFields.includes(file)){ + if(this.fileFields().includes(file)){ return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}/${file}?encode=true`; } return ''; From b58e9f0c5547e1d57e7e8c6970df36a4be696d8e Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 1 Feb 2021 14:43:14 +0100 Subject: [PATCH 16/22] get encoded file --- dist/mobx-spine.cjs.js | 6 ++++-- dist/mobx-spine.es.js | 6 ++++-- src/Model.js | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 30ec32a..cf842bc 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -868,6 +868,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'getEncodedFile', value: function getEncodedFile(file) { + // get the resource name from path + var id = this[this.constructor.primaryKey]; if (this.fileFields().includes(file)) { return '' + lodash.result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; } @@ -1675,9 +1677,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { var bname = this.constructor.backendResourceName; if (valErrors[bname]) { - var _id = this.getInternalId(); + var id = this.getInternalId(); // When there is no id or negative id, the backend may use the string 'null'. Bit weird, but eh. - var errorsForModel = valErrors[bname][_id] || valErrors[bname]['null']; + var errorsForModel = valErrors[bname][id] || valErrors[bname]['null']; if (errorsForModel) { var camelCasedErrors = lodash.mapKeys(errorsForModel, function (value, key) { return snakeToCamel(key); diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index e9176a8..0cf9d76 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -862,6 +862,8 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'getEncodedFile', value: function getEncodedFile(file) { + // get the resource name from path + var id = this[this.constructor.primaryKey]; if (this.fileFields().includes(file)) { return '' + result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; } @@ -1669,9 +1671,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { var bname = this.constructor.backendResourceName; if (valErrors[bname]) { - var _id = this.getInternalId(); + var id = this.getInternalId(); // When there is no id or negative id, the backend may use the string 'null'. Bit weird, but eh. - var errorsForModel = valErrors[bname][_id] || valErrors[bname]['null']; + var errorsForModel = valErrors[bname][id] || valErrors[bname]['null']; if (errorsForModel) { var camelCasedErrors = mapKeys(errorsForModel, function (value, key) { return snakeToCamel(key); diff --git a/src/Model.js b/src/Model.js index 09b62c8..642bf04 100644 --- a/src/Model.js +++ b/src/Model.js @@ -123,6 +123,8 @@ export default class Model { } getEncodedFile(file){ + // get the resource name from path + const id = this[this.constructor.primaryKey]; if(this.fileFields().includes(file)){ return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}/${file}?encode=true`; } From 3dc34be02c5f701fae146b66b12cd59ff070638f Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Mon, 1 Feb 2021 16:15:02 +0100 Subject: [PATCH 17/22] fixed extra slash --- dist/mobx-spine.cjs.js | 4 ++-- dist/mobx-spine.es.js | 4 ++-- src/Model.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index cf842bc..9dc9f30 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -869,9 +869,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { key: 'getEncodedFile', value: function getEncodedFile(file) { // get the resource name from path - var id = this[this.constructor.primaryKey]; if (this.fileFields().includes(file)) { - return '' + lodash.result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; + var id = this[this.constructor.primaryKey]; + return '' + lodash.result(this, 'urlRoot') + (id ? id + '/' : '') + file + '/?encode=true'; } return ''; } diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 0cf9d76..62c8a91 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -863,9 +863,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { key: 'getEncodedFile', value: function getEncodedFile(file) { // get the resource name from path - var id = this[this.constructor.primaryKey]; if (this.fileFields().includes(file)) { - return '' + result(this, 'urlRoot') + (id ? id + '/' : '') + '/' + file + '?encode=true'; + var id = this[this.constructor.primaryKey]; + return '' + result(this, 'urlRoot') + (id ? id + '/' : '') + file + '/?encode=true'; } return ''; } diff --git a/src/Model.js b/src/Model.js index 642bf04..e48ae5a 100644 --- a/src/Model.js +++ b/src/Model.js @@ -124,9 +124,9 @@ export default class Model { getEncodedFile(file){ // get the resource name from path - const id = this[this.constructor.primaryKey]; if(this.fileFields().includes(file)){ - return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}/${file}?encode=true`; + const id = this[this.constructor.primaryKey]; + return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}${file}/?encode=true`; } return ''; } From 7265ff575bb43bce4f799e8b852577a327c33b34 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 6 Feb 2021 12:34:42 +0100 Subject: [PATCH 18/22] fix logic bug --- dist/mobx-spine.cjs.js | 5 +++-- dist/mobx-spine.es.js | 5 +++-- src/Model.js | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 9dc9f30..08fdecb 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -869,8 +869,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { key: 'getEncodedFile', value: function getEncodedFile(file) { // get the resource name from path - if (this.fileFields().includes(file)) { - var id = this[this.constructor.primaryKey]; + var id = this[this.constructor.primaryKey]; + + if (this.fileFields().includes(file) && id) { return '' + lodash.result(this, 'urlRoot') + (id ? id + '/' : '') + file + '/?encode=true'; } return ''; diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 62c8a91..0d2e73d 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -863,8 +863,9 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { key: 'getEncodedFile', value: function getEncodedFile(file) { // get the resource name from path - if (this.fileFields().includes(file)) { - var id = this[this.constructor.primaryKey]; + var id = this[this.constructor.primaryKey]; + + if (this.fileFields().includes(file) && id) { return '' + result(this, 'urlRoot') + (id ? id + '/' : '') + file + '/?encode=true'; } return ''; diff --git a/src/Model.js b/src/Model.js index e48ae5a..8ef0c3e 100644 --- a/src/Model.js +++ b/src/Model.js @@ -124,8 +124,9 @@ export default class Model { getEncodedFile(file){ // get the resource name from path - if(this.fileFields().includes(file)){ - const id = this[this.constructor.primaryKey]; + const id = this[this.constructor.primaryKey]; + + if(this.fileFields().includes(file) && id){ return `${result(this, 'urlRoot')}${id ? `${id}/` : ''}${file}/?encode=true`; } return ''; From cb7afce0d6b2a187bdcf50069e4c3f1ef070a7e2 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 20 Feb 2021 17:29:13 +0100 Subject: [PATCH 19/22] check for undefined str --- dist/mobx-spine.cjs.js | 2 +- dist/mobx-spine.es.js | 2 +- src/Model.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 08fdecb..648791d 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1487,7 +1487,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'isBase64', value: function isBase64(str) { - if (str === '' || str.trim() === '') { + if (!str || str === '' || str.trim() === '') { return false; } str = str.replace(/^[^,]+,/, ''); diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 0d2e73d..be27f1d 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1481,7 +1481,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'isBase64', value: function isBase64(str) { - if (str === '' || str.trim() === '') { + if (!str || str === '' || str.trim() === '') { return false; } str = str.replace(/^[^,]+,/, ''); diff --git a/src/Model.js b/src/Model.js index 8ef0c3e..73ab3b1 100644 --- a/src/Model.js +++ b/src/Model.js @@ -727,7 +727,7 @@ export default class Model { } isBase64(str) { - if (str ==='' || str.trim() ===''){ return false; } + if (!str || str ==='' || str.trim() ===''){ return false; } str = str.replace(/^[^,]+,/, ''); try { return btoa(atob(str)) === atob(btoa(str)); From e39a7c1c84c95cbd84241cc96954119e597e079e Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 20 Feb 2021 17:48:51 +0100 Subject: [PATCH 20/22] try to fix failing cypress test --- dist/mobx-spine.cjs.js | 5 ++++- dist/mobx-spine.es.js | 5 ++++- src/Model.js | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 648791d..8b6df03 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1487,7 +1487,10 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'isBase64', value: function isBase64(str) { - if (!str || str === '' || str.trim() === '') { + if (str === undefined || str === null) { + return false; + } + if (str === '' || str.trim() === '') { return false; } str = str.replace(/^[^,]+,/, ''); diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index be27f1d..6fed289 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1481,7 +1481,10 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'isBase64', value: function isBase64(str) { - if (!str || str === '' || str.trim() === '') { + if (str === undefined || str === null) { + return false; + } + if (str === '' || str.trim() === '') { return false; } str = str.replace(/^[^,]+,/, ''); diff --git a/src/Model.js b/src/Model.js index 73ab3b1..4eac89e 100644 --- a/src/Model.js +++ b/src/Model.js @@ -727,7 +727,8 @@ export default class Model { } isBase64(str) { - if (!str || str ==='' || str.trim() ===''){ return false; } + if( str === undefined || str === null){ return false;} + if (str ==='' || str.trim() ===''){ return false; } str = str.replace(/^[^,]+,/, ''); try { return btoa(atob(str)) === atob(btoa(str)); From 99d5c10b873c717de6eed63680535f3153b0a017 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Sat, 20 Feb 2021 18:09:38 +0100 Subject: [PATCH 21/22] check for obj --- dist/mobx-spine.cjs.js | 8 +++++++- dist/mobx-spine.es.js | 8 +++++++- src/Model.js | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 8b6df03..d2d73e8 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -79,6 +79,12 @@ function forNestedRelations(model, nestedRelations, fn) { }); } +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; +} : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; +}; + var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); @@ -1487,7 +1493,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'isBase64', value: function isBase64(str) { - if (str === undefined || str === null) { + if ((typeof str === 'undefined' ? 'undefined' : _typeof(str)) === 'object' || str === undefined || str === null) { return false; } if (str === '' || str.trim() === '') { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 6fed289..3267a83 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -73,6 +73,12 @@ function forNestedRelations(model, nestedRelations, fn) { }); } +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; +} : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; +}; + var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); @@ -1481,7 +1487,7 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { }, { key: 'isBase64', value: function isBase64(str) { - if (str === undefined || str === null) { + if ((typeof str === 'undefined' ? 'undefined' : _typeof(str)) === 'object' || str === undefined || str === null) { return false; } if (str === '' || str.trim() === '') { diff --git a/src/Model.js b/src/Model.js index 4eac89e..6d6aa08 100644 --- a/src/Model.js +++ b/src/Model.js @@ -727,7 +727,7 @@ export default class Model { } isBase64(str) { - if( str === undefined || str === null){ return false;} + if( typeof str === 'object' || str === undefined || str === null){ return false;} if (str ==='' || str.trim() ===''){ return false; } str = str.replace(/^[^,]+,/, ''); try { From 8d7e38fe0dec988df04e81146593fe681c31c852 Mon Sep 17 00:00:00 2001 From: Adrian Cucos Date: Tue, 24 Aug 2021 22:44:47 +0200 Subject: [PATCH 22/22] merged master changes --- dist/mobx-spine.cjs.js | 1 - dist/mobx-spine.es.js | 1 - src/Model.js | 1 - 3 files changed, 3 deletions(-) diff --git a/dist/mobx-spine.cjs.js b/dist/mobx-spine.cjs.js index 8e3205b..db8de58 100644 --- a/dist/mobx-spine.cjs.js +++ b/dist/mobx-spine.cjs.js @@ -1497,7 +1497,6 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); if (!this.isBase64File) { diff --git a/dist/mobx-spine.es.js b/dist/mobx-spine.es.js index 265e0fe..3e43418 100644 --- a/dist/mobx-spine.es.js +++ b/dist/mobx-spine.es.js @@ -1491,7 +1491,6 @@ var Model = (_class$1 = (_temp$1 = _class2$1 = function () { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); if (!this.isBase64File) { diff --git a/src/Model.js b/src/Model.js index ce3fdfc..85ddc86 100644 --- a/src/Model.js +++ b/src/Model.js @@ -728,7 +728,6 @@ export default class Model { this.__fileChanges[name] = value; delete this.__fileDeletions[name]; - // console.log('value!', this.isBase64(value)); this.isBase64File = this.isBase64(value); if(!this.isBase64File){