mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: upload variables (WIP)
This commit is contained in:
1 parent
14807b7c32
commit
1e29995c8c
2 files changed
+40
-20
No files matched your search
@@ -13,7 +13,7 @@
|
||||
class="alert-sticky"
|
||||
class:is-success={type === 'success'}
|
||||
class:is-warning={type === 'warning'}
|
||||
class:is-error={type === 'error'}
|
||||
class:is-danger={type === 'error'}
|
||||
class:is-info={type === 'info'}>
|
||||
<button class="x-button" aria-label="close alert" on:click={() => dispatch('dismiss')}>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
|
||||
+39
-19
@@ -1,21 +1,57 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
// import { addNotification } from '$lib/stores/notifications';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { variableList } from '../../../store';
|
||||
|
||||
export let show = false;
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const functionId = $page.params.function;
|
||||
let list = new DataTransfer();
|
||||
let files: FileList;
|
||||
let input: HTMLInputElement;
|
||||
let variables: object = {};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
dispatch('uploaded', variables);
|
||||
if (files?.length) {
|
||||
const variables = await parseFile(files[0]);
|
||||
for (const variable of variables) {
|
||||
try {
|
||||
await variableList.create(functionId, variable.key, variable.value);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Variable uploaded'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
dispatch('uploaded', variables);
|
||||
} else {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: 'No file uploaded'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
async function parseFile(file: File) {
|
||||
if (file) {
|
||||
let variables = [];
|
||||
let text = await file.text();
|
||||
text.split('\n').forEach((line) => {
|
||||
const [key, value] = line.split('=');
|
||||
variables.push({ key, value });
|
||||
});
|
||||
return variables;
|
||||
}
|
||||
}
|
||||
|
||||
function dropHandler(ev: DragEvent) {
|
||||
ev.preventDefault();
|
||||
if (ev.dataTransfer.items) {
|
||||
@@ -34,22 +70,6 @@
|
||||
function dragOverHandler(ev: DragEvent) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
async function parseFile(file: File) {
|
||||
if (file) {
|
||||
let text = await file.text();
|
||||
|
||||
text.split('\n').forEach((line) => {
|
||||
const [key, value] = line.split('=');
|
||||
variables[key] = value;
|
||||
});
|
||||
|
||||
return variables;
|
||||
}
|
||||
}
|
||||
|
||||
$: console.log(parseFile(files?.length ? files[0] : null));
|
||||
$: console.log(variables);
|
||||
</script>
|
||||
|
||||
<input bind:files bind:this={input} type="file" style="display: none" />
|
||||
|
||||
Reference in new issue
Block a user