summaryrefslogtreecommitdiff
path: root/site/custom.cpp
blob: 5d955a2e7c824cdd7a930889a7583a59b04a0a4a (plain)
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
#include "icespider-routes-search.h"

namespace MirrorSearch {
	using namespace std::literals;
	// Implementation classes.

	// Route name: download
	//       path: /download/{filename}
	class download : public IceSpider::IRouteHandler {
		public:
			download(const IceSpider::Core * core) :
				IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/download/{filename}"),
				prx0(core->getProxy<MirrorSearch::Search>()),
				_pi_filename(1)
			{
			}

			void execute(IceSpider::IHttpRequest * request) const
			{
				auto _p_filename(request->getURLParam<::std::string>(_pi_filename));
				auto _responseModel = prx0->feelingLucky(_p_filename, request->getContext());
				if (_responseModel) {
					request->responseRedirect(*_responseModel, "Mirror found"s);
				}
				request->response(404, "No mirror found");
			}

		private:
			const MirrorSearch::SearchPrxPtr prx0;
			const unsigned int _pi_filename;
	};

} // namespace MirrorSearch

// Register route handlers.
FACTORY(MirrorSearch::download, IceSpider::RouteHandlerFactory);

// End generated code.