namespace Friendica\Model\Storage;
-use \BadMethodCallException;
-use Friendica\DI;
+use Exception;
+use Friendica\Util\HTTPSignature;
/**
* External resource storage class
/**
* @inheritDoc
*/
- public function get(string $filename)
+ public function get(string $reference): string
{
- $parts = parse_url($filename);
+ $data = json_decode($reference);
+ if (empty($data->url)) {
+ throw new ReferenceStorageException(sprintf('Invalid reference %s, cannot retrieve URL', $reference));
+ }
+
+ $parts = parse_url($data->url);
if (empty($parts['scheme']) || empty($parts['host'])) {
- return "";
+ throw new ReferenceStorageException(sprintf('Invalid reference %s, cannot extract scheme and host', $reference));
}
- $curlResult = DI::httpRequest()->get($filename);
- if ($curlResult->isSuccess()) {
- return $curlResult->getBody();
+ try {
+ $fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, ['accept_content' => []]);
+ } catch (Exception $exception) {
+ throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
+ }
+ if ($fetchResult->isSuccess()) {
+ return $fetchResult->getBody();
} else {
- return "";
+ throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBody()));
}
}
- /**
- * @inheritDoc
- */
- public function put(string $data, string $filename = '')
- {
- throw new BadMethodCallException();
- }
-
- public function delete(string $filename)
- {
- throw new BadMethodCallException();
- }
-
- /**
- * @inheritDoc
- */
- public function getOptions()
- {
- return [];
- }
-
- /**
- * @inheritDoc
- */
- public function saveOptions(array $data)
- {
- return [];
- }
-
/**
* @inheritDoc
*/
/**
* @inheritDoc
*/
- public static function getName()
+ public static function getName(): string
{
return self::NAME;
}