Skip to content

Commit

Permalink
Implement 3rd layer single event screenshot and movie making and fetc…
Browse files Browse the repository at this point in the history
…hing prev/next image per source id (#385)

* preflight OPTIONS requests , handled seperately from application

* add new endpoints

* 400 for validation errors in api, also handle json and respond with 400 json

* use production urls for help and api doc messages

* add eventsState columns to screenshot and movies tables

* events manager usage , now using eventsState into the database

* fix bug when fail to open movie frames directory

* new event state implementation

* add autoloader to queue jobs

* eventManager in composite_image handling 3rd level event_instances

* update statistics

* fix index php syntax

* fix statistics for postMovie endpoint

* new functions for testing, makeIdFunction to be used tests, fix some tabs, fix small bug about inconsistent event_states

* events manager tests

* rebuild movies should handle if movie not found

* 404 on not found screenshots

* db function to query prev and next images

* remove code

* add http endpoint to read before and after closest images

* updates for comments, new validation method array_ints and tests for it , fix statistics

* fix bug about ROI for movies and enable requeue tests

* documentation for postMovies and postScreenshots and eventStates strings

* handle markers_visible if it is not there

* prevent and dublication in short labels and labels of HEK Events

* add more comments about old event fields

* remove flv from docs

* Update docs/src/source/api/api_groups/movies/postMovie.rst

* Update docs/src/source/api/api_groups/movies/postMovie.rst

* Update docs/src/source/api/api_groups/movies/postMovie.rst

* Update docs/src/source/appendix/events_state.rst

* Update docs/src/source/appendix/events_state.rst

---------

Co-authored-by: Daniel Garcia Briseno <[email protected]>
  • Loading branch information
mudhoney and dgarciabriseno authored Jun 17, 2024
1 parent a73f755 commit 580224c
Show file tree
Hide file tree
Showing 33 changed files with 2,395 additions and 321 deletions.
9 changes: 4 additions & 5 deletions docroot/docs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
// Script was called directly. Redirect to an API-version specific URL.
if (realpath(__FILE__) == $_SERVER['SCRIPT_FILENAME']) {
require_once dirname(realpath(__FILE__)).'/../../src/Config.php';
$config = new Config(dirname(realpath(__FILE__))
. '/../../settings/Config.ini');
$config = new Config(dirname(realpath(__FILE__)) . '/../../settings/Config.ini');
header('Location: '.HV_WEB_ROOT_URL.'/docs/'.$api_version);
}


function import_xml($api_version, &$api_xml_path, &$xml) {
$api_xml_path = dirname(realpath(__FILE__)) . '/' . $api_version
. '/api_definitions.xml';
$xml = simplexml_load_file($api_xml_path);
$api_xml_url = sprintf("%s/docs/%s/api_definitions.xml", "https://api.helioviewer.org", $api_version);
$xml = simplexml_load_file($api_xml_url);
$api_xml_path = dirname(realpath(__FILE__)) . '/' . $api_version. '/api_definitions.xml';
}

function output_html($api_version) {
Expand Down
164 changes: 97 additions & 67 deletions docroot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
date_default_timezone_set('UTC');
register_shutdown_function('shutdownFunction');

if ( array_key_exists('docs', $_GET) ) {
printAPIDocs();
// Options requests are just for validating CORS
// Lets just pass them through
if ( array_key_exists('REQUEST_METHOD', $_SERVER) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) {
echo 'OK';
exit;
}

Expand All @@ -52,6 +54,7 @@
echo json_encode([
'success' => false,
'message' => $re->getMessage(),
'data' => [],
]);
exit;
}
Expand All @@ -75,68 +78,65 @@
function loadModule($params) {

$valid_actions = array(
'downloadScreenshot' => 'WebClient',
'getClosestImage' => 'WebClient',
'getDataSources' => 'WebClient',
'getJP2Header' => 'WebClient',
'getNewsFeed' => 'WebClient',
'getStatus' => 'WebClient',
'getSciDataScript' => 'WebClient',
'getTile' => 'WebClient',
'downloadImage' => 'WebClient',
'getUsageStatistics' => 'WebClient',
'getDataCoverageTimeline' => 'WebClient',
'getDataCoverage' => 'WebClient',
'updateDataCoverage' => 'WebClient', // Deprecated, remove in V3, replaced by management scripts
'shortenURL' => 'WebClient',
'goto' => 'WebClient',
'saveWebClientState' => 'WebClient',
'getWebClientState' => 'WebClient',
'takeScreenshot' => 'WebClient',
'getRandomSeed' => 'WebClient',
'getJP2Image' => 'JHelioviewer',
'getJPX' => 'JHelioviewer',
'getJPXClosestToMidPoint' => 'JHelioviewer',
'launchJHelioviewer' => 'JHelioviewer',
'downloadMovie' => 'Movies',
'getMovieStatus' => 'Movies',
'playMovie' => 'Movies',
'queueMovie' => 'Movies',
'reQueueMovie' => 'Movies',
'uploadMovieToYouTube' => 'Movies',
'checkYouTubeAuth' => 'Movies',
'getYouTubeAuth' => 'Movies',
'getUserVideos' => 'Movies',
'getObservationDateVideos' => 'Movies',
'events' => 'SolarEvents',
'getEventFRMs' => 'SolarEvents',
'getEvent' => 'SolarEvents',
'getFRMs' => 'SolarEvents',
'getDefaultEventTypes' => 'SolarEvents',
'getEvents' => 'SolarEvents',
'importEvents' => 'SolarEvents', // Deprecated, remove in V3, replaced by management scripts
'getEventsByEventLayers' => 'SolarEvents',
'getEventGlossary' => 'SolarEvents',
'getSolarBodiesGlossary' => 'SolarBodies',
'getSolarBodies' => 'SolarBodies',
'getTrajectoryTime' => 'SolarBodies',
'logNotificationStatistics' => 'WebClient',
'getEclipseImage' => 'WebClient'
'downloadScreenshot' => 'WebClient',
'getClosestImage' => 'WebClient',
'getDataSources' => 'WebClient',
'getJP2Header' => 'WebClient',
'getNewsFeed' => 'WebClient',
'getStatus' => 'WebClient',
'getSciDataScript' => 'WebClient',
'getTile' => 'WebClient',
'downloadImage' => 'WebClient',
'getUsageStatistics' => 'WebClient',
'getDataCoverageTimeline' => 'WebClient',
'getDataCoverage' => 'WebClient',
'updateDataCoverage' => 'WebClient', // Deprecated, remove in V3, replaced by management scripts
'shortenURL' => 'WebClient',
'goto' => 'WebClient',
'saveWebClientState' => 'WebClient',
'getWebClientState' => 'WebClient',
'takeScreenshot' => 'WebClient',
'postScreenshot' => 'WebClient',
'getRandomSeed' => 'WebClient',
'getJP2Image' => 'JHelioviewer',
'getJPX' => 'JHelioviewer',
'getJPXClosestToMidPoint' => 'JHelioviewer',
'launchJHelioviewer' => 'JHelioviewer',
'downloadMovie' => 'Movies',
'getMovieStatus' => 'Movies',
'playMovie' => 'Movies',
'queueMovie' => 'Movies',
'postMovie' => 'Movies',
'reQueueMovie' => 'Movies',
'uploadMovieToYouTube' => 'Movies',
'checkYouTubeAuth' => 'Movies',
'getYouTubeAuth' => 'Movies',
'getUserVideos' => 'Movies',
'getObservationDateVideos' => 'Movies',
'events' => 'SolarEvents',
'getEventFRMs' => 'SolarEvents',
'getEvent' => 'SolarEvents',
'getFRMs' => 'SolarEvents',
'getDefaultEventTypes' => 'SolarEvents',
'getEvents' => 'SolarEvents',
'importEvents' => 'SolarEvents', // Deprecated, remove in V3, replaced by management scripts
'getEventsByEventLayers' => 'SolarEvents',
'getEventGlossary' => 'SolarEvents',
'getSolarBodiesGlossary' => 'SolarBodies',
'getSolarBodies' => 'SolarBodies',
'getTrajectoryTime' => 'SolarBodies',
'logNotificationStatistics' => 'WebClient',
'getEclipseImage' => 'WebClient',
'getClosestImageDatesForSources' => 'WebClient',
);

include_once HV_ROOT_DIR.'/../src/Validation/InputValidator.php';

try {
if ( !array_key_exists('action', $params) ||
!array_key_exists($params['action'], $valid_actions) ) {

$url = HV_WEB_ROOT_URL.'/docs/';
throw new Exception(
'Invalid action specified.<br />Consult the <a href="'.$url.'">' .
'API Documentation</a> for a list of valid actions.', 26
);
}
else {
if ( !array_key_exists($params['action'], $valid_actions) ) {
throw new \InvalidArgumentException('Invalid action specified.<br />Consult the <a href="https://api.helioviewer.org/docs/v2/">API Documentation</a> for a list of valid actions.');
} else {

//Set-up variables for rate-limiting
$prefix = HV_RATE_LIMIT_PREFIX;
//Use IP address as identifier.
Expand Down Expand Up @@ -170,13 +170,19 @@ function loadModule($params) {
$module->execute();

// Update usage stats
$actions_to_keep_stats_for = array('getClosestImage',
'takeScreenshot', 'getJPX', 'getJPXClosestToMidPoint', 'uploadMovieToYouTube', 'getRandomSeed');
$actions_to_keep_stats_for = [
'getClosestImage',
'takeScreenshot',
'postScreenshot',
'getJPX',
'getJPXClosestToMidPoint',
'uploadMovieToYouTube',
'getRandomSeed',
];

// Note that in addition to the above, buildMovie requests and
// addition to getTile when the tile was already in the cache.
if ( HV_ENABLE_STATISTICS_COLLECTION &&
in_array($params['action'], $actions_to_keep_stats_for) ) {
if ( HV_ENABLE_STATISTICS_COLLECTION && in_array($params['action'], $actions_to_keep_stats_for) ) {

include_once HV_ROOT_DIR.'/../src/Database/Statistics.php';
$statistics = new Database_Statistics();
Expand All @@ -198,9 +204,34 @@ function loadModule($params) {
//limit exceeded
}
}
}
catch (Exception $e) {
} catch (\InvalidArgumentException $e) {

// Proper response code
http_response_code(400);

// Determine the content type of the request
$content_type = $_SERVER['CONTENT_TYPE'] ?? '';

// If the request is posting JSON
if('application/json' === $content_type) {

// Set the content type to JSON
header('Content-Type: application/json');

echo json_encode([
'success' => false,
'message' => $e->getMessage(),
'data' => [],
]);
exit;
}

printHTMLErrorMsg($e->getMessage());

} catch (Exception $e) {

printHTMLErrorMsg($e->getMessage());

}

return true;
Expand Down Expand Up @@ -263,8 +294,7 @@ function shutDownFunction() {
$error = error_get_last();

if (!is_null($error) && $error['type'] == 1) {
handleError(sprintf("%s:%d - %s", $error['file'], $error['line'],
$error['message']), $error->getCode());
handleError(sprintf("%s:%d - %s", $error['file'], $error['line'], $error['message']));
}
}
?>
6 changes: 3 additions & 3 deletions docroot/statistics/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ var colors = ["#D32F2F", "#9bd927", "#27d9be", "#6527d9", "#0091EA", "#FF6F00",
var heirarchy = {
"Total":["total","rate_limit_exceeded"],
"Client Sites":["standard","embed","minimal"],
"Images":["takeScreenshot","getTile","getClosestImage","getJP2Image-web","getJP2Image-jpip","getJP2Image","downloadScreenshot","getJPX","getJPXClosestToMidPoint", "downloadImage"],
"Movies":["buildMovie","getMovieStatus","queueMovie","reQueueMovie","playMovie","downloadMovie","getUserVideos","getObservationDateVideos","uploadMovieToYouTube","checkYouTubeAuth","getYouTubeAuth"],
"Images":["takeScreenshot","postScreenshot","getTile","getClosestImage","getJP2Image-web","getJP2Image-jpip","getJP2Image","downloadScreenshot","getJPX","getJPXClosestToMidPoint", "downloadImage"],
"Movies":["buildMovie","getMovieStatus","queueMovie","postMovie","reQueueMovie","playMovie","downloadMovie","getUserVideos","getObservationDateVideos","uploadMovieToYouTube","checkYouTubeAuth","getYouTubeAuth"],
"Events":["getEventGlossary", "events", "getEvents","getFRMs","getEvent","getEventFRMs","getDefaultEventTypes","getEventsByEventLayers","importEvents"],
"Data":["getRandomSeed","getDataSources","getJP2Header","getDataCoverage","getStatus","getNewsFeed","getDataCoverageTimeline","getClosestData","getSolarBodiesGlossary","getSolarBodies","getTrajectoryTime","sciScript-SSWIDL","sciScript-SunPy","getSciDataScript","updateDataCoverage","getEclipseImage"],
"Data":["getRandomSeed","getDataSources","getJP2Header","getDataCoverage","getStatus","getNewsFeed","getDataCoverageTimeline","getClosestData","getSolarBodiesGlossary","getSolarBodies","getTrajectoryTime","sciScript-SSWIDL","sciScript-SunPy","getSciDataScript","updateDataCoverage","getEclipseImage","getClosestImageDatesForSources"],
"Other":["shortenURL", "goto", "getUsageStatistics","movie-notifications-granted","movie-notifications-denied","logNotificationStatistics","launchJHelioviewer", "saveWebClientState", "getWebClientState"],
"WebGL":["getTexture","getGeometryServiceData"]
};
Expand Down
1 change: 1 addition & 0 deletions docs/src/source/api/api_groups/movies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ See the Coordinates Appendix for more infomration about working with the coordin
used by Helioviewer.org.

.. include:: movies/queueMovie.rst
.. include:: movies/postMovie.rst
.. include:: movies/reQueueMovie.rst
.. include:: movies/getMovieStatus.rst
.. include:: movies/downloadMovie.rst
Expand Down
2 changes: 1 addition & 1 deletion docs/src/source/api/api_groups/movies/downloadMovie.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Download a custom movie in one of three file formats.
+===========+==========+=========+=========+==================================================================================================+
| id | Required | string | VXvX5 | Unique movie identifier (provided by the response to a `queueMovie` request). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------------------------+
| format | Required | string | mp4 | Movie Format (`mp4`, `webm`, or `flv`). |
| format | Required | string | mp4 | Movie Format (`mp4`, `webm`). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------------------------+
| hq | Optional | boolean | true | Optionally download a higher-quality movie file (valid for .mp4 movies only, ignored otherwise). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/src/source/api/api_groups/movies/getMovieStatus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GET /v2/getMovieStatus/
+===========+==========+=========+=========+================================================================================+
| id | Required | string | VXvX5 | Unique movie identifier (provided by the response to a `queueMovie` request). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------+
| format | Required | string | mp4 | Movie format (`mp4`, `webm`, or `flv`). |
| format | Required | string | mp4 | Movie format (`mp4`, `webm`). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------+
| verbose | Optional | boolean | true | Optionally include extra metadata in the response. |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/src/source/api/api_groups/movies/playMovie.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Output an HTML web page with the requested movie embedded within.
+===========+==========+=========+=========+==================================================================================================+
| id | Required | string | VXvX5 | Unique movie identifier (provided by the response to a `queueMovie` request). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------------------------+
| format | Required | string | mp4 | Movie format (mp4, webm, or flv). |
| format | Required | string | mp4 | Movie format (mp4, webm). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------------------------+
| hq | Optional | boolean | true | Optionally download a higher-quality movie file (valid for .mp4 movies only, ignored otherwise). |
+-----------+----------+---------+---------+--------------------------------------------------------------------------------------------------+
Expand Down
Loading

0 comments on commit 580224c

Please sign in to comment.