GetFileAccessTokenAction.class.php 1.0 KB

12345678910111213141516171819202122232425
  1. <?php
  2. class GetFileAccessTokenAction implements IAction {
  3. public function execute() {
  4. if(!Authorize::isLoggedIn()) {
  5. return array("error" => "Access not authorized");
  6. }
  7. $database = SqliteDatabase::getSingleton();
  8. $clientId = $_SESSION['client_id'];
  9. $projectId = isset($_POST['project_id']) ? $_POST['project_id'] : $_GET['project_id'];
  10. $projects = $database->queryArray("SELECT rowid AS project_id, * FROM projects WHERE project_id IN (SELECT project_id FROM account_projects WHERE account_id = ".$clientId." AND project_id = ".$projectId .") LIMIT 1;");
  11. $project = $projects[0];
  12. $awsOauth = new AWSOAuth();
  13. $filename = isset($_POST['filename']) ? $_POST['filename']: $_GET['filename'];
  14. $url = "https://".BUCKET_PREFIX . $project['bucket'].".s3.amazonaws.com/" . $project['folder'] . $filename;
  15. $params = $awsOauth->getFileSecureParams(BUCKET_PREFIX . $project['bucket'], $project['folder'] . $filename);
  16. return array("url" => $url,
  17. "params" => $params,
  18. "full" => $url . "?" . $params);
  19. }
  20. }