diff --git a/src/Client.php b/src/Client.php index 33af158..b15c26a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -307,6 +307,10 @@ public function listFiles(array $options) */ public function getFile(array $options) { + if (!isset($options['FileId']) && isset($options['BucketName']) && isset($options['FileName'])) { + $options['FileId'] = $this->getFileIdFromBucketAndFileName($options['BucketName'], $options['FileName']); + } + $response = $this->client->request('POST', $this->apiUrl.'/b2_get_file_info', [ 'headers' => [ 'Authorization' => $this->authToken @@ -338,7 +342,7 @@ public function deleteFile(array $options) if (!isset($options['FileName'])) { $file = $this->getFile($options); - $options['FileName'] = $file->getPath(); + $options['FileName'] = $file->getName(); } $this->client->request('POST', $this->apiUrl.'/b2_delete_file_version', [ @@ -407,4 +411,19 @@ protected function getBucketNameFromId($id) return null; } + + protected function getFileIdFromBucketAndFileName($bucketName, $fileName) + { + $files = $this->listFiles([ + 'BucketName' => $bucketName + ]); + + foreach ($files as $file) { + if ($file->getName() === $fileName) { + return $file->getId(); + } + } + + return null; + } } \ No newline at end of file diff --git a/src/File.php b/src/File.php index fdb0799..ecdb165 100644 --- a/src/File.php +++ b/src/File.php @@ -5,9 +5,7 @@ class File { protected $id; - - // TODO: I reckon path should be name instead, to keep it consistent with B2's terminology. - protected $path; + protected $name; protected $hash; protected $size; protected $type; @@ -17,16 +15,16 @@ class File * File constructor. * * @param $id - * @param $path + * @param $name * @param $hash * @param $size * @param $type * @param $info */ - public function __construct($id, $path, $hash = null, $size = null, $type = null, $info = null) + public function __construct($id, $name, $hash = null, $size = null, $type = null, $info = null) { $this->id = $id; - $this->path = $path; + $this->name = $name; $this->hash = $hash; $this->size = $size; $this->type = $type; @@ -44,9 +42,9 @@ public function getId() /** * @return string */ - public function getPath() + public function getName() { - return $this->path; + return $this->name; } /**