Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
8f32064f
Unverified
Commit
8f32064f
authored
2 years ago
by
Andreas Nedbal
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(client): refactor api-console to use Composition API (#8566)
parent
6a446167
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/client/src/pages/api-console.vue
+42
-54
42 additions, 54 deletions
packages/client/src/pages/api-console.vue
with
42 additions
and
54 deletions
packages/client/src/pages/api-console.vue
+
42
−
54
View file @
8f32064f
...
...
@@ -25,8 +25,8 @@
</MkSpacer>
</template>
<
script
lang=
"ts"
>
import
{
define
Component
}
from
'
vue
'
;
<
script
lang=
"ts"
setup
>
import
{
define
Expose
,
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
>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment