2021-02-06 13:05:00 +01:00
|
|
|
<template>
|
|
|
|
<FormBase>
|
2021-04-13 18:41:49 +02:00
|
|
|
<FormInfo warn>{{ $ts._plugin.installWarn }}</FormInfo>
|
2021-02-06 13:05:00 +01:00
|
|
|
|
|
|
|
<FormGroup>
|
2021-09-29 17:50:45 +02:00
|
|
|
<FormTextarea v-model="code" tall>
|
2021-02-06 13:05:00 +01:00
|
|
|
<span>{{ $ts.code }}</span>
|
|
|
|
</FormTextarea>
|
|
|
|
</FormGroup>
|
|
|
|
|
2021-04-20 16:22:59 +02:00
|
|
|
<FormButton @click="install" :disabled="code == null" primary inline><i class="fas fa-check"></i> {{ $ts.install }}</FormButton>
|
2021-02-06 13:05:00 +01:00
|
|
|
</FormBase>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import { AiScript, parse } from '@syuilo/aiscript';
|
|
|
|
import { serialize } from '@syuilo/aiscript/built/serializer';
|
|
|
|
import { v4 as uuid } from 'uuid';
|
2021-03-23 09:30:14 +01:00
|
|
|
import FormTextarea from '@client/components/form/textarea.vue';
|
|
|
|
import FormSelect from '@client/components/form/select.vue';
|
|
|
|
import FormRadios from '@client/components/form/radios.vue';
|
2021-09-29 17:50:45 +02:00
|
|
|
import FormBase from '@client/components/debobigego/base.vue';
|
|
|
|
import FormGroup from '@client/components/debobigego/group.vue';
|
|
|
|
import FormLink from '@client/components/debobigego/link.vue';
|
|
|
|
import FormButton from '@client/components/debobigego/button.vue';
|
|
|
|
import FormInfo from '@client/components/debobigego/info.vue';
|
2021-03-23 09:30:14 +01:00
|
|
|
import * as os from '@client/os';
|
|
|
|
import { ColdDeviceStorage } from '@client/store';
|
|
|
|
import { unisonReload } from '@client/scripts/unison-reload';
|
2021-04-10 05:54:12 +02:00
|
|
|
import * as symbols from '@client/symbols';
|
2021-02-06 13:05:00 +01:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
FormTextarea,
|
|
|
|
FormSelect,
|
|
|
|
FormRadios,
|
|
|
|
FormBase,
|
|
|
|
FormGroup,
|
|
|
|
FormLink,
|
|
|
|
FormButton,
|
2021-04-13 18:41:49 +02:00
|
|
|
FormInfo,
|
2021-02-06 13:05:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['info'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: {
|
2021-02-06 13:05:00 +01:00
|
|
|
title: this.$ts._plugin.install,
|
2021-09-29 17:50:45 +02:00
|
|
|
icon: 'fas fa-download',
|
|
|
|
bg: 'var(--bg)',
|
2021-02-06 13:05:00 +01:00
|
|
|
},
|
|
|
|
code: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
2021-04-10 05:54:12 +02:00
|
|
|
this.$emit('info', this[symbols.PAGE_INFO]);
|
2021-02-06 13:05:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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) => {
|
2021-03-23 09:30:14 +01:00
|
|
|
os.popup(import('@client/components/token-generate-window.vue'), {
|
2021-02-06 13:05:00 +01:00
|
|
|
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(() => {
|
2021-02-17 13:36:56 +01:00
|
|
|
unisonReload();
|
2021-02-06 13:05:00 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|