diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2021-02-06 21:05:00 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2021-02-06 21:05:00 +0900 |
| commit | 3d73ce63cade45f8dc45987aa9d500460c723ed2 (patch) | |
| tree | e8d17a4419a6a8e123d929b29e1276dfa25f8efb /src/client/pages/settings/plugin.install.vue | |
| parent | Update dep (diff) | |
| download | misskey-3d73ce63cade45f8dc45987aa9d500460c723ed2.tar.gz misskey-3d73ce63cade45f8dc45987aa9d500460c723ed2.tar.bz2 misskey-3d73ce63cade45f8dc45987aa9d500460c723ed2.zip | |
Improve plugin setting
Diffstat (limited to 'src/client/pages/settings/plugin.install.vue')
| -rw-r--r-- | src/client/pages/settings/plugin.install.vue | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/src/client/pages/settings/plugin.install.vue b/src/client/pages/settings/plugin.install.vue new file mode 100644 index 0000000000..34c62619ad --- /dev/null +++ b/src/client/pages/settings/plugin.install.vue @@ -0,0 +1,146 @@ +<template> +<FormBase> + <MkInfo warn>{{ $ts.pluginInstallWarn }}</MkInfo> + + <FormGroup> + <FormTextarea v-model:value="code" tall> + <span>{{ $ts.code }}</span> + </FormTextarea> + </FormGroup> + + <FormButton @click="install" :disabled="code == null" primary inline><Fa :icon="faCheck"/> {{ $ts.install }}</FormButton> +</FormBase> +</template> + +<script lang="ts"> +import { defineComponent } from 'vue'; +import { faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt, faEye } from '@fortawesome/free-solid-svg-icons'; +import { AiScript, parse } from '@syuilo/aiscript'; +import { serialize } from '@syuilo/aiscript/built/serializer'; +import { v4 as uuid } from 'uuid'; +import FormTextarea from '@/components/form/textarea.vue'; +import FormSelect from '@/components/form/select.vue'; +import FormRadios from '@/components/form/radios.vue'; +import FormBase from '@/components/form/base.vue'; +import FormGroup from '@/components/form/group.vue'; +import FormLink from '@/components/form/link.vue'; +import FormButton from '@/components/form/button.vue'; +import MkInfo from '@/components/ui/info.vue'; +import * as os from '@/os'; +import { ColdDeviceStorage } from '@/store'; + +export default defineComponent({ + components: { + FormTextarea, + FormSelect, + FormRadios, + FormBase, + FormGroup, + FormLink, + FormButton, + MkInfo, + }, + + emits: ['info'], + + data() { + return { + INFO: { + title: this.$ts._plugin.install, + icon: faDownload + }, + code: null, + faPalette, faDownload, faFolderOpen, faCheck, faTrashAlt, faEye + } + }, + + mounted() { + this.$emit('info', this.INFO); + }, + + methods: { + installPlugin({ id, meta, ast, token }) { + ColdDeviceStorage.set('plugins', ColdDeviceStorage.get('plugins').concat({ + ...meta, + id, + active: true, + configData: {}, + token: token, + ast: ast + })); + }, + + async install() { + let ast; + try { + ast = parse(this.code); + } catch (e) { + os.dialog({ + type: 'error', + text: 'Syntax error :(' + }); + return; + } + const meta = AiScript.collectMetadata(ast); + if (meta == null) { + os.dialog({ + type: 'error', + text: 'No metadata found :(' + }); + return; + } + const data = meta.get(null); + if (data == null) { + os.dialog({ + type: 'error', + text: 'No metadata found :(' + }); + return; + } + const { name, version, author, description, permissions, config } = data; + if (name == null || version == null || author == null) { + os.dialog({ + type: 'error', + text: 'Required property not found :(' + }); + return; + } + + const token = permissions == null || permissions.length === 0 ? null : await new Promise((res, rej) => { + os.popup(import('@/components/token-generate-window.vue'), { + title: this.$ts.tokenRequested, + information: this.$ts.pluginTokenRequestedDescription, + initialName: name, + initialPermissions: permissions + }, { + done: async result => { + const { name, permissions } = result; + const { token } = await os.api('miauth/gen-token', { + session: null, + name: name, + permission: permissions, + }); + + res(token); + } + }, 'closed'); + }); + + this.installPlugin({ + id: uuid(), + meta: { + name, version, author, description, permissions, config + }, + token, + ast: serialize(ast) + }); + + os.success(); + + this.$nextTick(() => { + location.reload(); + }); + }, + } +}); +</script> |