PutFileAccessTokenAction.class.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. class PutFileAccessTokenAction implements IAction {
  3. public function execute() {
  4. if(!Authorize::isLoggedIn()) {
  5. return array("error" => "Access not authorized");
  6. }
  7. $projectId = $_POST['project_id'] ?? $_GET['project_id'];
  8. $filePath = $_POST['filePath'] ?? $_GET['filePath'];
  9. $fileType = $_POST['fileType'] ?? $_GET['fileType'];
  10. $isResume = ($_POST['resume'] ?? $_GET['resume'] ?? false) == "true";
  11. $database = SqliteDatabase::getSingleton();
  12. $projects = $database->queryArray("SELECT rowid AS project_id, * FROM projects WHERE project_id = ".$projectId .";");
  13. $project = $projects[0];
  14. $bucket = $project['bucket'];
  15. $folder = $project['folder'];
  16. $folderTree = explode("/", $filePath);
  17. array_shift($folderTree);
  18. $filePath = implode("/", $folderTree);
  19. $awsOauth = new AWSOAuth();
  20. $region = BucketGetRegion::get($bucket);
  21. $uploadAuthData = $awsOauth->putFileSecureParams($bucket, $region, "/" . $folder. "/". $filePath);
  22. $uploadAuthData['status'] = 1;
  23. $uploadAuthData['headers']['content-type'] = $fileType;
  24. unset($uploadAuthData['canonical_request']);
  25. unset($uploadAuthData['string_to_sign']);
  26. unset($uploadAuthData['signature']);
  27. return $uploadAuthData;
  28. }
  29. }