Giter Club home page Giter Club logo

Comments (7)

matthewgoslett avatar matthewgoslett commented on May 27, 2024

Can you provide me with some sample code so I can replicate this?
Thanks

from flysystem-google-cloud-storage.

paulcanning avatar paulcanning commented on May 27, 2024

My connector:

function googleCloud($bucket)
    {
        $credentials = new \Google_Auth_AssertionCredentials(
            'gcstest@MY_PROJECT.iam.gserviceaccount.com',
            [\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL],
            file_get_contents(set_realpath('MY_SECRET.p12')),
            'notasecret'
        );

        $client = new \Google_Client();
        $client->setAssertionCredentials($credentials);
        $client->setDeveloperKey('MY_KEY');

        $service = new \Google_Service_Storage($client);

        $adapter = new GoogleStorageAdapter($service, $bucket);

        return $adapter;
    }

    public function elfinder_init()
    {
        $this->load->helper('path');

        $opts = array(
            'roots' => array(
                array(
                    'id' => 'root',
                    'driver' => 'Flysystem',
                    'alias' => 'CS Root',
                    'URL' => 'https://storage.googleapis.com/MY_BUCKET/',
                    'filesystem' => new Filesystem($this->googleCloud('MY_BUCKET')),
                    'separator' => '/'
                )
            )
        );

        $this->load->library('elfinder_lib', $opts);
    }

from flysystem-google-cloud-storage.

paulcanning avatar paulcanning commented on May 27, 2024

Please look at #23 and #24 as I believe it is all connected.

You can replicate this by doing the following:

In the root bucket, create a directory (using the GCS console) then upload a file into the new directory.

In elFinder, you will now see two directories under the main root bucket, with the same name. One will contain the file you uploaded, the other will be empty.

I believe this issue and the two I linked are all related. Basically, the adapter is not recognising directories properly and simply normalises then to be files (if you change the type to directory on line 139 elFinder will list everything as directories (even files obviously) but previously "invisible" directories are now visible.

Clearly some bugs here.

from flysystem-google-cloud-storage.

paulcanning avatar paulcanning commented on May 27, 2024

Below is a basic fix for the issue. It will need testing but seems to work for me.

protected function normaliseObject(\Google_Service_Storage_StorageObject $object)
    {
        $type = 'file';

        if ($object->size == '0')
        {
            $type = 'dir';
        }

        return [
            'type' => $type,
            'dirname' => Util::dirname($object->getName()),
            'path' => $type == 'file' ? $object->getName() : rtrim($object->getName(), '/'),
            'timestamp' => strtotime($object->getUpdated()),
            'mimetype' => $object->getContentType(),
            'size' => $object->getSize(),
        ];
    }

from flysystem-google-cloud-storage.

matthewgoslett avatar matthewgoslett commented on May 27, 2024

Is this related to #23

With that proposed fix of mine in place, it seems to be resolved:

$filesystem->createDir('zzzz');
$filesystem->put('zzzz', 'hello world');
var_dump($filesystem->listContents());

array(2) {
  [0]=>
  array(8) {
    ["type"]=>
    string(4) "file"
    ["dirname"]=>
    string(0) ""
    ["path"]=>
    string(5) "zzzzz"
    ["timestamp"]=>
    int(1463658746)
    ["mimetype"]=>
    string(10) "text/plain"
    ["size"]=>
    string(2) "11"
    ["basename"]=>
    string(5) "zzzzz"
    ["filename"]=>
    string(5) "zzzzz"
  }
  [1]=>
  array(8) {
    ["type"]=>
    string(3) "dir"
    ["dirname"]=>
    string(0) ""
    ["path"]=>
    string(5) "zzzzz"
    ["timestamp"]=>
    int(1463658744)
    ["mimetype"]=>
    string(10) "text/plain"
    ["size"]=>
    string(1) "0"
    ["basename"]=>
    string(5) "zzzzz"
    ["filename"]=>
    string(5) "zzzzz"
  }
}

from flysystem-google-cloud-storage.

paulcanning avatar paulcanning commented on May 27, 2024

Yes, it is related, I didn't realise at the time :)

from flysystem-google-cloud-storage.

matthewgoslett avatar matthewgoslett commented on May 27, 2024

Fixed in release 1.0.4 - https://github.com/Superbalist/flysystem-google-storage/releases/tag/1.0.4

from flysystem-google-cloud-storage.

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.