Module: Sinatra::AssetHelper
- Includes:
- Rack::Utils
- Defined in:
- lib/sras/helpers/asset.rb
Instance Method Summary collapse
- #get_asset_data(asset_id) ⇒ Object
-
#get_asset_type(request) ⇒ Object
usage: asset_type = get_asset_type(‘image/tga’) asset_type = get_asset_type(12).
- #write_asset_data ⇒ Object
Instance Method Details
#get_asset_data(asset_id) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sras/helpers/asset.rb', line 8 def get_asset_data(asset_id) @asset = Asset.get(asset_id) if @asset.enabled == false return end @asset_file = @asset.base_dir + '/' + @asset.sha256[0..2] + '/' + @asset.sha256[3..5] + '/' + @asset.sha256 if File.exists?(@asset_file + '.gz') Zlib::GzipReader.open(@asset_file + '.gz') do |file| @asset_data = file.read end elsif File.exists?(@asset_file) File.open(@asset_file) do |file| @asset_data = file.read end end return @asset_data end |
#get_asset_type(request) ⇒ Object
usage:
asset_type = get_asset_type('image/tga')
asset_type = get_asset_type(12)
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sras/helpers/asset.rb', line 72 def get_asset_type(request) # default 'application/octet-stream' asset_type = { 'image/jp2' => 0, 'application/ogg' => 1, 'application/x-metaverse-callingcard' => 2, 'application/x-metaverse-landmark' => 3, 'application/x-metaverse-clothing' => 5, 'application/x-metaverse-primitive' => 6, 'application/x-metaverse-notecard' => 7, 'application/x-metaverse-folder' => 8, 'application/x-metaverse-lsl' => 10, 'application/x-metaverse-lso' => 11, 'image/tga' => 12, 'application/x-metaverse-bodypart' => 13, 'audio/x-wav' => 17, 'image/jpeg' => 19, 'application/x-metaverse-animation' => 20, 'application/x-metaverse-gesture' => 21, 'application/x-metaverse-simstate' => 22 } if asset_type[request] response = asset_type[request] elsif asset_type.invert[request] response = asset_type.invert[request] end return response end |
#write_asset_data ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sras/helpers/asset.rb', line 30 def write_asset_data() @asset_file_dir = @asset.base_dir + '/' + @asset.sha256[0..2] + '/' + @asset.sha256[3..5] @asset_file = @asset_file_dir + '/' + @asset.sha256 # see if asset file with this hash already exists. if it # does, then we don't need to overwrite it with identical # data... if File.exists?(@asset_file + '.gz') || File.exists?(@asset_file) return end # mkdirs if necessary... FileUtils.mkpath @asset_file_dir # write the data to a file, gzip'd... Zlib::GzipWriter.open(@asset_file + '.gz') do |file| file.write @asset_data file.close end end |