Skip to content

Commit

Permalink
Merge pull request #87 from freimuts/2.x
Browse files Browse the repository at this point in the history
useDisplayPaths/showDisplayPaths

**useDisplayPaths:**
true [default]: human readable path in FileAttributes/DirectoryAttributes path (ignores showDisplayPaths)
false: virtual ID path in FileAttributes/DirectoryAttributes path

**showDisplayPaths:**
true: human readable path in extra metadata display_path
false [default]: virtual ID path in extra metadata display_path
  • Loading branch information
masbug authored Mar 9, 2023
2 parents 1342c85 + d1e12e6 commit 3c17ef5
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/GoogleDriveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class GoogleDriveAdapter implements FilesystemAdapter
'spaces' => 'drive',
'useHasDir' => false,
'useDisplayPaths' => true,
'showDisplayPaths' => false,
'usePermanentDelete' => false,
'useSinglePathTransaction' => false,
'publishPermission' => [
Expand Down Expand Up @@ -199,6 +200,13 @@ class GoogleDriveAdapter implements FilesystemAdapter
*/
private $useDisplayPaths = true;

/**
* Show display paths in extra metadata instead of virtual IDs
*
* @var bool
*/
private $showDisplayPaths = false;

/**
* Resolved root ID
*
Expand Down Expand Up @@ -249,6 +257,7 @@ public function __construct($service, $root = null, $options = [])
$this->useSinglePathTransaction = $this->options['useSinglePathTransaction'];
$this->publishPermission = $this->options['publishPermission'];
$this->useDisplayPaths = $this->options['useDisplayPaths'];
$this->showDisplayPaths = $this->options['showDisplayPaths'];
$this->optParams = $this->cleanOptParameters($this->options['parameters']);

if ($root !== null) {
Expand Down Expand Up @@ -1159,7 +1168,10 @@ protected function normaliseObject(DriveFile $object, $dirname)
$id = $object->getId();
$path_parts = $this->splitFileExtension($object->getName());
$type = $object->mimeType === self::DIRMIME ? 'dir' : 'file';
$result = ['id' => $id];
$result = [
'id' => $id,
'name' => $object->getName(),
];
$visibility = Visibility::PRIVATE;
$permissions = $object->getPermissions();
try {
Expand All @@ -1172,24 +1184,30 @@ protected function normaliseObject(DriveFile $object, $dirname)
} catch (Throwable $e) {
// Unnecesary
}
if ($this->useDisplayPaths) {
$result['virtual_path'] = ($dirname ? ($dirname.'/') : '').$id;
$result['display_path'] = $this->toDisplayPath($result['virtual_path']);
} else {
$result['virtual_path'] = ($dirname ? ($dirname.'/') : '').$id;
$result['display_path'] = $result['virtual_path'];
}

$result['virtual_path'] = ($dirname ? ($dirname.'/') : '').$id;
$result['display_path'] = $this->useDisplayPaths || $this->showDisplayPaths ? $this->toDisplayPath($result['virtual_path']) : $result['virtual_path'];

if ($type === 'file') {
$result['filename'] = $path_parts['filename'];
$result['extension'] = $path_parts['extension'];
return new FileAttributes($result['display_path'], (int)$object->getSize(), $visibility, strtotime($object->getModifiedTime()), $object->mimeType, $result);
return new FileAttributes(
$this->useDisplayPaths ? $result['display_path'] : $result['virtual_path'],
(int)$object->getSize(),
$visibility,
strtotime($object->getModifiedTime()),
$object->mimeType,
$result);
}
if ($type === 'dir') {
if ($this->useHasDir) {
$result['hasdir'] = isset($this->cacheHasDirs[$id]) ? $this->cacheHasDirs[$id] : false;
}
return new DirectoryAttributes(rtrim($result['display_path'], '/'), $visibility, strtotime($object->getModifiedTime()), $result);
return new DirectoryAttributes(
rtrim($this->useDisplayPaths ? $result['display_path'] : $result['virtual_path'], '/'),
$visibility,
strtotime($object->getModifiedTime()),
$result);
}
}

Expand Down

0 comments on commit 3c17ef5

Please sign in to comment.