diff --git a/rails/app/controllers/application_controller.rb b/rails/app/controllers/application_controller.rb index 5b25c37..f711163 100644 --- a/rails/app/controllers/application_controller.rb +++ b/rails/app/controllers/application_controller.rb @@ -1,5 +1,6 @@ class ApplicationController < ActionController::Base protect_from_forgery + require 'beatdb' require 'pp' #require 'cobravsmongoose' end diff --git a/rails/app/helpers/application_helper.rb b/rails/app/helpers/application_helper.rb index de6be79..a5d2739 100644 --- a/rails/app/helpers/application_helper.rb +++ b/rails/app/helpers/application_helper.rb @@ -1,2 +1,15 @@ module ApplicationHelper end + +class Numeric + def toSeconds + (self / 1000).round + end + + def toTime + s = self.toSeconds + m = (s / 60).floor + s -= m * 60 + m.to_s << ':' << (s < 10 ? '0' : '') << s.to_s + end +end \ No newline at end of file diff --git a/rails/app/models/beatdb.rb b/rails/app/models/beatdb.rb new file mode 100644 index 0000000..94102ce --- /dev/null +++ b/rails/app/models/beatdb.rb @@ -0,0 +1,33 @@ +class BeatDB + @@db_root = '/www/beatdb' + + def self.get key + unless self.exists(key) || File.readable?(self.filePathByKey(key)) + return false + end + h = File.open(self.filePathByKey(key), 'r') + JSON.decode(h.readline) + end + + def self.set key, data + unless self.exists(key) || File.writable?(self.filePathByKey(key)) + return false + end + h = File.open(self.filePathByKey(key), 'w') + h.puts(JSON.encode(data)) + end + + def self.delete key + + end + + def self.exists key + File.exists?(self.filePathByKey(key)) + end + + def self.filePathByKey key + path = '' + key.to_s.each_char {|c| path << '/' + c} + @@db_root + path[0..(path.length-2)] << key.to_s + '.json' + end +end \ No newline at end of file diff --git a/rails/app/views/artist/view.rhtml b/rails/app/views/artist/view.rhtml index 7468de4..231b9d0 100644 --- a/rails/app/views/artist/view.rhtml +++ b/rails/app/views/artist/view.rhtml @@ -1,9 +1,9 @@