Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misskey-js: fallback to Content-Type: application/json for unknown endpoints #14502

Closed
1 task
zyoshoka opened this issue Sep 5, 2024 · 2 comments · Fixed by #14508
Closed
1 task

misskey-js: fallback to Content-Type: application/json for unknown endpoints #14502

zyoshoka opened this issue Sep 5, 2024 · 2 comments · Fixed by #14508
Labels
✨Feature This adds/improves/enhances a feature

Comments

@zyoshoka
Copy link
Contributor

zyoshoka commented Sep 5, 2024

Summary

2024.7.0 以降では、misskey-js の APIClient で request する際、エンドポイントに対応する Content-Type を渡す仕様になっています:

'Content-Type': endpointReqTypes[endpoint],

しかし、この仕様では misskey-js が知らない /api/signup といったエンドポイントを叩こうとした際に(対応する Content-Type がないため)415 エラーが返ってしまい少々不便です。こういった際には 2024.5.0 以前と同じように Content-Type: application/json になるようにしたいです。実際ほとんどのエンドポイントについて application/json であるため一定の合理性があると思います:

export const endpointReqTypes: Record<keyof Endpoints, 'application/json' | 'multipart/form-data'> = {
'admin/meta': 'application/json',
'admin/abuse-user-reports': 'application/json',
'admin/abuse-report/notification-recipient/list': 'application/json',
'admin/abuse-report/notification-recipient/show': 'application/json',
'admin/abuse-report/notification-recipient/create': 'application/json',
'admin/abuse-report/notification-recipient/update': 'application/json',
'admin/abuse-report/notification-recipient/delete': 'application/json',
'admin/accounts/create': 'application/json',
'admin/accounts/delete': 'application/json',
'admin/accounts/find-by-email': 'application/json',
'admin/ad/create': 'application/json',
'admin/ad/delete': 'application/json',
'admin/ad/list': 'application/json',
'admin/ad/update': 'application/json',
'admin/announcements/create': 'application/json',
'admin/announcements/delete': 'application/json',
'admin/announcements/list': 'application/json',
'admin/announcements/update': 'application/json',
'admin/avatar-decorations/create': 'application/json',
'admin/avatar-decorations/delete': 'application/json',
'admin/avatar-decorations/list': 'application/json',
'admin/avatar-decorations/update': 'application/json',
'admin/delete-all-files-of-a-user': 'application/json',
'admin/unset-user-avatar': 'application/json',
'admin/unset-user-banner': 'application/json',
'admin/drive/clean-remote-files': 'application/json',
'admin/drive/cleanup': 'application/json',
'admin/drive/files': 'application/json',
'admin/drive/show-file': 'application/json',
'admin/emoji/add-aliases-bulk': 'application/json',
'admin/emoji/add': 'application/json',
'admin/emoji/copy': 'application/json',
'admin/emoji/delete-bulk': 'application/json',
'admin/emoji/delete': 'application/json',
'admin/emoji/import-zip': 'application/json',
'admin/emoji/list-remote': 'application/json',
'admin/emoji/list': 'application/json',
'admin/emoji/remove-aliases-bulk': 'application/json',
'admin/emoji/set-aliases-bulk': 'application/json',
'admin/emoji/set-category-bulk': 'application/json',
'admin/emoji/set-license-bulk': 'application/json',
'admin/emoji/update': 'application/json',
'admin/federation/delete-all-files': 'application/json',
'admin/federation/refresh-remote-instance-metadata': 'application/json',
'admin/federation/remove-all-following': 'application/json',
'admin/federation/update-instance': 'application/json',
'admin/get-index-stats': 'application/json',
'admin/get-table-stats': 'application/json',
'admin/get-user-ips': 'application/json',
'admin/invite/create': 'application/json',
'admin/invite/list': 'application/json',
'admin/promo/create': 'application/json',
'admin/queue/clear': 'application/json',
'admin/queue/deliver-delayed': 'application/json',
'admin/queue/inbox-delayed': 'application/json',
'admin/queue/promote': 'application/json',
'admin/queue/stats': 'application/json',
'admin/relays/add': 'application/json',
'admin/relays/list': 'application/json',
'admin/relays/remove': 'application/json',
'admin/reset-password': 'application/json',
'admin/resolve-abuse-user-report': 'application/json',
'admin/send-email': 'application/json',
'admin/server-info': 'application/json',
'admin/show-moderation-logs': 'application/json',
'admin/show-user': 'application/json',
'admin/show-users': 'application/json',
'admin/suspend-user': 'application/json',
'admin/unsuspend-user': 'application/json',
'admin/update-meta': 'application/json',
'admin/delete-account': 'application/json',
'admin/update-user-note': 'application/json',
'admin/roles/create': 'application/json',
'admin/roles/delete': 'application/json',
'admin/roles/list': 'application/json',
'admin/roles/show': 'application/json',
'admin/roles/update': 'application/json',
'admin/roles/assign': 'application/json',
'admin/roles/unassign': 'application/json',
'admin/roles/update-default-policies': 'application/json',
'admin/roles/users': 'application/json',
'admin/system-webhook/create': 'application/json',
'admin/system-webhook/delete': 'application/json',
'admin/system-webhook/list': 'application/json',
'admin/system-webhook/show': 'application/json',
'admin/system-webhook/update': 'application/json',
'announcements': 'application/json',
'announcements/show': 'application/json',
'antennas/create': 'application/json',
'antennas/delete': 'application/json',
'antennas/list': 'application/json',
'antennas/notes': 'application/json',
'antennas/show': 'application/json',
'antennas/update': 'application/json',
'ap/get': 'application/json',
'ap/show': 'application/json',
'app/create': 'application/json',
'app/show': 'application/json',
'auth/accept': 'application/json',
'auth/session/generate': 'application/json',
'auth/session/show': 'application/json',
'auth/session/userkey': 'application/json',
'blocking/create': 'application/json',
'blocking/delete': 'application/json',
'blocking/list': 'application/json',
'channels/create': 'application/json',
'channels/featured': 'application/json',
'channels/follow': 'application/json',
'channels/followed': 'application/json',
'channels/owned': 'application/json',
'channels/show': 'application/json',
'channels/timeline': 'application/json',
'channels/unfollow': 'application/json',
'channels/update': 'application/json',
'channels/favorite': 'application/json',
'channels/unfavorite': 'application/json',
'channels/my-favorites': 'application/json',
'channels/search': 'application/json',
'charts/active-users': 'application/json',
'charts/ap-request': 'application/json',
'charts/drive': 'application/json',
'charts/federation': 'application/json',
'charts/instance': 'application/json',
'charts/notes': 'application/json',
'charts/user/drive': 'application/json',
'charts/user/following': 'application/json',
'charts/user/notes': 'application/json',
'charts/user/pv': 'application/json',
'charts/user/reactions': 'application/json',
'charts/users': 'application/json',
'clips/add-note': 'application/json',
'clips/remove-note': 'application/json',
'clips/create': 'application/json',
'clips/delete': 'application/json',
'clips/list': 'application/json',
'clips/notes': 'application/json',
'clips/show': 'application/json',
'clips/update': 'application/json',
'clips/favorite': 'application/json',
'clips/unfavorite': 'application/json',
'clips/my-favorites': 'application/json',
'drive': 'application/json',
'drive/files': 'application/json',
'drive/files/attached-notes': 'application/json',
'drive/files/check-existence': 'application/json',
'drive/files/create': 'multipart/form-data',
'drive/files/delete': 'application/json',
'drive/files/find-by-hash': 'application/json',
'drive/files/find': 'application/json',
'drive/files/show': 'application/json',
'drive/files/update': 'application/json',
'drive/files/upload-from-url': 'application/json',
'drive/folders': 'application/json',
'drive/folders/create': 'application/json',
'drive/folders/delete': 'application/json',
'drive/folders/find': 'application/json',
'drive/folders/show': 'application/json',
'drive/folders/update': 'application/json',
'drive/stream': 'application/json',
'email-address/available': 'application/json',
'endpoint': 'application/json',
'endpoints': 'application/json',
'export-custom-emojis': 'application/json',
'federation/followers': 'application/json',
'federation/following': 'application/json',
'federation/instances': 'application/json',
'federation/show-instance': 'application/json',
'federation/update-remote-user': 'application/json',
'federation/users': 'application/json',
'federation/stats': 'application/json',
'following/create': 'application/json',
'following/delete': 'application/json',
'following/update': 'application/json',
'following/update-all': 'application/json',
'following/invalidate': 'application/json',
'following/requests/accept': 'application/json',
'following/requests/cancel': 'application/json',
'following/requests/list': 'application/json',
'following/requests/reject': 'application/json',
'gallery/featured': 'application/json',
'gallery/popular': 'application/json',
'gallery/posts': 'application/json',
'gallery/posts/create': 'application/json',
'gallery/posts/delete': 'application/json',
'gallery/posts/like': 'application/json',
'gallery/posts/show': 'application/json',
'gallery/posts/unlike': 'application/json',
'gallery/posts/update': 'application/json',
'get-online-users-count': 'application/json',
'get-avatar-decorations': 'application/json',
'hashtags/list': 'application/json',
'hashtags/search': 'application/json',
'hashtags/show': 'application/json',
'hashtags/trend': 'application/json',
'hashtags/users': 'application/json',
'i': 'application/json',
'i/2fa/done': 'application/json',
'i/2fa/key-done': 'application/json',
'i/2fa/password-less': 'application/json',
'i/2fa/register-key': 'application/json',
'i/2fa/register': 'application/json',
'i/2fa/update-key': 'application/json',
'i/2fa/remove-key': 'application/json',
'i/2fa/unregister': 'application/json',
'i/apps': 'application/json',
'i/authorized-apps': 'application/json',
'i/claim-achievement': 'application/json',
'i/change-password': 'application/json',
'i/delete-account': 'application/json',
'i/export-blocking': 'application/json',
'i/export-following': 'application/json',
'i/export-mute': 'application/json',
'i/export-notes': 'application/json',
'i/export-clips': 'application/json',
'i/export-favorites': 'application/json',
'i/export-user-lists': 'application/json',
'i/export-antennas': 'application/json',
'i/favorites': 'application/json',
'i/gallery/likes': 'application/json',
'i/gallery/posts': 'application/json',
'i/import-blocking': 'application/json',
'i/import-following': 'application/json',
'i/import-muting': 'application/json',
'i/import-user-lists': 'application/json',
'i/import-antennas': 'application/json',
'i/notifications': 'application/json',
'i/notifications-grouped': 'application/json',
'i/page-likes': 'application/json',
'i/pages': 'application/json',
'i/pin': 'application/json',
'i/read-all-unread-notes': 'application/json',
'i/read-announcement': 'application/json',
'i/regenerate-token': 'application/json',
'i/registry/get-all': 'application/json',
'i/registry/get-detail': 'application/json',
'i/registry/get': 'application/json',
'i/registry/keys-with-type': 'application/json',
'i/registry/keys': 'application/json',
'i/registry/remove': 'application/json',
'i/registry/scopes-with-domain': 'application/json',
'i/registry/set': 'application/json',
'i/revoke-token': 'application/json',
'i/signin-history': 'application/json',
'i/unpin': 'application/json',
'i/update-email': 'application/json',
'i/update': 'application/json',
'i/move': 'application/json',
'i/webhooks/create': 'application/json',
'i/webhooks/list': 'application/json',
'i/webhooks/show': 'application/json',
'i/webhooks/update': 'application/json',
'i/webhooks/delete': 'application/json',
'invite/create': 'application/json',
'invite/delete': 'application/json',
'invite/list': 'application/json',
'invite/limit': 'application/json',
'meta': 'application/json',
'emojis': 'application/json',
'emoji': 'application/json',
'miauth/gen-token': 'application/json',
'mute/create': 'application/json',
'mute/delete': 'application/json',
'mute/list': 'application/json',
'renote-mute/create': 'application/json',
'renote-mute/delete': 'application/json',
'renote-mute/list': 'application/json',
'my/apps': 'application/json',
'notes': 'application/json',
'notes/children': 'application/json',
'notes/clips': 'application/json',
'notes/conversation': 'application/json',
'notes/create': 'application/json',
'notes/delete': 'application/json',
'notes/favorites/create': 'application/json',
'notes/favorites/delete': 'application/json',
'notes/featured': 'application/json',
'notes/global-timeline': 'application/json',
'notes/hybrid-timeline': 'application/json',
'notes/local-timeline': 'application/json',
'notes/mentions': 'application/json',
'notes/polls/recommendation': 'application/json',
'notes/polls/vote': 'application/json',
'notes/reactions': 'application/json',
'notes/reactions/create': 'application/json',
'notes/reactions/delete': 'application/json',
'notes/renotes': 'application/json',
'notes/replies': 'application/json',
'notes/search-by-tag': 'application/json',
'notes/search': 'application/json',
'notes/show': 'application/json',
'notes/state': 'application/json',
'notes/thread-muting/create': 'application/json',
'notes/thread-muting/delete': 'application/json',
'notes/timeline': 'application/json',
'notes/translate': 'application/json',
'notes/unrenote': 'application/json',
'notes/user-list-timeline': 'application/json',
'notifications/create': 'application/json',
'notifications/flush': 'application/json',
'notifications/mark-all-as-read': 'application/json',
'notifications/test-notification': 'application/json',
'page-push': 'application/json',
'pages/create': 'application/json',
'pages/delete': 'application/json',
'pages/featured': 'application/json',
'pages/like': 'application/json',
'pages/show': 'application/json',
'pages/unlike': 'application/json',
'pages/update': 'application/json',
'flash/create': 'application/json',
'flash/delete': 'application/json',
'flash/featured': 'application/json',
'flash/like': 'application/json',
'flash/show': 'application/json',
'flash/unlike': 'application/json',
'flash/update': 'application/json',
'flash/my': 'application/json',
'flash/my-likes': 'application/json',
'ping': 'application/json',
'pinned-users': 'application/json',
'promo/read': 'application/json',
'roles/list': 'application/json',
'roles/show': 'application/json',
'roles/users': 'application/json',
'roles/notes': 'application/json',
'request-reset-password': 'application/json',
'reset-db': 'application/json',
'reset-password': 'application/json',
'server-info': 'application/json',
'stats': 'application/json',
'sw/show-registration': 'application/json',
'sw/update-registration': 'application/json',
'sw/register': 'application/json',
'sw/unregister': 'application/json',
'test': 'application/json',
'username/available': 'application/json',
'users': 'application/json',
'users/clips': 'application/json',
'users/followers': 'application/json',
'users/following': 'application/json',
'users/gallery/posts': 'application/json',
'users/get-frequently-replied-users': 'application/json',
'users/featured-notes': 'application/json',
'users/lists/create': 'application/json',
'users/lists/delete': 'application/json',
'users/lists/list': 'application/json',
'users/lists/pull': 'application/json',
'users/lists/push': 'application/json',
'users/lists/show': 'application/json',
'users/lists/favorite': 'application/json',
'users/lists/unfavorite': 'application/json',
'users/lists/update': 'application/json',
'users/lists/create-from-public': 'application/json',
'users/lists/update-membership': 'application/json',
'users/lists/get-memberships': 'application/json',
'users/notes': 'application/json',
'users/pages': 'application/json',
'users/flashs': 'application/json',
'users/reactions': 'application/json',
'users/recommendation': 'application/json',
'users/relation': 'application/json',
'users/report-abuse': 'application/json',
'users/search-by-username-and-host': 'application/json',
'users/search': 'application/json',
'users/show': 'application/json',
'users/achievements': 'application/json',
'users/update-memo': 'application/json',
'fetch-rss': 'application/json',
'fetch-external-resources': 'application/json',
'retention': 'application/json',
'bubble-game/register': 'application/json',
'bubble-game/ranking': 'application/json',
'reversi/cancel-match': 'application/json',
'reversi/games': 'application/json',
'reversi/match': 'application/json',
'reversi/invitations': 'application/json',
'reversi/show-game': 'application/json',
'reversi/surrender': 'application/json',
'reversi/verify': 'application/json',
};

Purpose

misskey-js が知らないエンドポイントを叩く際に不便なため。この操作が意図されていないのであれば close で問題ありません。

Do you want to implement this feature yourself?

  • Yes, I will implement this by myself and send a pull request
@zyoshoka zyoshoka added the ✨Feature This adds/improves/enhances a feature label Sep 5, 2024
@kakkokari-gtyih
Copy link
Contributor

generator自体もapplication/jsonではないエンドポイントのみを記録するほうがいい気がする

@zyoshoka
Copy link
Contributor Author

zyoshoka commented Sep 6, 2024

この issue の本題自体はインスタンス作成時に fetch を適当に指定すれば解決されることに気づいたので一旦 close にしようと思います。#14502 (comment) については別途対応お願いしたいです。

new Misskey.api.APIClient({
	origin,
	fetch: (input, init) => fetch(input, {
		...init,
		headers: {
			...init?.headers,
			'Content-Type': 'application/json',
		},
	}),
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨Feature This adds/improves/enhances a feature
Projects
None yet
2 participants