1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

Added upload

This commit is contained in:
Eldad Fux 2020-07-15 06:38:57 +03:00
parent 8d5e62a02b
commit 6251d2b40a
4 changed files with 24 additions and 11 deletions

View file

@ -1334,9 +1334,18 @@ $collections = [
],
[
'$collection' => Database::SYSTEM_COLLECTION_RULES,
'label' => 'Code',
'key' => 'code',
'type' => Database::SYSTEM_VAR_TYPE_KEY,
'label' => 'Code Path',
'key' => 'codePath',
'type' => Database::SYSTEM_VAR_TYPE_TEXT,
'default' => '',
'required' => false,
'array' => false,
],
[
'$collection' => Database::SYSTEM_COLLECTION_RULES,
'label' => 'Code Size',
'key' => 'codeSize',
'type' => Database::SYSTEM_VAR_TYPE_NUMERIC,
'default' => '',
'required' => false,
'array' => false,

View file

@ -220,8 +220,8 @@ App::post('/v1/functions/:functionId/tags')
->label('sdk.description', '/docs/references/functions/create-tag.md')
->param('functionId', '', function () { return new UID(); }, 'Function unique ID.')
->param('command', '', function () { return new Text('1028'); }, 'Code execution command.')
// ->param('code', '', function () { return new Text(128); }, 'Code package. Use the '.APP_NAME.' code packager to create a deployable package file.')
->param('code', [], function () { return new File(); }, 'Gzip file containing your code.', false)
// ->param('code', '', function () { return new Text(128); }, 'Code package. Use the '.APP_NAME.' code packager to create a deployable package file.')
->action(function ($functionId, $command, $code, $request, $response, $projectDB) {
$function = $projectDB->getDocument($functionId);
@ -245,9 +245,9 @@ App::post('/v1/functions/:functionId/tags')
$file['size'] = (\is_array($file['size']) && isset($file['size'][0])) ? $file['size'][0] : $file['size'];
// Check if file type is allowed (feature for project settings?)
if (!$fileType->isValid($file['tmp_name'])) {
throw new Exception('File type not allowed', 400);
}
// if (!$fileType->isValid($file['tmp_name'])) {
// throw new Exception('File type not allowed', 400);
// }
if (!$fileSize->isValid($file['size'])) { // Check if file size is exceeding allowed limit
throw new Exception('File size not allowed', 400);

View file

@ -366,6 +366,8 @@ App::get('/console/functions/function')
$page
->setParam('events', Config::getParam('events', []))
->setParam('fileLimit', App::getEnv('_APP_STORAGE_LIMIT', 0))
->setParam('fileLimitHuman', Storage::human(App::getEnv('_APP_STORAGE_LIMIT', 0)))
;
$layout

View file

@ -1,5 +1,6 @@
<?php
$fileLimit = $this->getParam('fileLimit', 0);
$fileLimitHuman = $this->getParam('fileLimitHuman', 0);
$events = array_keys($this->getParam('events', []));
?>
@ -60,7 +61,7 @@ $events = array_keys($this->getParam('events', []));
data-scope="sdk"
data-event="load,functions.createTag,functions.deleteTag"
data-name="project-function-tags"
data-param-project-id="{{router.params.project}}"
data-param-function-id="{{router.params.id}}"
data-success="trigger"
data-success-param-trigger-events="functions.listTags">
@ -77,7 +78,7 @@ $events = array_keys($this->getParam('events', []));
<a data-ls-attrs="href=/console/functions/function?id={{function.$id}}&project={{router.params.project}}" class="button pull-end">Set Default</a>
<span data-ls-bind="{{function.name}}"></span>
<span data-ls-bind="{{tag}}"></span>
</li>
</ul>
</div>
@ -110,7 +111,8 @@ $events = array_keys($this->getParam('events', []));
<input type="text" id="tag-command" name="command" required autocomplete="off" class="margin-bottom" placeholder="node main.js" />
<label for="tag-code">Gzipped Code</label>
<input type="file" name="code" id="tag-code" size="1" required class="margin-bottom-xl">
<input type="file" name="code" id="tag-code" size="1" required accept="application/x-gzip">
<div class="text-fade text-size-xs margin-top-negative-small margin-bottom-large">(Max file size allowed: <?php echo $fileLimitHuman; ?>)</div>
<footer>
<button type="submit">Create</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>