@rails/activestorage
Advanced tools
Comparing version 7.0.0-alpha2 to 7.0.0-rc1
@@ -511,3 +511,3 @@ var sparkMd5 = { | ||
class BlobRecord { | ||
constructor(file, checksum, url) { | ||
constructor(file, checksum, url, directUploadToken, attachmentName) { | ||
this.file = file; | ||
@@ -520,2 +520,4 @@ this.attributes = { | ||
}; | ||
this.directUploadToken = directUploadToken; | ||
this.attachmentName = attachmentName; | ||
this.xhr = new XMLHttpRequest; | ||
@@ -548,3 +550,5 @@ this.xhr.open("POST", url, true); | ||
this.xhr.send(JSON.stringify({ | ||
blob: this.attributes | ||
blob: this.attributes, | ||
direct_upload_token: this.directUploadToken, | ||
attachment_name: this.attachmentName | ||
})); | ||
@@ -610,6 +614,8 @@ } | ||
class DirectUpload { | ||
constructor(file, url, delegate) { | ||
constructor(file, url, serviceName, attachmentName, delegate) { | ||
this.id = ++id; | ||
this.file = file; | ||
this.url = url; | ||
this.serviceName = serviceName; | ||
this.attachmentName = attachmentName; | ||
this.delegate = delegate; | ||
@@ -623,3 +629,3 @@ } | ||
} | ||
const blob = new BlobRecord(this.file, checksum, this.url); | ||
const blob = new BlobRecord(this.file, checksum, this.url, this.serviceName, this.attachmentName); | ||
notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr); | ||
@@ -655,3 +661,3 @@ blob.create((error => { | ||
this.file = file; | ||
this.directUpload = new DirectUpload(this.file, this.url, this); | ||
this.directUpload = new DirectUpload(this.file, this.url, this.directUploadToken, this.attachmentName, this); | ||
this.dispatch("initialize"); | ||
@@ -687,2 +693,8 @@ } | ||
} | ||
get directUploadToken() { | ||
return this.input.getAttribute("data-direct-upload-token"); | ||
} | ||
get attachmentName() { | ||
return this.input.getAttribute("data-direct-upload-attachment-name"); | ||
} | ||
dispatch(name, detail = {}) { | ||
@@ -689,0 +701,0 @@ detail.file = this.file; |
@@ -506,3 +506,3 @@ (function(global, factory) { | ||
class BlobRecord { | ||
constructor(file, checksum, url) { | ||
constructor(file, checksum, url, directUploadToken, attachmentName) { | ||
this.file = file; | ||
@@ -515,2 +515,4 @@ this.attributes = { | ||
}; | ||
this.directUploadToken = directUploadToken; | ||
this.attachmentName = attachmentName; | ||
this.xhr = new XMLHttpRequest; | ||
@@ -543,3 +545,5 @@ this.xhr.open("POST", url, true); | ||
this.xhr.send(JSON.stringify({ | ||
blob: this.attributes | ||
blob: this.attributes, | ||
direct_upload_token: this.directUploadToken, | ||
attachment_name: this.attachmentName | ||
})); | ||
@@ -602,6 +606,8 @@ } | ||
class DirectUpload { | ||
constructor(file, url, delegate) { | ||
constructor(file, url, serviceName, attachmentName, delegate) { | ||
this.id = ++id; | ||
this.file = file; | ||
this.url = url; | ||
this.serviceName = serviceName; | ||
this.attachmentName = attachmentName; | ||
this.delegate = delegate; | ||
@@ -615,3 +621,3 @@ } | ||
} | ||
const blob = new BlobRecord(this.file, checksum, this.url); | ||
const blob = new BlobRecord(this.file, checksum, this.url, this.serviceName, this.attachmentName); | ||
notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr); | ||
@@ -645,3 +651,3 @@ blob.create((error => { | ||
this.file = file; | ||
this.directUpload = new DirectUpload(this.file, this.url, this); | ||
this.directUpload = new DirectUpload(this.file, this.url, this.directUploadToken, this.attachmentName, this); | ||
this.dispatch("initialize"); | ||
@@ -677,2 +683,8 @@ } | ||
} | ||
get directUploadToken() { | ||
return this.input.getAttribute("data-direct-upload-token"); | ||
} | ||
get attachmentName() { | ||
return this.input.getAttribute("data-direct-upload-attachment-name"); | ||
} | ||
dispatch(name, detail = {}) { | ||
@@ -679,0 +691,0 @@ detail.file = this.file; |
{ | ||
"name": "@rails/activestorage", | ||
"version": "7.0.0-alpha2", | ||
"version": "7.0.0-rc1", | ||
"description": "Attach cloud and local files in Rails applications", | ||
"module": "app/assets/javascripts/activestorage.esm.js", | ||
"main": "app/assets/javascripts/activestorage.js", | ||
"type": "module", | ||
"files": [ | ||
@@ -8,0 +8,0 @@ "app/assets/javascripts/*.js", |
import { getMetaValue } from "./helpers" | ||
export class BlobRecord { | ||
constructor(file, checksum, url) { | ||
constructor(file, checksum, url, directUploadToken, attachmentName) { | ||
this.file = file | ||
@@ -11,5 +11,8 @@ | ||
byte_size: file.size, | ||
checksum: checksum | ||
checksum: checksum, | ||
} | ||
this.directUploadToken = directUploadToken | ||
this.attachmentName = attachmentName | ||
this.xhr = new XMLHttpRequest | ||
@@ -47,3 +50,7 @@ this.xhr.open("POST", url, true) | ||
this.callback = callback | ||
this.xhr.send(JSON.stringify({ blob: this.attributes })) | ||
this.xhr.send(JSON.stringify({ | ||
blob: this.attributes, | ||
direct_upload_token: this.directUploadToken, | ||
attachment_name: this.attachmentName | ||
})) | ||
} | ||
@@ -50,0 +57,0 @@ |
@@ -8,3 +8,3 @@ import { DirectUpload } from "./direct_upload" | ||
this.file = file | ||
this.directUpload = new DirectUpload(this.file, this.url, this) | ||
this.directUpload = new DirectUpload(this.file, this.url, this.directUploadToken, this.attachmentName, this) | ||
this.dispatch("initialize") | ||
@@ -45,2 +45,10 @@ } | ||
get directUploadToken() { | ||
return this.input.getAttribute("data-direct-upload-token") | ||
} | ||
get attachmentName() { | ||
return this.input.getAttribute("data-direct-upload-attachment-name") | ||
} | ||
dispatch(name, detail = {}) { | ||
@@ -47,0 +55,0 @@ detail.file = this.file |
@@ -8,6 +8,8 @@ import { FileChecksum } from "./file_checksum" | ||
export class DirectUpload { | ||
constructor(file, url, delegate) { | ||
constructor(file, url, serviceName, attachmentName, delegate) { | ||
this.id = ++id | ||
this.file = file | ||
this.url = url | ||
this.serviceName = serviceName | ||
this.attachmentName = attachmentName | ||
this.delegate = delegate | ||
@@ -23,3 +25,3 @@ } | ||
const blob = new BlobRecord(this.file, checksum, this.url) | ||
const blob = new BlobRecord(this.file, checksum, this.url, this.serviceName, this.attachmentName) | ||
notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr) | ||
@@ -26,0 +28,0 @@ |
2077
79774
13
No