diff --git a/README.Developer b/README.Developer index dc6a10a..6099c0f 100644 --- a/README.Developer +++ b/README.Developer @@ -82,7 +82,6 @@ properly unless the separate model validation is in place. Deployment ---------- - To prepare your computer to run Debshots 2.x either for development or production you need to… @@ -90,7 +89,7 @@ or production you need to… - install Ruby 2.0.0 via rvm (see http://rvm.io/) - install the library header packages so that the required Ruby gems can be compiled: - sudo apt-get install libbz2-dev libpq-dev + sudo apt-get install libbz2-dev libpq-dev libyaml-dev - install a PostgreSQL database: sudo apt-get install postgresql - edit the PostgreSQL authentication configuration at diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 64acd72..10b8733 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base # and show them even before moderation. def create_user_token session[:token] ||= SecureRandom.hex + session[:ip] ||= request.remote_ip end end diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 738d23d..f8eebd4 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -24,6 +24,8 @@ class PackagesController < ApplicationController @package = Package.find_by(name: params[:name]) end + # POST target of the screenshots upload form. + # Checks upload images and creates a new Screenshot record for it. def upload_image @package = Package.find_by(name: params[:name]) @@ -33,13 +35,15 @@ class PackagesController < ApplicationController new_screenshot = @package.screenshots.new(image: img) # Check if the image was valid - unless new_screenshot.valid? - errors = new_screenshot.errors[:image].join(' and ') - flash['alert'] = "Sorry - the image #{errors}" - else + if new_screenshot.valid? + new_screenshot.uploaderhash = session[:token] + new_screenshot.uploaderip = session[:ip] new_screenshot.save successful_upload_count += 1 Log.log "Screenshot #{new_screenshot.id} uploaded successfully." + else + errors = new_screenshot.errors[:image].join(' and ') + flash['alert'] = "Sorry - the image #{errors}" end if successful_upload_count > 0 diff --git a/app/models/screenshot.rb b/app/models/screenshot.rb index 5524ab0..6e59c7a 100644 --- a/app/models/screenshot.rb +++ b/app/models/screenshot.rb @@ -42,7 +42,7 @@ class Screenshot < ActiveRecord::Base # Return Debshots 1.x path to allow migration of images into Paperclip filesystem schema def image_url(size) - "#{Rails.configuration.images_path_prefix}/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png" + "live/screenshots/approved/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png" end diff --git a/app/views/packages/details.slim b/app/views/packages/details.slim index ef465ff..4d8ed63 100644 --- a/app/views/packages/details.slim +++ b/app/views/packages/details.slim @@ -10,6 +10,9 @@ .small-12.columns a.black.fancybox href=screenshot.image.url(:large, timestamp: false) rel='fancybox-thumb' title=screenshot.caption = image_tag(screenshot.image.url(:large, timestamp: false), alt: screenshot.caption) + .imgcaption =screenshot.caption + // TODO: Show information only if admin + p Uploader IP=#{screenshot.uploaderip} / Token=#{screenshot.uploaderhash} // TODO: Enable button only if admin or uploader a.button.tiny.alert[ href=delete_screenshot_path(@package.name, screenshot.id) diff --git a/bin/get-data-from-old-live-server.sh b/bin/get-data-from-old-live-server.sh index 530fc5f..b01291d 100755 --- a/bin/get-data-from-old-live-server.sh +++ b/bin/get-data-from-old-live-server.sh @@ -1,9 +1,10 @@ #!/bin/sh -ex -IMAGE_DEST=public/screenshots +#IMAGE_DEST=../public +IMAGE_DEST=public #IMAGE_DEST=/local/screenshots -DB_HOST=localhost -#DB_HOST=torf +#DB_HOST=localhost +DB_HOST=torf echo Getting screenshot files rsync -v root@screenshots.debian.net:/home/debshots/debshots-screenshots.tar /tmp @@ -30,8 +31,9 @@ psql -h $DB_HOST debshots_test debshots < /tmp/debshots.sql echo Unpacking screenshots tarball #cd ../public -cd $IMAGE_DEST -tar xf /tmp/debshots-screenshots.tar +#cd $IMAGE_DEST +tar -C $IMAGE_DEST -xf /tmp/debshots-screenshots.tar #mv public/live/screenshots/approved public/screenshots #rm -r public/live +ln -fs public/live/screenshots/approved public/screenshots diff --git a/config/database.yml b/config/database.yml index 4bae6fd..05531f3 100644 --- a/config/database.yml +++ b/config/database.yml @@ -7,8 +7,8 @@ development: adapter: postgresql database: debshots_dev username: debshots - password: GonwannEn0 - host: localhost + password: shootme + host: torf pool: 5 timeout: 5000 @@ -19,8 +19,8 @@ test: adapter: postgresql database: debshots_test username: debshots - password: GonwannEn0 - host: localhost + password: shootme + host: torf pool: 5 timeout: 5000 diff --git a/config/environments/development.rb b/config/environments/development.rb index f8dc4db..3711fcf 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -30,10 +30,6 @@ Debshots::Application.configure do # ActiveRecord errors propagate normally (forward deprecation to Rails 5) config.active_record.raise_in_transactional_callbacks = true - - # URL prefix leading to the static images that should get delivered by the web server - config.images_path_prefix = '/screenshots' - # DEB package repositories to parse when running "rake debshots:... tasks" config.package_sources = [ { diff --git a/config/routes.rb b/config/routes.rb index f9c2c2d..2ac291c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,13 +13,13 @@ Debshots::Application.routes.draw do get 'packages' => 'packages#grid', as: :packages_grid get 'packages/list' => 'packages#list', as: :packages_list - get 'package/:name' => 'packages#details', as: :package + get 'package/:name' => 'packages#details', as: :package, name: /[^\/]+/ get 'upload', to: redirect('/packages') get 'upload/:name' => 'packages#upload', as: :upload_package_by_name - post 'upload_image/:name' => 'packages#upload_image', as: :upload_image + post 'upload_image/:name' => 'packages#upload_image', as: :upload_image, name: /[^\/]+/ get 'delete_screenshot/:name/:id' => 'packages#delete_screenshot', as: :delete_screenshot get 'about' => 'welcome#about' - get 'thumbnail/:name' => 'packages#thumbnail', as: :thumbnail_image + get 'thumbnail/:name' => 'packages#thumbnail', as: :thumbnail_image, name: /[^\/]+/ # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes".