asset.cgi 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Carp;
  4. use MyCGI;
  5. use OpenSim::Config;
  6. use OpenSim::Utility;
  7. use OpenSim::AssetServer;
  8. # !!
  9. # TODO: ERROR code
  10. #
  11. my $param = &MyCGI::getParam();
  12. my $response = "<ERROR />";
  13. if ($ENV{REQUEST_METHOD} eq "POST") {
  14. my $request = $param->{'POSTDATA'};
  15. #&OpenSim::Utility::Log("asset", "request", $ENV{REQUEST_URI}, $request);
  16. $response = &OpenSim::AssetServer::saveAsset($request);
  17. } else { # get
  18. eval {
  19. my $rest_param = &getRestParam();
  20. #&OpenSim::Utility::Log("asset", "request", $ENV{REQUEST_URI});
  21. my $rest_param_count = @$rest_param;
  22. if ($rest_param_count < 2) {
  23. Carp::croak($OpenSim::Config::SYS_MSG{FATAL});
  24. }
  25. $response = &OpenSim::AssetServer::getAsset($rest_param->[$#$rest_param], $param);
  26. };
  27. if ($@) {
  28. $response = "<ERROR>$@</ERROR>"; # TODO: better return message needed.
  29. }
  30. }
  31. #&OpenSim::Utility::Log("asset", "response", $response);
  32. &MyCGI::outputXml("utf-8", $response);
  33. sub getRestParam {
  34. my $uri = $ENV{REQUEST_URI} || Carp::croak($OpenSim::Config::SYS_MSG{FATAL});
  35. my ($request_uri, undef) = split(/\?/, $uri);
  36. $request_uri =~ s/\/$//;
  37. my @param = split(/\//, $request_uri);
  38. return \@param;
  39. }