Skip to content

Commit

Permalink
Revert #38957 (#44287)
Browse files Browse the repository at this point in the history
* Revert "Pass service_name param to DirectUploadsController"

This reverts commit 193289d.

* Revert "Multi-service direct uploads in Action Text attachment uploads"

This reverts commit 0b69ad4.
  • Loading branch information
gmcgibbon committed Jan 29, 2022
1 parent 20846a2 commit aaa6468
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 437 deletions.
34 changes: 7 additions & 27 deletions actiontext/app/assets/javascripts/actiontext.js
Expand Up @@ -506,16 +506,14 @@ var activestorage = {exports: {}};
}
}
class BlobRecord {
constructor(file, checksum, url, directUploadToken, attachmentName) {
constructor(file, checksum, url) {
this.file = file;
this.attributes = {
filename: file.name,
content_type: file.type || "application/octet-stream",
byte_size: file.size,
checksum: checksum,
checksum: checksum
};
this.directUploadToken = directUploadToken;
this.attachmentName = attachmentName;
this.xhr = new XMLHttpRequest;
this.xhr.open("POST", url, true);
this.xhr.responseType = "json";
Expand Down Expand Up @@ -543,9 +541,7 @@ var activestorage = {exports: {}};
create(callback) {
this.callback = callback;
this.xhr.send(JSON.stringify({
blob: this.attributes,
direct_upload_token: this.directUploadToken,
attachment_name: this.attachmentName
blob: this.attributes
}));
}
requestDidLoad(event) {
Expand Down Expand Up @@ -603,12 +599,10 @@ var activestorage = {exports: {}};
}
let id = 0;
class DirectUpload {
constructor(file, url, directUploadToken, attachmentName, delegate) {
constructor(file, url, delegate) {
this.id = ++id;
this.file = file;
this.url = url;
this.directUploadToken = directUploadToken;
this.attachmentName = attachmentName;
this.delegate = delegate;
}
create(callback) {
Expand All @@ -617,7 +611,7 @@ var activestorage = {exports: {}};
callback(error);
return;
}
const blob = new BlobRecord(this.file, checksum, this.url, this.directUploadToken, this.attachmentName);
const blob = new BlobRecord(this.file, checksum, this.url);
notify(this.delegate, "directUploadWillCreateBlobWithXHR", blob.xhr);
blob.create((error => {
if (error) {
Expand Down Expand Up @@ -646,7 +640,7 @@ var activestorage = {exports: {}};
constructor(input, file) {
this.input = input;
this.file = file;
this.directUpload = new DirectUpload(this.file, this.url, this.directUploadToken, this.attachmentName, this);
this.directUpload = new DirectUpload(this.file, this.url, this);
this.dispatch("initialize");
}
start(callback) {
Expand Down Expand Up @@ -677,12 +671,6 @@ var activestorage = {exports: {}};
get url() {
return this.input.getAttribute("data-direct-upload-url");
}
get directUploadToken() {
return this.input.getAttribute("data-direct-upload-token");
}
get attachmentName() {
return this.input.getAttribute("data-direct-upload-attachment-name");
}
dispatch(name, detail = {}) {
detail.file = this.file;
detail.id = this.directUpload.id;
Expand Down Expand Up @@ -842,7 +830,7 @@ class AttachmentUpload {
constructor(attachment, element) {
this.attachment = attachment;
this.element = element;
this.directUpload = new activestorage.exports.DirectUpload(attachment.file, this.directUploadUrl, this.directUploadToken, this.directUploadAttachmentName, this);
this.directUpload = new activestorage.exports.DirectUpload(attachment.file, this.directUploadUrl, this);
}

start() {
Expand Down Expand Up @@ -877,14 +865,6 @@ class AttachmentUpload {
return this.element.dataset.directUploadUrl
}

get directUploadToken() {
return this.element.dataset.directUploadToken
}

get directUploadAttachmentName() {
return this.element.dataset.directUploadAttachmentName
}

get blobUrlTemplate() {
return this.element.dataset.blobUrlTemplate
}
Expand Down
8 changes: 0 additions & 8 deletions actiontext/app/helpers/action_text/tag_helper.rb
Expand Up @@ -32,14 +32,6 @@ def rich_text_area_tag(name, value = nil, options = {})
options[:data][:direct_upload_url] ||= main_app.rails_direct_uploads_url
options[:data][:blob_url_template] ||= main_app.rails_service_blob_url(":signed_id", ":filename")

class_with_attachment = "ActionText::RichText#embeds"
options[:data][:direct_upload_attachment_name] ||= class_with_attachment
options[:data][:direct_upload_token] = ActiveStorage::DirectUploadToken.generate_direct_upload_token(
class_with_attachment,
ActiveStorage::Blob.service.name,
session
)

editor_tag = content_tag("trix-editor", "", options)
input_tag = hidden_field_tag(name, value.try(:to_trix_html) || value, id: options[:input], form: form)

Expand Down
9 changes: 1 addition & 8 deletions actiontext/app/javascript/actiontext/attachment_upload.js
Expand Up @@ -4,7 +4,7 @@ export class AttachmentUpload {
constructor(attachment, element) {
this.attachment = attachment
this.element = element
this.directUpload = new DirectUpload(attachment.file, this.directUploadUrl, this.directUploadToken, this.attachmentName, this)
this.directUpload = new DirectUpload(attachment.file, this.directUploadUrl, this)
}

start() {
Expand Down Expand Up @@ -42,11 +42,4 @@ export class AttachmentUpload {
get blobUrlTemplate() {
return this.element.dataset.blobUrlTemplate
}

get directUploadToken() {
return this.element.getAttribute("data-direct-upload-token");
}
get attachmentName() {
return this.element.getAttribute("data-direct-upload-attachment-name");
}
}

0 comments on commit aaa6468

Please sign in to comment.