summaryrefslogtreecommitdiff
path: root/packages/client/src
diff options
context:
space:
mode:
authorAndreas Nedbal <andreas.nedbal@in2code.de>2022-04-29 03:21:02 +0200
committerGitHub <noreply@github.com>2022-04-29 10:21:02 +0900
commit8f32064fea395b3dbea66a4d0c9404ff569a4b5d (patch)
tree777d918c46f6534795af5d2a86fdb81d40645025 /packages/client/src
parentchore(deps): Update github actions to use the same version as defined in .nod... (diff)
downloadmisskey-8f32064fea395b3dbea66a4d0c9404ff569a4b5d.tar.gz
misskey-8f32064fea395b3dbea66a4d0c9404ff569a4b5d.tar.bz2
misskey-8f32064fea395b3dbea66a4d0c9404ff569a4b5d.zip
refactor(client): refactor api-console to use Composition API (#8566)
Diffstat (limited to 'packages/client/src')
-rw-r--r--packages/client/src/pages/api-console.vue96
1 files changed, 42 insertions, 54 deletions
diff --git a/packages/client/src/pages/api-console.vue b/packages/client/src/pages/api-console.vue
index 142a3bee2e..7f174a6318 100644
--- a/packages/client/src/pages/api-console.vue
+++ b/packages/client/src/pages/api-console.vue
@@ -25,8 +25,8 @@
</MkSpacer>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { defineExpose, ref } from 'vue';
import * as JSON5 from 'json5';
import MkButton from '@/components/ui/button.vue';
import MkInput from '@/components/form/input.vue';
@@ -34,63 +34,51 @@ import MkTextarea from '@/components/form/textarea.vue';
import MkSwitch from '@/components/form/switch.vue';
import * as os from '@/os';
import * as symbols from '@/symbols';
+import { Endpoints } from 'misskey-js';
-export default defineComponent({
- components: {
- MkButton, MkInput, MkTextarea, MkSwitch,
- },
+const body = ref('{}');
+const endpoint = ref('');
+const endpoints = ref<any[]>([]);
+const sending = ref(false);
+const res = ref('');
+const withCredential = ref(true);
- data() {
- return {
- [symbols.PAGE_INFO]: {
- title: 'API console',
- icon: 'fas fa-terminal'
- },
+os.api('endpoints').then(endpointResponse => {
+ endpoints.value = endpointResponse;
+});
- endpoint: '',
- body: '{}',
- res: null,
- sending: false,
- endpoints: [],
- withCredential: true,
+function send() {
+ sending.value = true;
+ const requestBody = JSON5.parse(body.value);
+ os.api(endpoint.value as keyof Endpoints, requestBody, requestBody.i || (withCredential.value ? undefined : null)).then(resp => {
+ sending.value = false;
+ res.value = JSON5.stringify(resp, null, 2);
+ }, err => {
+ sending.value = false;
+ res.value = JSON5.stringify(err, null, 2);
+ });
+}
- };
- },
+function onEndpointChange() {
+ os.api('endpoint', { endpoint: endpoint.value }, withCredential.value ? undefined : null).then(resp => {
+ const endpointBody = {};
+ for (const p of resp.params) {
+ endpointBody[p.name] =
+ p.type === 'String' ? '' :
+ p.type === 'Number' ? 0 :
+ p.type === 'Boolean' ? false :
+ p.type === 'Array' ? [] :
+ p.type === 'Object' ? {} :
+ null;
+ }
+ body.value = JSON5.stringify(endpointBody, null, 2);
+ });
+}
- created() {
- os.api('endpoints').then(endpoints => {
- this.endpoints = endpoints;
- });
+defineExpose({
+ [symbols.PAGE_INFO]: {
+ title: 'API console',
+ icon: 'fas fa-terminal'
},
-
- methods: {
- send() {
- this.sending = true;
- const body = JSON5.parse(this.body);
- os.api(this.endpoint, body, body.i || (this.withCredential ? undefined : null)).then(res => {
- 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>