1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00

Expires header returned to the endpoints

This commit is contained in:
shimon 2022-07-28 18:24:18 +03:00
parent ae80607248
commit 5511a93e9c
5 changed files with 29 additions and 25 deletions

View file

@ -47,9 +47,10 @@ $avatarCallback = function (string $type, string $code, int $width, int $height,
$output = (empty($output)) ? $type : $output;
$data = $image->output($output, $quality);
$response
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
->setContentType('image/png')
->file($data, 'image/png');
->file($data, 'image/png')
;
unset($image);
};
@ -153,9 +154,10 @@ App::get('/v1/avatars/image')
$data = $image->output($output, $quality);
$response
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
->setContentType('image/png')
->file($data, 'image/png');
->file($data, 'image/png')
;
unset($image);
});
@ -282,9 +284,10 @@ App::get('/v1/avatars/favicon')
$data = $image->output($output, $quality);
$response
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
->setContentType('image/png')
->file($data, 'image/png');
->file($data, 'image/png')
;
unset($image);
});
@ -320,13 +323,13 @@ App::get('/v1/avatars/qr')
}
$image = new Image($qrcode->render($text));
$image->crop((int) $size, (int) $size);
$response
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache
->setContentType('image/png')
->send($image->output('png', 9));
->file($image->output('png', 9), 'image/png')
;
});
App::get('/v1/avatars/initials')
@ -407,5 +410,6 @@ App::get('/v1/avatars/initials')
$response
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache
->setContentType('image/png')
->send($image->getImageBlob());
->file($image->getImageBlob(), 'image/png')
;
});

View file

@ -959,9 +959,10 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
$contentType = (\array_key_exists($output, $outputs)) ? $outputs[$output] : $outputs['jpg'];
$response
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT')
->setContentType($contentType)
->file($data, $contentType);
->file($data, $contentType)
;
unset($image);
});

View file

@ -134,16 +134,14 @@ App::init(function (App $utopia, Request $request, Response $response, Document
}
$data = json_decode($data, true);
$expire = \date('D, d M Y H:i:s', \time() + $timestamp) . ' GMT';
$response
->addHeader('Expires', $expire)
->addHeader('X-Appwrite-Cache', 'hit')
->setContentType($data['content-type'])
->file(base64_decode($data['payload']), $data['content-type']);
} else {
$response
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $timestamp) . ' GMT')
->addHeader('X-Appwrite-Cache', 'miss');
->addHeader('X-Appwrite-Cache', 'hit')
->setContentType($data['content-type'])
->file(base64_decode($data['payload']), $data['content-type'])
;
} else {
$response->addHeader('X-Appwrite-Cache', 'miss');
}
}
}, ['utopia', 'request', 'response', 'project', 'user', 'events', 'audits', 'mails', 'usage', 'deletes', 'database', 'dbForProject', 'mode'], 'api');

12
composer.lock generated
View file

@ -2051,16 +2051,16 @@
},
{
"name": "utopia-php/database",
"version": "0.18.6",
"version": "0.18.9",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "e9e163642546343267c2fe0ee90016a4a0230b4a"
"reference": "227b3ca919149b7b0d6556c8effe9ee46ed081e6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/e9e163642546343267c2fe0ee90016a4a0230b4a",
"reference": "e9e163642546343267c2fe0ee90016a4a0230b4a",
"url": "https://api.github.com/repos/utopia-php/database/zipball/227b3ca919149b7b0d6556c8effe9ee46ed081e6",
"reference": "227b3ca919149b7b0d6556c8effe9ee46ed081e6",
"shasum": ""
},
"require": {
@ -2109,9 +2109,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.18.6"
"source": "https://github.com/utopia-php/database/tree/0.18.9"
},
"time": "2022-06-27T17:28:05+00:00"
"time": "2022-07-19T09:42:53+00:00"
},
{
"name": "utopia-php/domains",

View file

@ -460,6 +460,7 @@ class Response extends SwooleResponse
'content-type' => $contentType,
'payload' => $data
];
$this->send($data);
}