misskey-dev / misskey

🌎 A completely free and open interplanetary microblogging platform 🚀
https://misskey-hub.net/
GNU Affero General Public License v3.0
9.95k stars 1.35k forks source link

POST:admin/emoji/update​のパラメーターを一部指定で送信すると「name already exists」エラーが出る #14747

Closed mendakon closed 2 days ago

mendakon commented 3 days ago

💡 Summary

例えば以下のようなjsonで

{
    "id": "9yoba11106",
    "isSensitive": true
}

POST:admin/emoji/updateを使用して絵文字更新を行おうとすると、

{
    "error": {
        "message": "Internal error occurred. Please contact us if the error persists.",
        "code": "INTERNAL_ERROR",
        "id": "5d37dbcb-891e-41ca-a3d6-e690c97775ac",
        "kind": "server",
        "info": {
            "e": {
                "message": "name already exists",
                "code": "Error",
                "id": "63e11af7-e4c8-4a17-9f04-a698895e9697"
            }
        }
    }
}

というエラーが出る。

{
    "id": "9dohxjvw1t",
    "name": "kiken",
    "category": "文字",
    "aliases": [
        "危険",
        "きけん"
    ],
    "license": "made in sushi.ski",
    "isSensitive": true,
    "localOnly": false,
    "roleIdsThatCanBeUsedThisEmojiAsReaction": []
}

のような形式ですべての項目を指定すると正常に更新できる image

あと、apiドキュメントに、requiredの項目が存在しないのが気になる。(画像参照)意図的にそうしている可能性もありそうですが 赤丸のどれかがrequiredになるべきなのでは?

🥰 Expected Behavior

例え以下のようなjsonで

{
    "id": "9yoba11106",
    "isSensitive": true
}

部分的な指定でも正常にアップデートが行える

🤬 Actual Behavior

部分指定で、

{
    "id": "9yoba11106",
    "isSensitive": true
}

POST:admin/emoji/updateを使用して絵文字更新を行おうとすると、

{
    "error": {
        "message": "Internal error occurred. Please contact us if the error persists.",
        "code": "INTERNAL_ERROR",
        "id": "5d37dbcb-891e-41ca-a3d6-e690c97775ac",
        "kind": "server",
        "info": {
            "e": {
                "message": "name already exists",
                "code": "Error",
                "id": "63e11af7-e4c8-4a17-9f04-a698895e9697"
            }
        }
    }
}

というエラーが出る。

📝 Steps to Reproduce

  1. 設定からmisskeyの絵文字操作ができるapiキーを取得する
  2. 以下の内容でPOST /admin/emoji/updateエンドポイントにpostmanなどで対してリクエストを送信する。
    {
    "id": "9yoba11106",
    "isSensitive": true
    }
  3. 上記のリクエストに対してエラーレスポンスが返ってくる。

💻 Frontend Environment

* Model and OS of the device(s):
* Browser:chrome(というかapiリクエストはpostmanで送った)
* Server URL:https://sushi.ski
* Misskey:2024.10.0

🛰 Backend Environment (for server admin)

* Installation Method or Hosting Service:
* Misskey:2024.10.0
* Node:v20.11.0

Do you want to address this bug yourself?

FineArchs commented 2 days ago

私の開発環境で該当バージョン( 6de7c275221996011b03699a6f618909100cd44e )をチェックアウトして試したところ、APIコンソールとcurlでのリクエストは正常に完了しました。

# curlの例(bash)
curl -X POST -H "Content-Type: application/json" -d '{"id": "(省略)", "isSensitive": true, "i": "(省略)"}' localhost:3000/api/admin/emoji/update

postmanでは未確認です。

FineArchs commented 2 days ago

開発環境が絵文字一個という特殊な環境だったため絵文字を増やしてから実行したところ、該当エラーが再現できました。 https://github.com/misskey-dev/misskey/blob/d376aab45edc2170592a256a429a1d0b364bd7f5/packages/backend/src/core/CustomEmojiService.ts#L117 ここでnameがundefinedの検索が行われるのが原因と思われます。

samunohito commented 2 days ago

パラメータから引き込んだnameがundefinedのときはsameNameEmojiの取得及び重複チェックをしないようにする必要がありそうですね

FineArchs commented 2 days ago

apiドキュメントの方は、このエンドポイントが「"id"か"name"のどちらかが必要」なのでどちらにもrequiredがつかない感じです。 それ用の表示があればいいんですが、ドキュメント生成は外部ライブラリに頼っているので改善は難しそうです

mendakon commented 2 days ago

了解しました。ご対応ありがとうございました!!!