2020-10-25 09:11:08 +02:00
|
|
|
<template>
|
2021-12-04 11:27:31 +02:00
|
|
|
<MkSpacer :content-max="700">
|
|
|
|
<div class="_formRoot">
|
|
|
|
<div class="_formBlock">
|
|
|
|
<MkInput v-model="endpoint" :datalist="endpoints" class="_formBlock" @update:modelValue="onEndpointChange()">
|
|
|
|
<template #label>Endpoint</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model="body" class="_formBlock" code>
|
|
|
|
<template #label>Params (JSON or JSON5)</template>
|
|
|
|
</MkTextarea>
|
|
|
|
<MkSwitch v-model="withCredential" class="_formBlock">
|
|
|
|
With credential
|
|
|
|
</MkSwitch>
|
|
|
|
<MkButton class="_formBlock" primary :disabled="sending" @click="send">
|
|
|
|
<template v-if="sending"><MkEllipsis/></template>
|
|
|
|
<template v-else><i class="fas fa-paper-plane"></i> Send</template>
|
|
|
|
</MkButton>
|
|
|
|
</div>
|
|
|
|
<div v-if="res" class="_formBlock">
|
|
|
|
<MkTextarea v-model="res" code readonly tall>
|
|
|
|
<template #label>Response</template>
|
|
|
|
</MkTextarea>
|
|
|
|
</div>
|
2021-04-11 15:31:38 +03:00
|
|
|
</div>
|
2021-12-04 11:27:31 +02:00
|
|
|
</MkSpacer>
|
2020-10-25 09:11:08 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import * as JSON5 from 'json5';
|
2021-11-11 19:02:25 +02:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
|
|
|
import MkSwitch from '@/components/form/switch.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-10-25 09:11:08 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
MkButton, MkInput, MkTextarea, MkSwitch,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 06:54:12 +03:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-11-03 13:36:12 +02:00
|
|
|
title: 'API console',
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-terminal'
|
2020-10-25 09:11:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
endpoint: '',
|
|
|
|
body: '{}',
|
|
|
|
res: null,
|
|
|
|
sending: false,
|
|
|
|
endpoints: [],
|
|
|
|
withCredential: true,
|
|
|
|
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
os.api('endpoints').then(endpoints => {
|
|
|
|
this.endpoints = endpoints;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
send() {
|
|
|
|
this.sending = true;
|
2021-12-04 20:01:35 +02:00
|
|
|
const body = JSON5.parse(this.body);
|
2021-12-05 14:52:57 +02:00
|
|
|
os.api(this.endpoint, body, body.i || (this.withCredential ? undefined : null)).then(res => {
|
2020-10-25 09:11:08 +02:00
|
|
|
this.sending = false;
|
|
|
|
this.res = JSON5.stringify(res, null, 2);
|
|
|
|
}, err => {
|
|
|
|
this.sending = false;
|
|
|
|
this.res = JSON5.stringify(err, null, 2);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onEndpointChange() {
|
|
|
|
os.api('endpoint', { endpoint: this.endpoint }, this.withCredential ? undefined : null).then(endpoint => {
|
|
|
|
const body = {};
|
|
|
|
for (const p of endpoint.params) {
|
|
|
|
body[p.name] =
|
|
|
|
p.type === 'String' ? '' :
|
|
|
|
p.type === 'Number' ? 0 :
|
|
|
|
p.type === 'Boolean' ? false :
|
|
|
|
p.type === 'Array' ? [] :
|
|
|
|
p.type === 'Object' ? {} :
|
|
|
|
null;
|
|
|
|
}
|
|
|
|
this.body = JSON5.stringify(body, null, 2);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|