diff --git a/index.html b/index.html
index c2b8bf2..d97c753 100644
--- a/index.html
+++ b/index.html
@@ -28,6 +28,8 @@
The maximum words to include. Default 100.
include
Columns to include, comma separated list. Default: id, solution, print_date, days_since_launch, editor. Additional: access_count. When only one column is included the json will be a flat array, no objects.
+ mode
+ When set to 'mod.json', all other variables will be ignored and it will return a full mod.json file.
Share
diff --git a/words.php b/words.php
index 9db0d76..180648e 100644
--- a/words.php
+++ b/words.php
@@ -72,7 +72,7 @@ function get_words($date, $limit, $include) {
if(pg_num_rows($res) == 0) {
return [
'status' => 'ERROR',
- 'message' => 'Date too late'
+ 'message' => 'Already up to date'
];
}
@@ -110,7 +110,7 @@ function add_words($datestamp) {
// Add word to database
$query = 'INSERT INTO words (id, solution, print_date, days_since_launch, editor) ' .
- 'VALUES ($1, $2, $3, $4, $5)';
+ 'VALUES ($1, UPPER($2), $3, $4, $5)';
$params = [
$word['id'],
$word['solution'],
@@ -135,34 +135,6 @@ function add_words($datestamp) {
$dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD")
or die('Could not connect: ' . pg_last_error());
-// Check get vars
-$date = $_GET['date'];
-$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 100;
-$include = isset($_GET['include']) ? $_GET['include'] : 'id,solution,print_date,days_since_launch,editor';
-
-if(!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
- die(json_encode([
- 'status' => 'ERROR',
- 'message' => 'Invalid date format (YYYY-MM-DD)'
- ]));
-} else if($date < '2021-06-19') {
- die(json_encode([
- 'status' => 'ERROR',
- 'message' => 'Date too early'
- ]));
-} else if($limit <= 0) {
- die(json_encode([
- 'status' => 'ERROR',
- 'message' => 'Invalid limit'
- ]));
-} else if(!preg_match('/^[a-z,_]+$/', $include)) {
- die(json_encode([
- 'status' => 'ERROR',
- 'message' => 'Invalid include'
- ]));
-}
-
-
// Check for words once a day
$res = pg_query('SELECT EXTRACT(EPOCH FROM time) AS time FROM update') or die('Query failed: ' . pg_last_error());
$cur_time = time();
@@ -175,6 +147,42 @@ if($cur_time > $last_time + (60 * 60 * 24)) {
}
// Get words
-echo json_encode(get_words($date, $limit, $include));
+if($_GET['mode'] == 'mod.json') {
+ header('Content-Disposition: attachment; filename="mod.json"');
+ echo json_encode([
+ 'words' => [
+ 'order' => get_words('2021-06-19', 100000, 'id')
+ ]
+ ]);
+} else {
+ // Check get vars
+ $date = $_GET['date'];
+ $limit = isset($_GET['limit']) ? intval($_GET['limit']) : 100;
+ $include = isset($_GET['include']) ? $_GET['include'] : 'id,solution,print_date,days_since_launch,editor';
+
+ if(!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
+ die(json_encode([
+ 'status' => 'ERROR',
+ 'message' => 'Invalid date format (YYYY-MM-DD)'
+ ]));
+ } else if($date < '2021-06-19') {
+ die(json_encode([
+ 'status' => 'ERROR',
+ 'message' => 'Date too early'
+ ]));
+ } else if($limit <= 0) {
+ die(json_encode([
+ 'status' => 'ERROR',
+ 'message' => 'Invalid limit'
+ ]));
+ } else if(!preg_match('/^[a-z,_]+$/', $include)) {
+ die(json_encode([
+ 'status' => 'ERROR',
+ 'message' => 'Invalid include'
+ ]));
+ }
+
+ echo json_encode(get_words($date, $limit, $include));
+}
pg_close($dbc);