-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.rb
More file actions
51 lines (43 loc) · 1.12 KB
/
Copy pathweb.rb
File metadata and controls
51 lines (43 loc) · 1.12 KB
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
require 'sinatra'
require 'mongo_mapper'
require 'octokit'
require 'video_info'
require_relative 'models'
get "/" do
@links = Link.where(:isPhoto => false, :isGithubRepo => false, :isVideo => false).sort(:datePosted.desc)
erb :index
end
get '/last' do
@last_link = Link.last(:order => :datePosted.desc).url
erb :last
end
get '/user/:user' do
username = params[:user]
@links = Link.where(:submitter => username).sort(:datePosted.desc)
erb :user
end
get '/photos' do
@links = Link.where(:isPhoto => true).sort(:datePosted.desc)
erb :photos
end
get '/photo/:id' do |id|
link = Link.where(:id => id).first()
photo = link.photo
[200, {'Content-Type' => photo.content_type}, [photo.read]]
end
get '/repos' do
links = Link.where(:isGithubRepo => true).sort(:datePosted.desc)
@repos = []
for repo in links
@repos << Octokit.repo(repo.url.split('/', 4).last)
end
erb :repos
end
get '/videos' do
links = Link.where(:isVideo => true).sort(:datePosted.desc)
@videos = []
for video in links
@videos << VideoInfo.get(video.url)
end
erb :videos
end