Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t_core_tokens now has only a c_inherit column. we'll need a c_owner column too, ... #5

Open
github-actions bot opened this issue Dec 3, 2023 · 0 comments
Labels

Comments

@github-actions
Copy link

github-actions bot commented Dec 3, 2023

print_r($serverParams);

print_r($request->getHeader('X-glued-auth-uuid'));

$f['meta'] = json_decode($parsedBody['stor'] ?? [],true)[$file->getClientFilename()] ?? [];

// TODO t_core_tokens now has only a c_inherit column. we'll need a c_owner column too, because user tokens will use c_inherit, but svc tokens will have c_owner (the one whom is the token management associated to)

        return $response->withJson($data);
    }

    function getObjectMeta($file):array {
        $path = $file->getStream()->getMetadata('uri');
        $mime = mime_content_type($path) ?? $file->getClientMediaType() ?? null;
        $data = [
            'uuid' => \Ramsey\Uuid\Uuid::uuid4()->toString(),
            'name' => $file->getClientFilename(),
            'size' => $file->getSize(),
            'hash' => [
                'sha3-512' => hash_file('sha3-512', $path),
                'md5' => hash_file('md5', $path)
            ],
            'mime' => [
                'type' => $mime,
                'ext' => $mime && array_key_exists($mime, $this->utils->mime2ext) ? $this->utils->mime2ext[$mime][0] : ($file->getClientFilename() ? pathinfo($file->getClientFilename(), PATHINFO_EXTENSION) : null),
            ]
        ];
        return $data;
    }

    // TODO t_core_tokens now has only a c_inherit column. we'll need a c_owner column too, because user tokens will use c_inherit, but svc tokens will have c_owner (the one whom is the token management associated to)
    public function files_w1(Request $request, Response $response, array $args = []): Response {

        if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > $this->convert_units(ini_get('post_max_size'))) {
            throw new \Exception(
                'Upload size in bytes exceeds allowed limit ('.$_SERVER['CONTENT_LENGTH'].' > '.$this->convert_units(ini_get('post_max_size')).').',
                400);
        }

        $data         = [];
        $files        = $request->getUploadedFiles();
        $parsedBody   = $request->getParsedBody();
        $hdrUser      = $request->getHeader('X-glued-auth-uuid')[0] ?? null;
        $hdrAuth      = $request->getHeader('Authorization')[0] ?? null;

        $serverParams = $request->getServerParams();
        $headers      = $request->getHeaders();
        $headerValueArray = $request->getHeader('Accept');
        $headerValueString = $request->getHeaderLine('Accept');

        //print_r($headers);
        //print_r($serverParams);
        //print_r($request->getHeader('X-glued-auth-uuid'));
        $hdrUser = $request->getHeader('X-glued-auth-uuid')[0] ?? null;
        $hdrAuth = $request->getHeader('Authorization')[0] ?? null;

//die();

        if (!empty($files)) {
            $target_dir = array_values($this->dev_handle())[0]['path'];

            // flatten $files array to unify handling of file1=,file2=,file[]
            foreach ($files as $k => $f) {
                if (is_array($f)) {
                    foreach ($f as $kk=>$ff) { $flattened[$k.'+'.$kk] = $ff; }
                } else {
                    $flattened[$k] = $f;
                }
            }

            $linksMeta = json_decode(($parsedBody['links'] ?? []), true);
            foreach ($flattened as $file) {
                if ($file->getError() === UPLOAD_ERR_OK) {
                    $target_file = $target_dir . $file->getClientFilename();
                    $object = $this->getObjectMeta($file);
                    $link = $linksMeta[$file->getClientFilename()] ?? [];
                    if (!isset($link['name'])) { $link['name'] = $file->getClientFilename() ?? 'file'; }
                    $data[] = [
                        'object' => $object,
                        'link' => $link
                    ];

                    /*
                    //print_r($data); echo "DIEING"; die();
                    //$f['meta'] = json_decode($parsedBody['stor'] ?? [],true)[$file->getClientFilename()] ?? [];


                    // Check if file already exists
                    if (!file_exists($target_file)) {
@github-actions github-actions bot added the todo label Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants