Merge branch 'feat-git-integration' of github.com:appwrite/appwrite into feat-git-integration
This commit is contained in:
commit
d5968f3f2a
1 changed files with 87 additions and 0 deletions
|
@ -760,6 +760,93 @@ App::put('/v1/functions/:functionId')
|
||||||
$response->dynamic($function, Response::MODEL_FUNCTION);
|
$response->dynamic($function, Response::MODEL_FUNCTION);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
App::get('/v1/functions/:functionId/deployments/:deploymentId/download')
|
||||||
|
->groups(['api', 'functions'])
|
||||||
|
->desc('Download Deployment')
|
||||||
|
->label('scope', 'functions.read')
|
||||||
|
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||||
|
->label('sdk.namespace', 'functions')
|
||||||
|
->label('sdk.method', 'downloadDeployment')
|
||||||
|
->label('sdk.description', '/docs/references/functions/download-deployment.md')
|
||||||
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
|
->label('sdk.response.type', '*/*')
|
||||||
|
->label('sdk.methodType', 'location')
|
||||||
|
->param('functionId', '', new UID(), 'Function ID.')
|
||||||
|
->param('deploymentId', '', new UID(), 'Deployment ID.')
|
||||||
|
->inject('response')
|
||||||
|
->inject('request')
|
||||||
|
->inject('dbForProject')
|
||||||
|
->inject('deviceFunctions')
|
||||||
|
->action(function (string $functionId, string $deploymentId, Response $response, Request $request, Database $dbForProject, Device $deviceFunctions) {
|
||||||
|
|
||||||
|
$function = $dbForProject->getDocument('functions', $functionId);
|
||||||
|
if ($function->isEmpty()) {
|
||||||
|
throw new Exception(Exception::FUNCTION_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
||||||
|
if ($deployment->isEmpty()) {
|
||||||
|
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($deployment->getAttribute('resourceId') !== $function->getId()) {
|
||||||
|
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = $deployment->getAttribute('path', '');
|
||||||
|
if (!$deviceFunctions->exists($path)) {
|
||||||
|
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response
|
||||||
|
->setContentType('application/gzip')
|
||||||
|
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache
|
||||||
|
->addHeader('X-Peak', \memory_get_peak_usage())
|
||||||
|
->addHeader('Content-Disposition', 'attachment; filename="'.$deploymentId.'.tar.gz"')
|
||||||
|
;
|
||||||
|
|
||||||
|
$size = $deviceFunctions->getFileSize($path);
|
||||||
|
$rangeHeader = $request->getHeader('range');
|
||||||
|
|
||||||
|
if (!empty($rangeHeader)) {
|
||||||
|
$start = $request->getRangeStart();
|
||||||
|
$end = $request->getRangeEnd();
|
||||||
|
$unit = $request->getRangeUnit();
|
||||||
|
|
||||||
|
if ($end === null) {
|
||||||
|
$end = min(($start + MAX_OUTPUT_CHUNK_SIZE - 1), ($size - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($unit !== 'bytes' || $start >= $end || $end >= $size) {
|
||||||
|
throw new Exception(Exception::STORAGE_INVALID_RANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response
|
||||||
|
->addHeader('Accept-Ranges', 'bytes')
|
||||||
|
->addHeader('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $size)
|
||||||
|
->addHeader('Content-Length', $end - $start + 1)
|
||||||
|
->setStatusCode(Response::STATUS_CODE_PARTIALCONTENT);
|
||||||
|
|
||||||
|
$response->send($deviceFunctions->read($path, $start, ($end - $start + 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($size > APP_STORAGE_READ_BUFFER) {
|
||||||
|
$response->addHeader('Content-Length', $deviceFunctions->getFileSize($path));
|
||||||
|
for ($i = 0; $i < ceil($size / MAX_OUTPUT_CHUNK_SIZE); $i++) {
|
||||||
|
$response->chunk(
|
||||||
|
$deviceFunctions->read(
|
||||||
|
$path,
|
||||||
|
($i * MAX_OUTPUT_CHUNK_SIZE),
|
||||||
|
min(MAX_OUTPUT_CHUNK_SIZE, $size - ($i * MAX_OUTPUT_CHUNK_SIZE))
|
||||||
|
),
|
||||||
|
(($i + 1) * MAX_OUTPUT_CHUNK_SIZE) >= $size
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response->send($deviceFunctions->read($path));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
App::patch('/v1/functions/:functionId/deployments/:deploymentId')
|
App::patch('/v1/functions/:functionId/deployments/:deploymentId')
|
||||||
->groups(['api', 'functions'])
|
->groups(['api', 'functions'])
|
||||||
->desc('Update Function Deployment')
|
->desc('Update Function Deployment')
|
||||||
|
|
Loading…
Reference in a new issue