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
5251cd3a
Unverified
Commit
5251cd3a
authored
1 year ago
by
かっこかり
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
(refactor) api呼び出し関数のレスポンス型を必要に応じてオーバーライドできるように (#12936)
parent
0e536bdd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/frontend/src/scripts/misskey-api.ts
+18
-8
18 additions, 8 deletions
packages/frontend/src/scripts/misskey-api.ts
with
18 additions
and
8 deletions
packages/frontend/src/scripts/misskey-api.ts
+
18
−
8
View file @
5251cd3a
...
...
@@ -10,12 +10,17 @@ import { $i } from '@/account.js';
export
const
pendingApiRequestsCount
=
ref
(
0
);
// Implements Misskey.api.ApiClient.request
export
function
misskeyApi
<
E
extends
keyof
Misskey
.
Endpoints
,
P
extends
Misskey
.
Endpoints
[
E
][
'
req
'
]
>
(
export
function
misskeyApi
<
ResT
=
void
,
E
extends
keyof
Misskey
.
Endpoints
=
keyof
Misskey
.
Endpoints
,
P
extends
Misskey
.
Endpoints
[
E
][
'
req
'
]
=
Misskey
.
Endpoints
[
E
][
'
req
'
],
_ResT
=
ResT
extends
void
?
Misskey
.
api
.
SwitchCaseResponseType
<
E
,
P
>
:
ResT
,
>
(
endpoint
:
E
,
data
:
P
=
{}
as
any
,
token
?:
string
|
null
|
undefined
,
signal
?:
AbortSignal
,
):
Promise
<
Misskey
.
api
.
SwitchCaseResponseType
<
E
,
P
>
>
{
):
Promise
<
_ResT
>
{
if
(
endpoint
.
includes
(
'
://
'
))
throw
new
Error
(
'
invalid endpoint
'
);
pendingApiRequestsCount
.
value
++
;
...
...
@@ -23,7 +28,7 @@ export function misskeyApi<E extends keyof Misskey.Endpoints, P extends Misskey.
pendingApiRequestsCount
.
value
--
;
};
const
promise
=
new
Promise
<
Misskey
.
Endpoints
[
E
][
'
res
'
]
|
void
>
((
resolve
,
reject
)
=>
{
const
promise
=
new
Promise
<
_ResT
>
((
resolve
,
reject
)
=>
{
// Append a credential
if
(
$i
)
(
data
as
any
).
i
=
$i
.
token
;
if
(
token
!==
undefined
)
(
data
as
any
).
i
=
token
;
...
...
@@ -44,7 +49,7 @@ export function misskeyApi<E extends keyof Misskey.Endpoints, P extends Misskey.
if
(
res
.
status
===
200
)
{
resolve
(
body
);
}
else
if
(
res
.
status
===
204
)
{
resolve
(
);
resolve
(
undefined
as
_ResT
);
// void -> undefined
}
else
{
reject
(
body
.
error
);
}
...
...
@@ -57,10 +62,15 @@ export function misskeyApi<E extends keyof Misskey.Endpoints, P extends Misskey.
}
// Implements Misskey.api.ApiClient.request
export
function
misskeyApiGet
<
E
extends
keyof
Misskey
.
Endpoints
,
P
extends
Misskey
.
Endpoints
[
E
][
'
req
'
]
>
(
export
function
misskeyApiGet
<
ResT
=
void
,
E
extends
keyof
Misskey
.
Endpoints
=
keyof
Misskey
.
Endpoints
,
P
extends
Misskey
.
Endpoints
[
E
][
'
req
'
]
=
Misskey
.
Endpoints
[
E
][
'
req
'
],
_ResT
=
ResT
extends
void
?
Misskey
.
api
.
SwitchCaseResponseType
<
E
,
P
>
:
ResT
,
>
(
endpoint
:
E
,
data
:
P
=
{}
as
any
,
):
Promise
<
Misskey
.
api
.
SwitchCaseResponseType
<
E
,
P
>
>
{
):
Promise
<
_ResT
>
{
pendingApiRequestsCount
.
value
++
;
const
onFinally
=
()
=>
{
...
...
@@ -69,7 +79,7 @@ export function misskeyApiGet<E extends keyof Misskey.Endpoints, P extends Missk
const
query
=
new
URLSearchParams
(
data
as
any
);
const
promise
=
new
Promise
<
Misskey
.
Endpoints
[
E
][
'
res
'
]
|
void
>
((
resolve
,
reject
)
=>
{
const
promise
=
new
Promise
<
_ResT
>
((
resolve
,
reject
)
=>
{
// Send request
window
.
fetch
(
`
${
apiUrl
}
/
${
endpoint
}
?
${
query
}
`
,
{
method
:
'
GET
'
,
...
...
@@ -81,7 +91,7 @@ export function misskeyApiGet<E extends keyof Misskey.Endpoints, P extends Missk
if
(
res
.
status
===
200
)
{
resolve
(
body
);
}
else
if
(
res
.
status
===
204
)
{
resolve
(
);
resolve
(
undefined
as
_ResT
);
// void -> undefined
}
else
{
reject
(
body
.
error
);
}
...
...
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