asset_host_core 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.markdown +138 -0
- data/Rakefile +11 -0
- data/app/assets/images/asset_host_core/alert-overlay.png +0 -0
- data/app/assets/images/asset_host_core/arrow-left.gif +0 -0
- data/app/assets/images/asset_host_core/arrow-right.gif +0 -0
- data/app/assets/images/asset_host_core/fallback-img-rect.png +0 -0
- data/app/assets/images/asset_host_core/videoplayer-play.png +0 -0
- data/app/assets/images/asset_host_core/x.png +0 -0
- data/app/assets/javascripts/asset_host_core/admin/assets.js.coffee +221 -0
- data/app/assets/javascripts/asset_host_core/application.js +20 -0
- data/app/assets/javascripts/asset_host_core/assetadmin.js.coffee +56 -0
- data/app/assets/javascripts/asset_host_core/assethost.js.coffee.erb +17 -0
- data/app/assets/javascripts/asset_host_core/browserui.js.coffee +139 -0
- data/app/assets/javascripts/asset_host_core/chooserui.js.coffee +381 -0
- data/app/assets/javascripts/asset_host_core/client.js.coffee +29 -0
- data/app/assets/javascripts/asset_host_core/clients/BrightcoveVideo.js.coffee +64 -0
- data/app/assets/javascripts/asset_host_core/clients/templates/brightcove_embed.jst.eco +18 -0
- data/app/assets/javascripts/asset_host_core/clients/templates/vimeo_embed.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/clients/templates/youtube_embed.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/clients/vimeo_video.js.coffee +21 -0
- data/app/assets/javascripts/asset_host_core/clients/youtube_video.js.coffee +21 -0
- data/app/assets/javascripts/asset_host_core/cmsplugin.js.coffee +235 -0
- data/app/assets/javascripts/asset_host_core/models.js.coffee +586 -0
- data/app/assets/javascripts/asset_host_core/railsCMS.js.coffee +141 -0
- data/app/assets/javascripts/asset_host_core/slideshow.js.coffee +428 -0
- data/app/assets/javascripts/asset_host_core/templates/after_upload_button.jst.eco +3 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_drop_asset.jst.eco +4 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_modal.jst.eco +13 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_preview.jst.eco +35 -0
- data/app/assets/javascripts/asset_host_core/templates/asset_search.jst.eco +2 -0
- data/app/assets/javascripts/asset_host_core/templates/browser_asset.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/templates/browser_asset_tip.jst.eco +3 -0
- data/app/assets/javascripts/asset_host_core/templates/edit_modal.jst.eco +40 -0
- data/app/assets/javascripts/asset_host_core/templates/import_help.jst.eco +59 -0
- data/app/assets/javascripts/asset_host_core/templates/pagination_link.jst.eco +1 -0
- data/app/assets/javascripts/asset_host_core/templates/pagination_links.jst.eco +13 -0
- data/app/assets/javascripts/asset_host_core/templates/queued_file.jst.eco +11 -0
- data/app/assets/javascripts/asset_host_core/templates/save_and_close_view.jst.eco +4 -0
- data/app/assets/javascripts/asset_host_core/templates/upload_all_button.jst.eco +4 -0
- data/app/assets/javascripts/asset_host_core/templates/url_input.jst.eco +8 -0
- data/app/assets/stylesheets/asset_host_core/application.css.scss +384 -0
- data/app/assets/stylesheets/asset_host_core/jquery-ui.css +105 -0
- data/app/assets/stylesheets/asset_host_core/public.css.scss +204 -0
- data/app/assets/stylesheets/asset_host_core/slidetest.css.scss +93 -0
- data/app/controllers/asset_host_core/admin/api_users_controller.rb +72 -0
- data/app/controllers/asset_host_core/admin/assets_controller.rb +140 -0
- data/app/controllers/asset_host_core/admin/base_controller.rb +36 -0
- data/app/controllers/asset_host_core/admin/home_controller.rb +13 -0
- data/app/controllers/asset_host_core/admin/outputs_controller.rb +55 -0
- data/app/controllers/asset_host_core/api/assets_controller.rb +110 -0
- data/app/controllers/asset_host_core/api/base_controller.rb +43 -0
- data/app/controllers/asset_host_core/api/outputs_controller.rb +33 -0
- data/app/controllers/asset_host_core/application_controller.rb +43 -0
- data/app/controllers/asset_host_core/public_controller.rb +104 -0
- data/app/models/asset_host_core/api_user.rb +44 -0
- data/app/models/asset_host_core/api_user_permission.rb +6 -0
- data/app/models/asset_host_core/asset.rb +265 -0
- data/app/models/asset_host_core/asset_output.rb +69 -0
- data/app/models/asset_host_core/brightcove_video.rb +20 -0
- data/app/models/asset_host_core/output.rb +52 -0
- data/app/models/asset_host_core/permission.rb +19 -0
- data/app/models/asset_host_core/video.rb +8 -0
- data/app/models/asset_host_core/vimeo_video.rb +17 -0
- data/app/models/asset_host_core/youtube_video.rb +17 -0
- data/app/views/asset_host_core/admin/api_users/_form_fields.html.erb +5 -0
- data/app/views/asset_host_core/admin/api_users/edit.html.erb +26 -0
- data/app/views/asset_host_core/admin/api_users/index.html.erb +31 -0
- data/app/views/asset_host_core/admin/api_users/new.html.erb +17 -0
- data/app/views/asset_host_core/admin/api_users/show.html.erb +23 -0
- data/app/views/asset_host_core/admin/assets/index.html.erb +19 -0
- data/app/views/asset_host_core/admin/assets/metadata.html.erb +24 -0
- data/app/views/asset_host_core/admin/assets/show.html.erb +86 -0
- data/app/views/asset_host_core/admin/home/chooser.html.erb +49 -0
- data/app/views/asset_host_core/admin/outputs/_form_fields.html.erb +5 -0
- data/app/views/asset_host_core/admin/outputs/edit.html.erb +26 -0
- data/app/views/asset_host_core/admin/outputs/index.html.erb +27 -0
- data/app/views/asset_host_core/admin/outputs/new.html.erb +13 -0
- data/app/views/asset_host_core/admin/outputs/show.html.erb +17 -0
- data/app/views/asset_host_core/shared/_footerjs.html.erb +3 -0
- data/app/views/asset_host_core/shared/_navbar.html.erb +28 -0
- data/app/views/kaminari/_first_page.html.erb +3 -0
- data/app/views/kaminari/_gap.html.erb +3 -0
- data/app/views/kaminari/_last_page.html.erb +3 -0
- data/app/views/kaminari/_next_page.html.erb +3 -0
- data/app/views/kaminari/_page.html.erb +3 -0
- data/app/views/kaminari/_paginator.html.erb +17 -0
- data/app/views/kaminari/_prev_page.html.erb +3 -0
- data/app/views/layouts/asset_host_core/application.html.erb +54 -0
- data/app/views/layouts/asset_host_core/full_width.html.erb +32 -0
- data/app/views/layouts/asset_host_core/minimal.html.erb +45 -0
- data/config/initializers/simple_form.rb +142 -0
- data/config/initializers/simple_form_bootstrap.rb +45 -0
- data/config/locales/simple_form.en.yml +26 -0
- data/config/routes.rb +49 -0
- data/lib/asset_host_core.rb +38 -0
- data/lib/asset_host_core/config.rb +39 -0
- data/lib/asset_host_core/engine.rb +94 -0
- data/lib/asset_host_core/loaders.rb +34 -0
- data/lib/asset_host_core/loaders/asset_host.rb +30 -0
- data/lib/asset_host_core/loaders/base.rb +22 -0
- data/lib/asset_host_core/loaders/brightcove.rb +67 -0
- data/lib/asset_host_core/loaders/flickr.rb +114 -0
- data/lib/asset_host_core/loaders/url.rb +59 -0
- data/lib/asset_host_core/loaders/vimeo.rb +76 -0
- data/lib/asset_host_core/loaders/youtube.rb +90 -0
- data/lib/asset_host_core/model_methods.rb +61 -0
- data/lib/asset_host_core/paperclip.rb +4 -0
- data/lib/asset_host_core/paperclip/asset_thumbnail.rb +92 -0
- data/lib/asset_host_core/paperclip/attachment.rb +206 -0
- data/lib/asset_host_core/paperclip/trimmer.rb +33 -0
- data/lib/asset_host_core/resque_job.rb +13 -0
- data/lib/asset_host_core/version.rb +3 -0
- data/lib/tasks/asset_host_core_tasks.rake +4 -0
- data/spec/controllers/admin/api_users_controller_spec.rb +21 -0
- data/spec/controllers/admin/assets_controller_spec.rb +59 -0
- data/spec/controllers/admin/home_controller_spec.rb +4 -0
- data/spec/controllers/admin/outputs_controller_spec.rb +4 -0
- data/spec/controllers/api/assets_controller_spec.rb +133 -0
- data/spec/controllers/api/outputs_controller_spec.rb +51 -0
- data/spec/controllers/public_controller_spec.rb +4 -0
- data/spec/factories.rb +39 -0
- data/spec/features/api_users_spec.rb +78 -0
- data/spec/fixtures/api/brightcove/video.json +137 -0
- data/spec/fixtures/api/flickr/photos_getInfo.json +78 -0
- data/spec/fixtures/api/flickr/photos_getSizes.json +82 -0
- data/spec/fixtures/api/flickr/photos_licenses_getInfo.json +52 -0
- data/spec/fixtures/api/vimeo/video.json +28 -0
- data/spec/fixtures/api/youtube/discovery.json +5190 -0
- data/spec/fixtures/api/youtube/video.json +44 -0
- data/spec/fixtures/images/chipmunk.jpg +0 -0
- data/spec/fixtures/images/dude.jpg +0 -0
- data/spec/fixtures/images/ernie.jpg +0 -0
- data/spec/fixtures/images/fry.png +0 -0
- data/spec/fixtures/images/hat.jpg +0 -0
- data/spec/fixtures/images/spongebob.png +0 -0
- data/spec/fixtures/images/stars.jpg +0 -0
- data/spec/internal/app/controllers/application_controller.rb +16 -0
- data/spec/internal/app/controllers/sessions_controller.rb +24 -0
- data/spec/internal/app/models/user.rb +10 -0
- data/spec/internal/app/views/sessions/new.html.erb +14 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/assethost_config.rb +57 -0
- data/spec/internal/config/routes.rb +7 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +106 -0
- data/spec/internal/log/test.log +14769 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/internal/public/images/1_27f7745237849975ca90591c1fba5934_original. +0 -0
- data/spec/internal/public/images/1_7d33319deca787d5bb3f62ff06563ad2_original. +0 -0
- data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original. +0 -0
- data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original.jpg +0 -0
- data/spec/internal/public/images/1_b6d48c8b1286104ce76649731e09645f_original.txt +0 -0
- data/spec/internal/public/images/1_e179cbd27e07cb55042d0db36cdac095_original. +0 -0
- data/spec/internal/public/images/1_e669edd3dfd74be66fc38416e82e3a37_original. +0 -0
- data/spec/lib/asset_host_core/loaders/asset_host_spec.rb +33 -0
- data/spec/lib/asset_host_core/loaders/brightcove_spec.rb +51 -0
- data/spec/lib/asset_host_core/loaders/flickr_spec.rb +72 -0
- data/spec/lib/asset_host_core/loaders/url_spec.rb +42 -0
- data/spec/lib/asset_host_core/loaders/vimeo_spec.rb +51 -0
- data/spec/lib/asset_host_core/loaders/youtube_spec.rb +73 -0
- data/spec/lib/asset_host_core/loaders_spec.rb +4 -0
- data/spec/lib/asset_host_core/model_methods_spec.rb +4 -0
- data/spec/lib/asset_host_core/paperclip/asset_thumbnail_spec.rb +4 -0
- data/spec/lib/asset_host_core/paperclip/attachment_spec.rb +4 -0
- data/spec/lib/asset_host_core/resque_job_spec.rb +4 -0
- data/spec/lib/asset_host_core_spec.rb +4 -0
- data/spec/models/api_user_spec.rb +58 -0
- data/spec/models/asset_output_spec.rb +4 -0
- data/spec/models/asset_spec.rb +4 -0
- data/spec/models/output_spec.rb +4 -0
- data/spec/models/permission_spec.rb +4 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/fixture_loader.rb +9 -0
- data/spec/support/param_helper.rb +14 -0
- data/spec/support/permission_matcher.rb +17 -0
- data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_flat_10_000000_40x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_222222_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_228ef1_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_ef8c08_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_ffd27a_256x240.png +0 -0
- data/vendor/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
- data/vendor/assets/javascripts/backbone.js +1158 -0
- data/vendor/assets/javascripts/backbone.modelbinding.js +475 -0
- data/vendor/assets/javascripts/exif.js +695 -0
- data/vendor/assets/javascripts/jquery-ui.js +5614 -0
- data/vendor/assets/javascripts/simplemodal.js +698 -0
- data/vendor/assets/javascripts/spin.jquery.js +81 -0
- data/vendor/assets/javascripts/spin.min.js +1 -0
- data/vendor/assets/javascripts/underscore.min.js +1 -0
- metadata +658 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
module AssetHostCore
|
2
|
+
module Admin
|
3
|
+
class AssetsController < BaseController
|
4
|
+
before_filter :get_asset, only: [:show, :update, :replace, :destroy]
|
5
|
+
skip_before_filter :verify_authenticity_token, only: [:upload, :replace]
|
6
|
+
|
7
|
+
#----------
|
8
|
+
|
9
|
+
def index
|
10
|
+
@assets = Asset.visible.order("updated_at desc")
|
11
|
+
.page(params[:page])
|
12
|
+
.per(24)
|
13
|
+
end
|
14
|
+
|
15
|
+
#----------
|
16
|
+
|
17
|
+
def search
|
18
|
+
@query = params[:q]
|
19
|
+
|
20
|
+
@assets = Asset.visible.search(@query,
|
21
|
+
:page => params[:page] ? params[:page].to_i : 1,
|
22
|
+
:per_page => 24,
|
23
|
+
:order => "created_at DESC, @relevance DESC",
|
24
|
+
:field_weights => {
|
25
|
+
:title => 10,
|
26
|
+
:caption => 5
|
27
|
+
}
|
28
|
+
)
|
29
|
+
|
30
|
+
render :index
|
31
|
+
end
|
32
|
+
|
33
|
+
#----------
|
34
|
+
|
35
|
+
def upload
|
36
|
+
file = params[:file]
|
37
|
+
|
38
|
+
# FIXME: Put in place to keep Firefox 7 happy
|
39
|
+
if !file.original_filename
|
40
|
+
file.original_filename = "upload.jpg"
|
41
|
+
end
|
42
|
+
|
43
|
+
asset = Asset.new(image: file)
|
44
|
+
|
45
|
+
if asset.save
|
46
|
+
render json: asset.as_json
|
47
|
+
else
|
48
|
+
render text: 'ERROR'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#----------
|
53
|
+
|
54
|
+
def metadata
|
55
|
+
@assets = Asset.where(id: params[:ids].split(','))
|
56
|
+
end
|
57
|
+
|
58
|
+
#----------
|
59
|
+
|
60
|
+
def update_metadata
|
61
|
+
params[:assets].each do |id, attributes|
|
62
|
+
asset = Asset.find(id)
|
63
|
+
asset.update_attributes(attributes)
|
64
|
+
end
|
65
|
+
|
66
|
+
redirect_to a_assets_path
|
67
|
+
end
|
68
|
+
|
69
|
+
#----------
|
70
|
+
|
71
|
+
def show
|
72
|
+
# Use "visible" here because we are choosing next/prev based on the
|
73
|
+
# index listing. Hard-coding the order here (ID) because the
|
74
|
+
# AssetHostBrowserUI uses ID if no ORDER option is passed in, which
|
75
|
+
# it currently isn't, so the grid is ordered by ID.
|
76
|
+
@assets = AssetHostCore::Asset.visible.order('id desc')
|
77
|
+
@prev = @assets.where('id > ?', @asset.id).last
|
78
|
+
@next = @assets.where('id < ?', @asset.id).first
|
79
|
+
end
|
80
|
+
|
81
|
+
#----------
|
82
|
+
|
83
|
+
def update
|
84
|
+
if @asset.update_attributes(params[:asset])
|
85
|
+
flash[:notice] = "Successfully updated asset."
|
86
|
+
redirect_to a_asset_path(@asset)
|
87
|
+
else
|
88
|
+
flash[:notice] = @asset.errors.full_messages.join("<br/>")
|
89
|
+
render :action => :edit
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
#----------
|
94
|
+
|
95
|
+
def replace
|
96
|
+
file = params[:file]
|
97
|
+
|
98
|
+
if !file
|
99
|
+
render :text => 'ERROR' and return
|
100
|
+
end
|
101
|
+
|
102
|
+
# FIXME: Put in place to keep Firefox 7 happy
|
103
|
+
if !file.original_filename
|
104
|
+
file.original_filename = "upload.jpg"
|
105
|
+
end
|
106
|
+
|
107
|
+
# tell paperclip to replace our image
|
108
|
+
@asset.image = file
|
109
|
+
|
110
|
+
if @asset.save
|
111
|
+
render json: @asset.as_json
|
112
|
+
else
|
113
|
+
puts "Error: #{@asset.errors.to_s}"
|
114
|
+
render :text => 'ERROR'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#----------
|
119
|
+
|
120
|
+
def destroy
|
121
|
+
if @asset.destroy
|
122
|
+
flash[:notice] = "Deleted asset #{@asset.title}."
|
123
|
+
redirect_to a_assets_path
|
124
|
+
else
|
125
|
+
flash[:error] = "Unable to delete asset."
|
126
|
+
redirect_to a_asset_path(@asset)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
#----------
|
132
|
+
|
133
|
+
protected
|
134
|
+
|
135
|
+
def get_asset
|
136
|
+
@asset = Asset.find(params[:id])
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module AssetHostCore
|
2
|
+
module Admin
|
3
|
+
class BaseController < ApplicationController
|
4
|
+
layout 'asset_host_core/application'
|
5
|
+
|
6
|
+
before_filter :_authenticate_user!
|
7
|
+
|
8
|
+
helper_method :_current_user
|
9
|
+
helper_method :_sign_out_path
|
10
|
+
|
11
|
+
def _authenticate_user!
|
12
|
+
instance_eval &AssetHostCore::Config.authentication_method
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def _current_user
|
17
|
+
instance_eval &AssetHostCore::Config.current_user_method
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def _sign_out_path
|
22
|
+
instance_eval &AssetHostCore::Config.sign_out_path
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def authorize_admin
|
29
|
+
unless current_user.is_admin?
|
30
|
+
flash[:error] = "You must be a superuser to do that."
|
31
|
+
redirect_to assethost.a_root_path and return false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module AssetHostCore
|
2
|
+
module Admin
|
3
|
+
class OutputsController < BaseController
|
4
|
+
layout 'asset_host_core/full_width'
|
5
|
+
|
6
|
+
before_filter :authorize_admin
|
7
|
+
before_filter :get_output, except: [:index, :new, :create]
|
8
|
+
|
9
|
+
|
10
|
+
def index
|
11
|
+
@outputs = Output.all
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def update
|
16
|
+
if @output.update_attributes(params[:output])
|
17
|
+
flash[:notice] = "Updated Output."
|
18
|
+
redirect_to a_outputs_path
|
19
|
+
else
|
20
|
+
render :edit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def new
|
26
|
+
@output = Output.new
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def create
|
31
|
+
@output = Output.new(params[:output])
|
32
|
+
|
33
|
+
if @output.save
|
34
|
+
flash[:notice] = "Created Output."
|
35
|
+
redirect_to a_outputs_path
|
36
|
+
else
|
37
|
+
render :new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
@output.destroy
|
44
|
+
flash[:notice] = "Destroyed Output."
|
45
|
+
redirect_to a_outputs_path
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def get_output
|
51
|
+
@output = Output.find(params[:id])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module AssetHostCore
|
2
|
+
module Api
|
3
|
+
class AssetsController < BaseController
|
4
|
+
before_filter :set_access_control_headers
|
5
|
+
|
6
|
+
before_filter -> { authorize(:read) }, only: [:index, :show, :tag]
|
7
|
+
before_filter -> { authorize(:write) }, only: [:update, :create]
|
8
|
+
|
9
|
+
before_filter :get_asset, only: [:show, :update, :tag]
|
10
|
+
|
11
|
+
|
12
|
+
def index
|
13
|
+
if params[:q].present?
|
14
|
+
@assets = Asset.visible.search(params[:q],
|
15
|
+
:page => params[:page] ? params[:page].to_i : 1,
|
16
|
+
:per_page => 24,
|
17
|
+
:order => "created_at DESC, @relevance DESC",
|
18
|
+
:field_weights => {
|
19
|
+
:title => 10,
|
20
|
+
:caption => 3
|
21
|
+
}
|
22
|
+
)
|
23
|
+
else
|
24
|
+
@assets = Asset.visible.order("updated_at desc")
|
25
|
+
.page(params[:page])
|
26
|
+
.per(24)
|
27
|
+
end
|
28
|
+
|
29
|
+
response.headers['X-Next-Page'] = (@assets.last_page? ? nil : @assets.current_page + 1).to_s
|
30
|
+
response.headers['X-Total-Entries'] = @assets.total_count.to_s
|
31
|
+
|
32
|
+
respond_with @assets
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def show
|
37
|
+
respond_with @asset
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def update
|
42
|
+
if @asset.update_attributes(params[:asset])
|
43
|
+
respond_with @asset
|
44
|
+
else
|
45
|
+
respond_with @asset.errors.full_messages, :status => :error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def create
|
51
|
+
if !params[:url]
|
52
|
+
render_bad_request(message: "Must provide an asset URL")
|
53
|
+
return false
|
54
|
+
end
|
55
|
+
|
56
|
+
# see if we have a loader for this URL
|
57
|
+
if asset = AssetHostCore.as_asset(params[:url])
|
58
|
+
if params[:note].present?
|
59
|
+
asset.notes += "\n#{params[:note]}"
|
60
|
+
end
|
61
|
+
|
62
|
+
asset.is_hidden = params[:hidden].present?
|
63
|
+
asset.caption = params[:caption] if params[:caption].present?
|
64
|
+
asset.owner = params[:owner] if params[:owner].present?
|
65
|
+
asset.title = params[:title] if params[:title].present?
|
66
|
+
|
67
|
+
asset.save
|
68
|
+
respond_with asset, location: a_asset_path(asset)
|
69
|
+
|
70
|
+
else
|
71
|
+
render_not_found(message: "Unable to find or load an asset at " \
|
72
|
+
"the URL #{params[:url]}")
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def tag
|
79
|
+
output = Output.find_by_code!(params[:style])
|
80
|
+
ao = @asset.outputs.where(output_id: output.id).first
|
81
|
+
|
82
|
+
tag = {
|
83
|
+
:id => @asset.id,
|
84
|
+
:tag => @asset.image.tag(params[:style].to_sym),
|
85
|
+
:updated_at => @asset.image_updated_at,
|
86
|
+
:owner => @asset.owner,
|
87
|
+
:width => ao.try(:width),
|
88
|
+
:height => ao.try(:height)
|
89
|
+
}
|
90
|
+
|
91
|
+
respond_with tag
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def authorize(ability)
|
98
|
+
super ability, "AssetHostCore::Asset"
|
99
|
+
end
|
100
|
+
|
101
|
+
def get_asset
|
102
|
+
@asset = Asset.find_by_id(params[:id])
|
103
|
+
|
104
|
+
if !@asset
|
105
|
+
render_not_found and return false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AssetHostCore
|
2
|
+
module Api
|
3
|
+
class BaseController < ApplicationController
|
4
|
+
layout false
|
5
|
+
|
6
|
+
before_filter :authenticate_api_user
|
7
|
+
respond_to :json
|
8
|
+
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def set_access_control_headers
|
13
|
+
response.headers['Access-Control-Allow-Origin'] =
|
14
|
+
request.env['HTTP_ORIGIN'] || "*"
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# For the authentication/authorization checks, if the API is being
|
19
|
+
# accessed by AssetHost, then we should give it full write permission.
|
20
|
+
# If we add write ability via the API to Outputs or anything else,
|
21
|
+
# we should reassess this decision.
|
22
|
+
def authenticate_api_user
|
23
|
+
return true if current_user
|
24
|
+
@api_user = ApiUser.authenticate(params[:auth_token])
|
25
|
+
|
26
|
+
if !@api_user
|
27
|
+
render_unauthorized and return false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def authorize(ability, resource)
|
33
|
+
return true if current_user
|
34
|
+
|
35
|
+
if !@api_user.may?(ability, resource)
|
36
|
+
render_forbidden and return false
|
37
|
+
else
|
38
|
+
return true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module AssetHostCore
|
2
|
+
module Api
|
3
|
+
class OutputsController < BaseController
|
4
|
+
before_filter -> { authorize(:read) }, only: [:index, :show]
|
5
|
+
before_filter :get_output, only: [:show]
|
6
|
+
|
7
|
+
|
8
|
+
def index
|
9
|
+
@outputs = Output.all
|
10
|
+
respond_with @outputs
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
respond_with @output
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def authorize(ability)
|
21
|
+
super ability, "AssetHostCore::Output"
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_output
|
25
|
+
@output = Output.find_by_code(params[:id])
|
26
|
+
|
27
|
+
if !@output
|
28
|
+
render_not_found and return false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AssetHostCore
|
2
|
+
class ApplicationController < ::ApplicationController
|
3
|
+
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def render_not_found(options={})
|
8
|
+
options[:message] ||= "Not Found"
|
9
|
+
render_error(status: 404, message: options[:message])
|
10
|
+
end
|
11
|
+
|
12
|
+
def render_bad_request(options={})
|
13
|
+
options[:message] ||= "Bad Request"
|
14
|
+
render_error(status: 400, message: options[:message])
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_unauthorized(options={})
|
18
|
+
options[:message] ||= "Unauthorized"
|
19
|
+
render_error(status: 401, message: options[:message])
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_forbidden(options={})
|
23
|
+
options[:message] ||= "Forbidden"
|
24
|
+
render_error(status: 403, message: options[:message])
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def render_error(options={})
|
29
|
+
options[:message] ||= "Error"
|
30
|
+
|
31
|
+
respond_to do |format|
|
32
|
+
format.html { render status: options[:status] }
|
33
|
+
|
34
|
+
format.json do
|
35
|
+
render :json => {
|
36
|
+
:status => options[:status],
|
37
|
+
:error => options[:message]
|
38
|
+
}, :status => options[:status]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|