fix caching again and let / show 11.1
[opensuse:software-o-o.git] / app / controllers / main_controller.rb
1 require 'net/http'
2 require 'gettext_rails'
3
4 class MainController < ApplicationController
5
6   verify :only => :ymp, :params => [:project, :repository, :arch, :binary],
7     :redirect_to => :index
8
9   # these pages are completely static:
10   caches_page :release, :download_js
11
12   def ymp_with_arch_and_version
13     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:arch]}/#{params[:binary]}?view=ymp"
14     res = get_from_api(path)
15     render :text => res.body, :content_type => res.content_type
16   end
17
18   def ymp_without_arch_and_version
19     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:package]}?view=ymp"
20     res = get_from_api(path)
21     render :text => res.body, :content_type => res.content_type
22   end
23
24   def set_release(release)
25     if release == "111"
26        @isos = {}
27        @directory = "http://download.opensuse.org/distribution/11.1"
28        @isos["lang-32"] = "11.1-Addon-Lang-i586"
29        @isos["lang-64"] = "11.1-Addon-Lang-x86_64"
30        @isos["nonoss"] = "11.1-Addon-NonOss-BiArch-i586-x86_64"
31        @isos["kde-64"] = "11.1-KDE4-LiveCD-x86_64"
32        @isos["kde-32"] = "11.1-KDE4-LiveCD-i686"
33        @isos["gnome-64"] = "11.1-GNOME-LiveCD-x86_64"
34        @isos["gnome-32"] = "11.1-GNOME-LiveCD-i686"
35        @isos["dvd-64"] = "11.1-DVD-x86_64"
36        @isos["dvd-32"] = "11.1-DVD-i586"
37        @isos["net-32"] = "11.1-NET-i586"
38        @isos["net-64"] = "11.1-NET-x86_64"
39
40        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.1/RELEASE-NOTES.en.html"
41        @releasename = "openSUSE 11.1"
42        @repourl = "http://download.opensuse.org/distribution/11.1"
43        @medium = "dvd"
44     elsif release == "112"
45        @isos = {}
46        @directory = "http://download.opensuse.org/distribution/11.2"
47        @isos["lang-32"] = "11.2-Addon-Lang-i586"
48        @isos["lang-64"] = "11.2-Addon-Lang-x86_64"
49        @isos["nonoss"] = "11.2-Addon-NonOss-BiArch-i586-x86_64"
50        @isos["kde-64"] = "11.2-KDE4-LiveCD-x86_64"
51        @isos["kde-32"] = "11.2-KDE4-LiveCD-i686"
52        @isos["gnome-64"] = "11.2-GNOME-LiveCD-x86_64"
53        @isos["gnome-32"] = "11.2-GNOME-LiveCD-i686"
54        @isos["dvd-64"] = "11.2-DVD-x86_64"
55        @isos["dvd-32"] = "11.2-DVD-i586"
56        @isos["net-32"] = "11.2-NET-i586"
57        @isos["net-64"] = "11.2-NET-x86_64"
58
59        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.2/RELEASE-NOTES.en.html"
60        @releasename = "openSUSE 11.2"
61        @repourl = "http://download.opensuse.org/distribution/11.2"
62        @medium = "dvd"
63     elsif release == "developer"
64        @isos = {}
65        @directory = "http://download.opensuse.org/distribution/11.2-RC2"
66        @isos["lang-32"] = "Addon-Lang-Build0339-i586"
67        @isos["lang-64"] = "Addon-Lang-Build0339-x86_64"
68        @isos["nonoss"] = "Addon-NonOss-BiArch-Build0339-i586-x86_64"
69        @isos["kde-64"] = "KDE4-LiveCD-Build0339-x86_64"
70        @isos["kde-32"] = "KDE4-LiveCD-Build0339-i686"
71        @isos["gnome-64"] = "GNOME-LiveCD-Build0339-x86_64"
72        @isos["gnome-32"] = "GNOME-LiveCD-Build0339-i686"
73        @isos["dvd-64"] = "DVD-Build0339-x86_64"
74        @isos["dvd-32"] = "DVD-Build0339-i586"
75        @isos["net-32"] = "NET-Build0339-i586"
76        @isos["net-64"] = "NET-Build0339-x86_64"
77
78        @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.2/RELEASE-NOTES.en.html"
79        @releasename = "openSUSE 11.2-RC2"
80        @repourl = "http://download.opensuse.org/distribution/11.2"
81        @medium = "dvd"
82     end
83     @release = release
84   end
85
86   def developer
87     if params[:lang].nil?
88       lang = request.compatible_language_from(LANGUAGES) || "en"
89     else
90       lang = params[:lang][0]
91     end
92     redirect_to "/developer/" + lang
93   end
94    
95   def index
96     #GetText.locale = "en"
97     #render :template => "main/index"
98     #return
99
100     if params[:lang].nil?
101       lang = request.compatible_language_from(LANGUAGES) || "en"
102     else
103       lang = params[:lang][0]
104     end
105     redirect_to "/111/" + lang
106   end
107
108   def release
109     @lang = params[:lang][0]
110     GetText.locale = @lang
111
112     set_release(params[:release])
113     render :template => "main/release"
114   end
115
116   def change_install
117     set_release(params[:release])
118     @medium = params[:medium]
119     render :template => "main/release"
120   end
121
122   def download_js
123     set_release(params[:release])
124     render :template => "main/download", :content_type => 'text/javascript', :layout => false
125   end
126
127   def download
128     set_release(params[:release])
129     medium = params[:medium]
130
131     if params[:arch] == "i686"
132       medium += "-32"
133     else
134       medium += "-64"
135     end
136
137     suffix = ".iso"
138     
139     case
140     when params[:protocol] == "torrent"
141       if params[:medium] != "net"
142           suffix = ".iso.torrent"
143       end
144     when params[:protocol] == "mirror"
145       suffix = ".iso?mirrorlist"
146     when params[:protocol] == "metalink"
147       suffix = ".iso.metalink"
148     end
149     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
150
151   end
152
153   private
154   
155   def get_from_api(path)
156     req = Net::HTTP::Get.new(path)
157     req['x-username'] = "obs_read_only"
158
159     host, port = API_HOST.split(/:/)
160     port ||= 80
161     res = Net::HTTP.new(host, port).start do |http|
162       http.request(req)
163     end
164   end
165 end