Skip to content
Browse files

getting counters dir relative __FILE__

  • Loading branch information...
1 parent ff0a6e1 commit 29b887cbcedf2f86682eead0f2c5c8bcdba6a71f @sickill committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 sickounter.rb
View
9 sickounter.rb
@@ -1,10 +1,13 @@
require 'rubygems'
require 'sinatra'
+COUNTERS_DIR = File.join(File.dirname(__FILE__), 'counters')
+
get '/' do
url = params[:f] or raise Sinatra::NotFound
filename = url.gsub(/https?:\/\//, "").gsub(/[^a-zA-Z0-9_-]/, ".") + ".txt"
- path = "counters/#{filename}"
+ path = File.join(COUNTERS_DIR, filename)
+ puts path
val = (File.read(path).strip.to_i rescue 0) + 1
File.open(path, "w") do |f|
f.flock(File::LOCK_EX)
@@ -16,8 +19,8 @@
get '/stats' do
@downloads = {}
- Dir["counters/*.txt"].each do |counter|
- @downloads[counter.split("/")[1]] = File.read(counter).strip.to_i
+ Dir[File.join(COUNTERS_DIR, "*.txt")].each do |counter|
+ @downloads[counter.split("/")[-1]] = File.read(counter).strip.to_i
end
erb :stats
end

0 comments on commit 29b887c

Please sign in to comment.
Something went wrong with that request. Please try again.