aboutsummaryrefslogtreecommitdiffstats
path: root/app/javascript
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2018-02-14 14:11:54 -0500
committerJavan Makhmali <javan@javan.us>2018-02-14 14:11:54 -0500
commitba71c73836c084c95ca89021f9c9a455d8c94134 (patch)
treeee94bb396b1907e73de68c7bb67b7650be482975 /app/javascript
parent9ded0f3c420350144a9d41ccee3dc4b7ad9d8813 (diff)
downloadrails-ba71c73836c084c95ca89021f9c9a455d8c94134.tar.gz
rails-ba71c73836c084c95ca89021f9c9a455d8c94134.tar.bz2
rails-ba71c73836c084c95ca89021f9c9a455d8c94134.zip
Move hard coded URLs to computed data attributes
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/activetext/index.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/app/javascript/activetext/index.js b/app/javascript/activetext/index.js
index cdcd1d311f..e1c59dd50d 100644
--- a/app/javascript/activetext/index.js
+++ b/app/javascript/activetext/index.js
@@ -1,14 +1,12 @@
import * as Trix from "trix"
import { DirectUpload } from "activestorage"
-// FIXME: Hard coded routes
-const directUploadsURL = "/rails/active_storage/direct_uploads"
-const blobsURL = "/rails/active_storage/blobs"
-
addEventListener("trix-attachment-add", event => {
const { attachment } = event
if (!attachment.file) return
+ const { directUploadUrl, blobUrlTemplate } = event.target.dataset
+
const delegate = {
directUploadWillStoreFileWithXHR: (xhr) => {
xhr.upload.addEventListener("progress", event => {
@@ -18,17 +16,19 @@ addEventListener("trix-attachment-add", event => {
}
}
- const directUpload = new DirectUpload(attachment.file, directUploadsURL, delegate)
+ const directUpload = new DirectUpload(attachment.file, directUploadUrl, delegate)
directUpload.create((error, attributes) => {
if (error) {
console.warn("Failed to store file for attachment", attachment, error)
} else {
- console.log("Created blob for attachment", attributes, attachment)
- attachment.setAttributes({
- url: `${blobsURL}/${attributes.signed_id}/${encodeURIComponent(attachment.file.name)}`,
- sgid: attributes.attachable_sgid
- })
+ const sgid = attributes.attachable_sgid
+
+ const url = blobUrlTemplate
+ .replace(":signed_id", attributes.signed_id)
+ .replace(":filename", encodeURIComponent(attributes.filename))
+
+ attachment.setAttributes({ sgid, url })
}
})
})