Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $ra-font-path: "https://cdn.jsdelivr.net/npm/@infinizhen/rpg-awesome-continued@1

@import '@uppy/core/dist/style.min';
@import '@uppy/dashboard/dist/style.min';
@import '@uppy/url/dist/style.min';

.ts-control {
padding: 1px;
Expand Down
32 changes: 32 additions & 0 deletions app/controllers/uppy_companion_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class UppyCompanionController < ApplicationController
before_action :check_auth
before_action :validate_uri

def url_meta
response = Faraday.head @uri
render json: {
name: @uri.path.split("/").last,
type: response.headers["content-type"],
size: response.headers["content-length"].to_i,
status_code: response.status
}
end

def url_get
response = Faraday.get @uri
render status: response.status, json: {}
end

private

def check_auth
authorize :model, :new?
end

def validate_uri
@uri = URI.parse(params.permit(uppy_companion: [:url]).dig(:uppy_companion, :url))
head :bad_request unless ["https", "http"].include?(@uri.scheme)
rescue URI::InvalidURIError
head :bad_request
end
end
7 changes: 7 additions & 0 deletions app/javascript/controllers/upload_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Controller } from '@hotwired/stimulus'
import Uppy from '@uppy/core'
import Dashboard from '@uppy/dashboard'
import Tus from '@uppy/tus'
import Url from '@uppy/url'

import cs from '@uppy/locales/lib/cs_CZ'
import de from '@uppy/locales/lib/de_DE'
Expand Down Expand Up @@ -30,6 +31,12 @@ export default class extends Controller {
maxFileSize: +(settings?.maxFileSize ?? -1)
}
})
.use(Url, {
companionUrl: '/uppy_companion',
companionHeaders: {
"X-CSRF-Token": (document.head.querySelector("meta[name=csrf-token]") as HTMLMetaElement)?.content
}
})
.use(Dashboard, {
inline: true,
target: this.element,
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@

authenticate :user, lambda { |u| u.is_contributor? } do
mount Tus::Server => "/upload", :as => :upload
post "/uppy_companion/url/meta" => "uppy_companion#url_meta"
post "/uppy_companion/url/get" => "uppy_companion#url_get"
end

get("/oembed", to: redirect(status: 303) { |_, request|
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@uppy/form": "^4.1.1",
"@uppy/locales": "^4.5.2",
"@uppy/tus": "^4.2.2",
"@uppy/url": "^4.2.1",
"@uppy/utils": "^6.1.4",
"@zxcvbn-ts/core": "^3.0.4",
"@zxcvbn-ts/language-common": "^3.0.4",
Expand Down
67 changes: 67 additions & 0 deletions spec/cassettes/UppyCompanion_get_success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions spec/cassettes/UppyCompanion_meta_success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading