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

refactor(backend): replace punyHost with new URL().host #15164

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

saschanaz
Copy link
Member

@saschanaz saschanaz commented Dec 21, 2024

What

タイトル通り

Closes #15163

Why

コード量を減らすため

Additional info (optional)

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@github-actions github-actions bot added the packages/backend Server side specific issue/PR label Dec 21, 2024
Copy link
Contributor

github-actions bot commented Dec 21, 2024

このPRによるapi.jsonの差分
差分はありません。
Get diff files from Workflow Page

Copy link

codecov bot commented Dec 21, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 39.94%. Comparing base (f123be3) to head (da3fd90).

Files with missing lines Patch % Lines
...end/src/core/activitypub/models/ApPersonService.ts 60.00% 4 Missing ⚠️
...s/backend/src/core/activitypub/ApRequestService.ts 0.00% 1 Missing ⚠️
.../backend/src/core/activitypub/ApResolverService.ts 0.00% 1 Missing ⚠️
...ckend/src/core/activitypub/models/ApNoteService.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #15164      +/-   ##
===========================================
- Coverage    39.95%   39.94%   -0.01%     
===========================================
  Files         1563     1563              
  Lines       197878   197869       -9     
  Branches      3635     3631       -4     
===========================================
- Hits         79059    79047      -12     
- Misses      118215   118217       +2     
- Partials       604      605       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kakkokari-gtyih
Copy link
Contributor

別に用意されていたということはなにか事情があった可能性があるので、URL.hostと完全に等価なものかどうかを確認する必要がありそう

@u1-liquid
Copy link
Contributor

https://url.spec.whatwg.org/#host-serializing によると ASCII String (punycode化された文字列)が返されることになっているので、等価なものとして扱っていいと思います

@kakkokari-gtyih
Copy link
Contributor

MisskeyIO#858 のほうが良いかも

@saschanaz
Copy link
Member Author

this.utilityService.extractHost(url) より new URL(url).hostの方が短いし、できるならvanilla JSで書いて読みやすくしたいかも

Copy link
Member

@samunohito samunohito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実装に問題は無いと思うのでApproveします!


…が、少々に気になった点があります。感覚的な要素が強いので無視していただいても構いません。

if (new URL(url).host !== new URL(note.id).host) {

の表記は、new、スペース、大文字の連続、パラメータ、newで作成されるオブジェクトのプロパティ…というように、全体的な文字数は減っているものの、かえって複雑になっている印象を受けます。

なので、utilityService.punyHostの関数定義はそのまま残しておき、この関数の中身を

public punyHost(url: string): string {
  new new URL(url).host;
}

のようにするのはいかがでしょうか…?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages/backend Server side specific issue/PR
Projects
Status: Approved
Development

Successfully merging this pull request may close these issues.

Replace UtilityService.punyHost(url) with new URL(url).host
4 participants