forked from s3krit/file0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
61 lines (54 loc) · 1.87 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true
# File0 - A temporary image hosting app written in Ruby
# Copyright (C) 2017-2020 Martin Pugh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require 'rubygems'
require 'bundler'
require 'securerandom'
require 'base64'
require 'json'
require 'pry'
require 'mini_magick'
require 'filesize'
require 'sinatra/cookies'
Bundler.require
Dir['./app/*.rb'].sort.each { |f| require f }
Dir['./app/routes/*.rb'].sort.each { |f| require f }
Dir['./app/models/*.rb'].sort.each { |f| require f }
module File0
# Main app class
class App < Sinatra::Base
helpers Sinatra::Cookies
set :views, ::File.dirname(__FILE__) + '/app/views'
set :public_folder, ::File.dirname(__FILE__) + '/app/public'
redis_host = ENV['FILE0_REDIS_URL'] || 'localhost'
redis = Redis.new(host: redis_host)
# Probably not the best thing to use 2 connections just for namespacing...
set :file_redis, Redis::Namespace.new(:file, redis: redis)
set :album_redis, Redis::Namespace.new(:album, redis: redis)
attr_accessor :file_redis
attr_accessor :album_redis
not_found do
status 404
@lifetime = Config.lifetime
@pagetype = :fourohfour
return erb :base
end
configure do
use Routes::Gets
use Routes::Posts
end
end
end