From bff96fe21b483e8433d623cae8f242fece6b5a3d Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Sun, 23 Sep 2012 21:24:03 +0200 Subject: [PATCH] Use cloudinary to save and show images --- server/assets/gallery.html | 2 +- server/main.rb | 4 ++++ server/model.rb | 12 ++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server/assets/gallery.html b/server/assets/gallery.html index 239a82a..01c1565 100644 --- a/server/assets/gallery.html +++ b/server/assets/gallery.html @@ -82,7 +82,7 @@

GLSL Sandbox

diff --git a/server/main.rb b/server/main.rb index 4616758..39b3432 100644 --- a/server/main.rb +++ b/server/main.rb @@ -4,6 +4,7 @@ require 'mongo' require 'json' require 'erb' +require 'cloudinary' $: << './server' @@ -15,6 +16,9 @@ set :public_folder, 'server/assets' GALLERY=ERB.new(File.read('server/assets/gallery.html')) + IMAGE_PREFIX=ENV['IMAGE_PREFIX']||'' + uri=URI.parse(ENV['CLOUDINARY_URL']) + CLOUDINARY_PROJECT=uri.host $glsl=GlslDatabase.new diff --git a/server/model.rb b/server/model.rb index 64b016a..e8a45b8 100644 --- a/server/model.rb +++ b/server/model.rb @@ -32,6 +32,11 @@ def next_page @extra[:page]+1 end end + + def image(effect) + "http://res.cloudinary.com/#{CLOUDINARY_PROJECT}/image/upload/"<< + "#{IMAGE_PREFIX}#{effect['_id']}.png" + end end class GlslDatabase @@ -62,13 +67,16 @@ def save_version(code_id, code) :query => { :_id => code_id }, :update => { '$set' => { - :modified_at => time, - :image => code_data['image'] + :modified_at => time }, '$push' => { :versions => data } } }) + Cloudinary::Uploader.upload( + code_data['image'], + :public_id => IMAGE_PREFIX+code_id.to_s) + code=$glsl.get_code(code_id) version=code['versions'].length-1