<?php /* * creates new job */ $app->post('/jobs/:type/:id', function ($type, $chart_id) use($app) { disable_cache($app); if_chart_is_writable($chart_id, function ($user, $chart) use($app, $type) { try { // create a new export job for this chart $params = json_decode($app->request()->getBody(), true); $job = JobQuery::create()->createJob($type, $chart, $user, $params); ok(ceil(JobQuery::create()->estimatedTime($type) / 60)); } catch (Exception $e) { error('io-error', $e->getMessage()); } }); }); /* * returns the estimated time to complete a new print job * in minutes */ $app->get('/jobs/:type/estimate', function ($type) use($app) { disable_cache($app); ok(ceil(JobQuery::create()->estimatedTime($type) / 60)); }); /* * change status of a job, need admin access */ $app->put('/jobs/:id', function ($job_id) use($app) { if_is_admin(function () use($app, $job_id) {
disable_cache($app); if_chart_is_writable($chart_id, function ($user, $chart) use($app) { echo _getPublishStatus($chart); }); }); /* * stores client-side generated chart thumbnail */ $app->put('/charts/:id/thumbnail/:thumb', function ($chart_id, $thumb) use($app) { disable_cache($app); if_chart_is_writable($chart_id, function ($user, $chart) use($app, $thumb) { try { $imgurl = $app->request()->getBody(); $imgdata = base64_decode(substr($imgurl, strpos($imgurl, ",") + 1)); $static_path = get_static_path($chart); file_put_contents($static_path . "/" . $thumb . '.png', $imgdata); DatawrapperHooks::execute(DatawrapperHooks::PUBLISH_FILES, array(array($static_path . "/" . $thumb . '.png', $chart->getID() . '/' . $thumb . '.png', 'image/png'))); ok(); } catch (Exception $e) { error('io-error', $e->getMessage()); } }); }); /* * stores static snapshot of a chart (data, configuration, etc) as JSON * to /test/test-charts. This aims to simplify the generation of test * cases using the Datawrapper editor. Only for debugging. */ $app->post('/charts/:id/store_snapshot', function ($chart_id) use($app) { if (!empty($GLOBALS['dw_config']['debug_export_test_cases'])) { if_chart_exists($chart_id, function ($chart) use($app) { $json = $chart->serialize();