Skip to content

Commit 35ddc8e

Browse files
committed
routes and working url_meta for URL uploading
1 parent 5835609 commit 35ddc8e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class UppyCompanionController < ApplicationController
2+
skip_forgery_protection
3+
4+
def url_meta
5+
authorize :model, :new?
6+
# Do HEAD request for url
7+
response = Faraday.head params[:url]
8+
render json: {
9+
name: response.headers["filename"],
10+
type: response.headers["content-type"],
11+
size: response.headers["content-length"],
12+
status_code: response.status
13+
}
14+
end
15+
16+
def url_get
17+
authorize :model, :new?
18+
Faraday.get params[:url]
19+
render status: :internal_server_error, json: {}
20+
end
21+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136

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

141143
get("/oembed", to: redirect(status: 303) { |_, request|
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe "UppyCompanions", type: :request do
4+
describe "GET /url_meta" do
5+
it "returns http success" do
6+
get "/uppy_companion/url_meta"
7+
expect(response).to have_http_status(:success)
8+
end
9+
end
10+
11+
describe "GET /url_get" do
12+
it "returns http success" do
13+
get "/uppy_companion/url_get"
14+
expect(response).to have_http_status(:success)
15+
end
16+
end
17+
18+
end

0 commit comments

Comments
 (0)