Skip to content

Commit 4950edc

Browse files
authored
Attempt to restore legacy server (#575)
* Fix legacy server for local instances Previously, trying to create a local instance was causing this error: `Uncaught exception - /var/www/html/legacy/haxelib.db does not exist.` The db file and tables are now created automatically if they don't already exist. * Fix legacy link on homepage * Do not expose email address in legacy server See #570 * [legacy] Drop tables in separate function Just in case... * [legacy] Rename function
1 parent 4e4b034 commit 4950edc

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/legacyhaxelib/Site.hx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,15 @@ class Site {
3636
public static var TMP_DIR = CWD+"../tmp";
3737
public static var REP_DIR = CWD+"../"+Data.REPOSITORY;
3838

39-
static function setup() {
40-
SiteDb.create(db);
41-
}
42-
4339
static function initDatabase() {
44-
var path = "legacy/haxelib.db";
45-
FileStorage.instance.readFile(path, function(file) {
46-
if (Path.normalize(DB_FILE) != Path.normalize(file))
47-
throw '$file should be the same as $DB_FILE';
48-
db = neko.db.Sqlite.open(DB_FILE);
49-
neko.db.Manager.cnx = db;
50-
neko.db.Manager.initialize();
51-
});
40+
var alreadyExists = sys.FileSystem.exists(DB_FILE);
41+
db = neko.db.Sqlite.open(DB_FILE);
42+
neko.db.Manager.cnx = db;
43+
neko.db.Manager.initialize();
44+
45+
if (!alreadyExists) {
46+
SiteDb.create(db);
47+
}
5248
}
5349

5450
static function run() {
@@ -62,7 +58,8 @@ class Site {
6258
if( haxe.remoting.HttpConnection.handleRequest(ctx) )
6359
return;
6460
if( Sys.args()[0] == "setup" ) {
65-
setup();
61+
SiteDb.dropAll(db);
62+
SiteDb.create(db);
6663
neko.Lib.print("Setup done\n");
6764
return;
6865
}
@@ -111,7 +108,7 @@ class Site {
111108
act = uri.shift();
112109
ctx.basehref = domain + "/legacy/";
113110
}
114-
else
111+
else
115112
ctx.basehref = domain + "/";
116113
if( act == null || act == "" || act == "index.n" )
117114
act = "index";

src/legacyhaxelib/SiteApi.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SiteApi {
6868
return {
6969
name : u.name,
7070
fullname : u.fullname,
71-
email : u.email,
71+
email : "(private)",
7272
projects : projects,
7373
};
7474
}

src/legacyhaxelib/SiteDb.hx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,16 @@ class TagManager extends neko.db.Manager<Tag> {
141141

142142
class SiteDb {
143143

144-
public static function create( db : sys.db.Connection ) {
144+
public static function dropAll( db : sys.db.Connection ) {
145145
db.request("DROP TABLE IF EXISTS User");
146+
db.request("DROP TABLE IF EXISTS Project");
147+
db.request("DROP TABLE IF EXISTS Version");
148+
db.request("DROP TABLE IF EXISTS Developer");
149+
db.request("DROP TABLE IF EXISTS Tag");
150+
db.request("DROP INDEX IF EXISTS TagSearch");
151+
}
152+
153+
public static function create( db : sys.db.Connection ) {
146154
db.request("
147155
CREATE TABLE User (
148156
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@@ -152,7 +160,6 @@ class SiteDb {
152160
email VARCHAR(50) NOT NULL
153161
)
154162
");
155-
db.request("DROP TABLE IF EXISTS Project");
156163
db.request("
157164
CREATE TABLE Project (
158165
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@@ -165,7 +172,6 @@ class SiteDb {
165172
downloads INT NOT NULL
166173
)
167174
");
168-
db.request("DROP TABLE IF EXISTS Version");
169175
db.request("
170176
CREATE TABLE Version (
171177
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@@ -177,22 +183,19 @@ class SiteDb {
177183
documentation TEXT NULL
178184
)
179185
");
180-
db.request("DROP TABLE IF EXISTS Developer");
181186
db.request("
182187
CREATE TABLE Developer (
183188
user INTEGER NOT NULL,
184189
project INTEGER NOT NULL
185190
)
186191
");
187-
db.request("DROP TABLE IF EXISTS Tag");
188192
db.request("
189193
CREATE TABLE Tag (
190194
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
191195
tag VARCHAR(32) NOT NULL,
192196
project INTEGER NOT NULL
193197
)
194198
");
195-
db.request("DROP INDEX IF EXISTS TagSearch");
196199
db.request("CREATE INDEX TagSearch ON Tag(tag)");
197200
}
198201
}

www/view/layout.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.css" rel="stylesheet">
1010
<link href="/css/style.css" rel="stylesheet">
1111
<link href="/css/haxe-nav.css" rel="stylesheet">
12-
12+
1313
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
1414
<link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:200,600,600italic,400" rel="stylesheet">
1515
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,700,700italic,400italic" rel="stylesheet">
@@ -68,10 +68,10 @@
6868
}
6969
<li class="divider"></li>
7070
<li><a href="/rss/"><i class="fa fa-rss"></i> Recent Updates RSS Feed</a></li>
71-
<li><a href="//lib.haxe.org/legacy/"><i class="fa fa-folder-open-o"></i> Haxe 2 Haxelib repository</a></li>
71+
<li><a href="/legacy/"><i class="fa fa-folder-open-o"></i> Haxe 2 Haxelib repository</a></li>
7272
</ul>
7373
</li>
74-
74+
7575
<li class=" divider"></li>
7676
<li class="dropdown">
7777
<a class="dropdown-toggle" data-toggle="dropdown" href="https://haxe.org/documentation/">Learn Haxe <b class="caret"></b></a>
@@ -126,7 +126,7 @@
126126

127127
<div class="section info">
128128
<div class="container">
129-
129+
130130
<div class="row">
131131
<div class="span4">
132132
<h3><i class="fa fa-big fa-rocket"></i> All libraries are free</h3>
@@ -155,7 +155,7 @@ <h3><i class="fa fa-big fa-globe"></i> Join us on GitHub!</h3>
155155
<div class="container">
156156
<div class="copyright">
157157
<p>&copy;@todaysDate.getFullYear()
158-
<a href="//haxe.org/foundation/" title="Haxe Foundation Website" class="hf-link">Haxe Foundation</a> |
158+
<a href="//haxe.org/foundation/" title="Haxe Foundation Website" class="hf-link">Haxe Foundation</a> |
159159
<a href="https://github.com/HaxeFoundation/haxelib" title="Haxelib GitHub Repository" class="hf-link">Haxelib on GitHub</a>
160160
</p>
161161
</div>

0 commit comments

Comments
 (0)