Skip to content

Instantly share code, notes, and snippets.

@TrueBrain
Last active September 18, 2020 21:18
Show Gist options
  • Save TrueBrain/454c07fe4cb36a67340b7cc6fc2f496d to your computer and use it in GitHub Desktop.
Save TrueBrain/454c07fe4cb36a67340b7cc6fc2f496d to your computer and use it in GitHub Desktop.
grfsearch.openttd.org
'use strict';
const querystring = require('querystring');
exports.handler = (event, context, callback) => {
var request = event.Records[0].cf.request;
const params = querystring.parse(request.querystring);
var redirect_uri = '/index.php';
if (params.q) {
var redirect_params;
if (params.do == 'searchtext') {
redirect_params = {
do: 'search',
q: params.q,
};
}
if (params.do == 'searchgrfid') {
redirect_params = {
do: 'search',
type: 'grfidlist',
/* grfcrawler does not support md5sum, so remove them from the query */
q: params.q.replace(/:[0-9A-Fa-f]*/g, ''),
};
}
redirect_uri += "?" + querystring.stringify(redirect_params);
}
const response = {
status: '301',
statusDescription: 'Moved Permanently',
headers: {
location: [{
key: 'Location',
value: 'https://grfcrawler.tt-forums.net' + redirect_uri,
}],
},
};
callback(null, response);
return;
};
<?php
$do = '';
$q = '';
if (isset($_GET['do']))
$do = $_GET['do'];
if (isset($_GET['q']))
$q = $_GET['q'];
if ($do == 'searchtext') {
if ($q == '') {
header('Location: http://grfcrawler.tt-forums.net/index.php');
} else {
header('Location: http://grfcrawler.tt-forums.net/index.php?do=search&q='.urlencode($q));
}
} else if ($do == 'searchgrfid') {
/* grfcrawler does not support md5sum, so remove them from the query */
$grfidlist = preg_replace('/:[0-9A-Fa-f]*/', '', $q);
header('Location: http://grfcrawler.tt-forums.net/index.php?do=search&type=grfidlist&q='.urlencode($grfidlist));
} else {
header('Location: http://grfcrawler.tt-forums.net/index.php');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment