|
26 | 26 |
|
27 | 27 | use Exception; |
28 | 28 | use OC; |
| 29 | +use OCA\Files_External_Ethswarm\Db\SwarmFile; |
29 | 30 | use OCA\Files_External_Ethswarm\Db\SwarmFileMapper; |
30 | 31 | use OCA\Files_External_Ethswarm\Storage\BeeSwarm; |
31 | 32 | use OCP\Files\Storage\IStorage; |
@@ -74,12 +75,12 @@ public function setVisibility(string $fileName, int $storageId, int $visibility) |
74 | 75 | } |
75 | 76 |
|
76 | 77 | public function getToken(string $fileId): string { |
77 | | - $swarmFile = $this->fileMapper->findAll($fileId); |
78 | | - if (0 === count($swarmFile)) { |
| 78 | + $swarmFile = $this->fileMapper->findByFileId($fileId); |
| 79 | + if (!$swarmFile) { |
79 | 80 | throw new StorageNotAvailableException($this->l10n->t('No token found')); |
80 | 81 | } |
81 | 82 |
|
82 | | - return $swarmFile[0]->getToken(); |
| 83 | + return $swarmFile->getToken(); |
83 | 84 | } |
84 | 85 |
|
85 | 86 | public function archiveNode(string $fileName, IStorage $storage): void { |
@@ -147,4 +148,22 @@ public function rename(string $fileName, string $newName, IStorage $storage): vo |
147 | 148 | throw new StorageNotAvailableException($this->l10n->t('Failed to rename')); |
148 | 149 | } |
149 | 150 | } |
| 151 | + |
| 152 | + public function exportReferences(IStorage $storage): array { |
| 153 | + $storageId = $storage->getCache()->getNumericStorageId(); |
| 154 | + $files = $this->fileMapper->findAllByStorageId($storageId); |
| 155 | + |
| 156 | + try { |
| 157 | + return array_map(fn (SwarmFile $file) => [ |
| 158 | + 'path' => $file->getName(), |
| 159 | + 'reference' => $file->getSwarmReference(), |
| 160 | + 'visibility' => $file->getVisibility(), |
| 161 | + 'token' => $file->getToken(), |
| 162 | + 'mimetype' => $file->getMimetype(), |
| 163 | + 'size' => $file->getSize(), |
| 164 | + ], $files); |
| 165 | + } catch (Exception $e) { |
| 166 | + throw new StorageNotAvailableException($this->l10n->t('Failed to export references')); |
| 167 | + } |
| 168 | + } |
150 | 169 | } |
0 commit comments