Code Monkey home page Code Monkey logo

Comments (6)

masbug avatar masbug commented on August 24, 2024

Hi,
this driver is focused on the case when useDisplayPaths==true so the support for a false case might be lacking. However, when you call the createDir function you get back an array. The path should contain the id. Does it not?
See this snippet from the createDir:

...
        $folder = $this->createDirectory($name, $pdir !== '' ? basename($pdir) : $pdir);
        if ($folder !== null) {
            $itemId = $folder->getId();
            $this->cacheFileObjects[$itemId] = $folder;
            $this->cacheHasDirs[$itemId] = false;
            $this->cacheObjects([$itemId => $folder]);
            $path_parts = $this->splitFileExtension($name);
            $result = [
                'path' => Util::normalizeDirname($pdir).'/'.($this->useDisplayPaths ? $name : $itemId), // <-here the $itemId should be the folder ID
                'filename' => $path_parts['filename'],
                'extension' => $path_parts['extension']
            ];
            return $result;
        }

        return false;
...

from flysystem-google-drive-ext.

erikn69 avatar erikn69 commented on August 24, 2024

Also acording Flysystems V1 Docs you have to use createDir, not 'createDirectory', Flysystems Docs
image
but if you are using createDirectory , maybe with $result->getId();

from flysystem-google-drive-ext.

unsa-cdn avatar unsa-cdn commented on August 24, 2024

@masbug sorry I didn't mentioned it I was asking for branch 2.x which I think uses Flysystems V2 where createDir and CreateDirectory functions are the opposite from version 1.x

from flysystem-google-drive-ext.

erikn69 avatar erikn69 commented on August 24, 2024

public function getMetadata(string $path)
{
if ($this->useDisplayPaths) {
$path = $this->toVirtualPath($path, true, true);
}
if (($obj = $this->getFileObject($path, true))) {
if ($obj instanceof Google_Service_Drive_DriveFile) {
return $this->normaliseObject($obj, self::dirname($path));
}
}
return false;
}

@unsa-cdn on V2 everything changes(CreateDirectory returns void) you has to use FileAttributes or DirectoryAttributes, Flysystems V2 docs
both has function extraMetadata(): array

So, you can use: $adapter->getMetadata or $adapter->listContents and iterate a list of FileAttributes

$file=$adapter->getMetadata('path/to/file.txt'); //can be directory
if($file){
    $id=$file->getMetadata()['id']
}

because: $result = ['id' => $id]; and
return new FileAttributes($result['display_path'],$object->getSize(),$visibility, $object->getModifiedTime(),$object->mimeType,$result);

protected function normaliseObject(Google_Service_Drive_DriveFile $object, $dirname)
{
$id = $object->getId();
$path_parts = $this->splitFileExtension($object->getName());
$type = $object->mimeType === self::DIRMIME ? 'dir' : 'file';
$result = ['id' => $id];

There is a PR for more direct access, but it's a breaking change github.com/thephpleague/flysystem/pull/1324

If something doesn't work or can be improved, i can make a PR

from flysystem-google-drive-ext.

unsa-cdn avatar unsa-cdn commented on August 24, 2024

I see I need to provide a path to this getMetadata function but the way google drive woks is with Ids. I would need to migrate my current database to use display paths instead of storing Ids I don't think so. Then I guess I will have to stay in V1 of flysystem.
Thank you for your help @erikn69

from flysystem-google-drive-ext.

erikn69 avatar erikn69 commented on August 24, 2024

V2 its a headacke with the throws and this package is focused on the case when useDisplayPaths==true

from flysystem-google-drive-ext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.