php/googleClientLib/ffid.php

<?php
require_once 'env.php';
require_once 'cloud.php';

$f = new CloudFactory;
if (EnvCL) {
    if (count($a = envArgs()) === 1 and reset($a) === 'all')
        $a = ['fiwikoGo', 'spzhNC', 'wlHoNC', 'wlklNC', 'keNC', 'wlklGo', 'spwaGo'];
    foreach ($a as $one) {
        out("extracting $one at " . toLocalTst('now'));
        $cc = $f->make($one);
        $e = fopen('php://temp', 'w+');
        $o = fn ($n) => fputcsv($e, $n);
        $cc->ff('', $o
                , fn($m) => [$o([']]tbh meta']), $o($m[0]), $o($m[1]), $o([']]tbh ffid']), $o($m[2])]);
        out("$one $cc->ffFo folders, $cc->ffFi files, " . sprintf('%7.2e', $cc->ffSz) . ' Bytes (file) at ' . toLocalTst('now'));
        $sz = ftell($e);
        rewind($e);
        out("$one writing $sz bytes to $one:ffid-$one.csv, at " . toLocalTst('now'));
        $cc->upload("ffid-$one.csv" ,'text/csv', $sz < 1 ? '' : fread($e, $sz));
        fclose($e);
    }
    outEnd();
} else {
   $cc = $f->make('wlklGo');
   outBegin();
   $cc->ff('', fn ($n) => outTRD(...$n)
            , fn($m) => [out(']]tbh meta'), outTb(), outTRH(...$m[0]), outTRD(...$m[1]), outTbEnd(), out(']]tbh ffid'), outTb(), outTRH(...$m[2])]);
    outTbEnd();
    out("$cc->ffFo folders, $cc->ffFi files, " . sprintf('%7.2e', $cc->ffSz) . ' Bytes (file) at ' . toLocalTst('now'));
    outEnd();
}
/* ----------------
    # $cc->create('1Ff0f9XZx_K9o20hk0DqBnP-kENaspLbY', 'testCreate.txt', 'text/plain', 'text in testCreate.txt');
    # $cc->uploadVersion('1XkaWCp8lz5PrCx_MNd5Gby68Hrl5Wjmi', 'text in testCreate.txt from uploadVersion' );
    $cc->upload('testUploa2.txt' ,'text/plain', 'text in testUpload.txt from upload at ' . toLocalTst('now') ."\n und so oder");

exit();


    $nc->rename($nc->ff(), 'fn2valid', function($nx, $n, $fP, $fM, $tP) use($nc) {
            out("$nc->cloudId, $n[0], fP", $fP, ", tP", $tP, ", fM", $fM );
            echo "$nx path $n[0] invalid, renaming " . implode('/', $fM) . " ==> " . implode('/', $tP) . "\n";
            $nc->mv($fM, $tP);
        }); 
# require '/wkData/install/google-api-services/autoload.php';
// include_once __DIR__ . '/google-api/templates/base.php';

# echo "rrurl '" . RRURL . "' $_SERVER[REQUEST_SCHEME]<br>";

# echo "start " . __FILE__ . "\n";



const SCOPES = 
            [ 'https://www.googleapis.com/auth/drive.metadata.readonly' # drive readonly
            , 'https://www.googleapis.com/auth/drive'                   # drive file update
            , 'https://www.googleapis.com/auth/documents.readonly'      # docs readonly
            #, 'https://www.googleapis.com/auth/documents'               # docs readWrite
            ];
define('KYPR', str_starts_with($rp = realpath(__FILE__), '/wkData/www/') ? '/wkData/wk/extr2/'  # path prefix for locallly stored keys
             : (str_starts_with($rp, '/home/ch45859/web/') ? '/home/ch45859/web/files/extr2/' : err("realpath(__FILE__) $rp not supported")));
       # , RRURL = 'http://localhost/home/inf/php/e05GetServer.php' 
const RRCPA = '/wkData/pub/oauth2.log'; # redirect URL writes code to this path
;

if (php_sapi_name() === 'cli') {
    $tokenH = 'goRorAuthTokenFile';
    $codeH  = 'goRorAuthCodeCli';
    define('RRURL', 'https://localhost/home/inf/php/goauth2callback.php'); # redirect URL, authorization server sends token to this URL
} else {
    $tokenH = 'goRorAuthTokenSess';
    $codeH  = 'goRorAuthCodeWeb';
    define('RRURL', "$_SERVER[REQUEST_SCHEME]://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]") ; # redirect URL, authorization server sends token to this URL
    goAuthBeginWeb();
}
$c = goClient('QuW', 'Wlklxy', $tokenH, $codeH);
$drv = new Google\Service\Drive($c);
if (isset($_GET['csv'])) {
    header('content-type: text/csv'); 
    $out = fopen('php://temp', 'w+');
    $r = goDrList($drv, 'root', '', fn (...$a) => fputcsv($out, $a));
    rewind($out);
    fpassthru($out);
    fclose($out);
} else {
    outBegin(__FILE__);
    outTb();
    $r = goDrList($drv, 'root', '', 'outTRD', 'outTRH');
    outTbEnd();
    outEnd(__file__);
}
------------------------------*/