41void add_cors_headers(crow::response& res,
const rest_server_context& ctx) {
114 std::shared_ptr<rest_server_context> ctx) {
116 if (ctx->database !=
nullptr && g_thumbnail_service ==
nullptr) {
117 g_thumbnail_service =
118 std::make_shared<thumbnail_service>(ctx->database);
122 CROW_ROUTE(app,
"/api/v1/thumbnails/instances/<string>")
123 .methods(crow::HTTPMethod::GET)(
124 [ctx](
const crow::request& req,
const std::string& sop_uid) {
126 add_cors_headers(res, *ctx);
128 if (g_thumbnail_service ==
nullptr) {
130 res.add_header(
"Content-Type",
"application/json");
132 "Thumbnail service not configured");
136 auto params = parse_thumbnail_params(req);
137 auto result = g_thumbnail_service->get_thumbnail(sop_uid, params);
139 if (!result.success) {
141 res.add_header(
"Content-Type",
"application/json");
148 res.add_header(
"Content-Type", result.entry.content_type);
149 res.add_header(
"Cache-Control",
"max-age=3600");
150 res.body = std::string(
151 reinterpret_cast<const char*
>(result.entry.data.data()),
152 result.entry.data.size());
157 CROW_ROUTE(app,
"/api/v1/thumbnails/series/<string>")
158 .methods(crow::HTTPMethod::GET)(
159 [ctx](
const crow::request& req,
const std::string& series_uid) {
161 add_cors_headers(res, *ctx);
163 if (g_thumbnail_service ==
nullptr) {
165 res.add_header(
"Content-Type",
"application/json");
167 "Thumbnail service not configured");
171 auto params = parse_thumbnail_params(req);
173 g_thumbnail_service->get_series_thumbnail(series_uid, params);
175 if (!result.success) {
177 res.add_header(
"Content-Type",
"application/json");
184 res.add_header(
"Content-Type", result.entry.content_type);
185 res.add_header(
"Cache-Control",
"max-age=3600");
186 res.body = std::string(
187 reinterpret_cast<const char*
>(result.entry.data.data()),
188 result.entry.data.size());
193 CROW_ROUTE(app,
"/api/v1/thumbnails/studies/<string>")
194 .methods(crow::HTTPMethod::GET)(
195 [ctx](
const crow::request& req,
const std::string& study_uid) {
197 add_cors_headers(res, *ctx);
199 if (g_thumbnail_service ==
nullptr) {
201 res.add_header(
"Content-Type",
"application/json");
203 "Thumbnail service not configured");
207 auto params = parse_thumbnail_params(req);
209 g_thumbnail_service->get_study_thumbnail(study_uid, params);
211 if (!result.success) {
213 res.add_header(
"Content-Type",
"application/json");
220 res.add_header(
"Content-Type", result.entry.content_type);
221 res.add_header(
"Cache-Control",
"max-age=3600");
222 res.body = std::string(
223 reinterpret_cast<const char*
>(result.entry.data.data()),
224 result.entry.data.size());
229 CROW_ROUTE(app,
"/api/v1/thumbnails/cache")
230 .methods(crow::HTTPMethod::DELETE)([ctx](
const crow::request& ) {
232 res.add_header(
"Content-Type",
"application/json");
233 add_cors_headers(res, *ctx);
235 if (g_thumbnail_service ==
nullptr) {
238 "Thumbnail service not configured");
242 g_thumbnail_service->clear_cache();
250 CROW_ROUTE(app,
"/api/v1/thumbnails/cache/stats")
251 .methods(crow::HTTPMethod::GET)([ctx](
const crow::request& ) {
253 res.add_header(
"Content-Type",
"application/json");
254 add_cors_headers(res, *ctx);
256 if (g_thumbnail_service ==
nullptr) {
259 "Thumbnail service not configured");
263 std::ostringstream oss;
264 oss << R
"({"cache_size":)" << g_thumbnail_service->cache_size()
265 << R"(,"entry_count":)" << g_thumbnail_service->cache_entry_count()
266 << R"(,"max_size":)" << g_thumbnail_service->max_cache_size()
270 res.body = oss.str();