Giter VIP home page Giter VIP logo

klearsky's Introduction

三 🦀

$$\ce{$\unicode[goombafont; color:red; pointer-events: none; z-index: -10; position: fixed; top: 0; left: 0; height: 100vh; object-fit: cover; background-size: cover; width: 100vw; opacity: 0.5; background: url('https://raw.githubusercontent.com/Andrew-Pynch/Andrew-Pynch/main/pattern.png');]{x0000}$}$$

klearsky's People

Contributors

burningtree avatar mimonelu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

klearsky's Issues

[enhancement] Add option to remove label warnings

Label warnings on posts that have some NSFW content are too distracting and don't make sense to anyone who has selected the option to show this content in content filtering.

It would be interesting to add an option to remove them.

[Bug] メールアドレスに"+"記号が含まれている場合に、翻訳機能が正しく機能せず「INVALID EMAIL PROVIDED」と表示される

Klearsky上で「翻訳する」ボタンを押した場合、KlearskyはMyMemoryを使用して翻訳を行います。この時、deパラメータにアカウントに使っているメールアドレスが指定されるのですが、このメールアドレス内の+がパーセントエンコーディングされていないために、以下のようなレスポンスが返ってきてしまいます:

{
    "responseData": {
        "translatedText": "INVALID EMAIL PROVIDED"
    },
    "quotaFinished": null,
    "mtLangSupported": null,
    "responseDetails": "INVALID EMAIL PROVIDED",
    "responseStatus": "403",
    "responderId": null,
    "exception_code": null,
    "matches": ""
}

URLのクエリストリングにおいて、+ を意味します。しかし、Klearskyはメールアドレス内の+%2Bに置換しません。このためMyMemoryには が含まれるメールアドレスと認識され、「誤ったメールアドレス」と判定されるようです。

該当するコードは以下になります。encodeURIComponentによる変換処理は、mainState.atp.session?.emailにも必要です

const url = `https://api.mymemory.translated.net/get?q=${encodeURIComponent(text)}&langpair=${langpair}|${dstLanguage}&de=${mainState.atp.session?.email}`

Note
なお、encodeURIComponentによる変換は不完全です。RFC3986に基づく「URL内で許可されていない文字」の一部(!'()*)を変換しません。
参照:encodeURIComponentが世界基準だと誤解してた話 - Qiita
これによる問題はおそらく無いはずですが、念のために

  • URLの組み立てに文字列結合とencodeURIComponentを使わず、URLオブジェクトURLSearchParamsオブジェクトを使う

    const url = new URL("https://api.mymemory.translated.net/get");
    url.searchParams.set("q", text);
    url.searchParams.set("langpair", `${langpair}|${dstLanguage}`);
    url.searchParams.set("de", mainState.atp.session?.email);
    const response = await fetch(url).catch(() => { // Note: fetch関数はURLオブジェクトを直接受け取れるため、url.toString()メソッドで文字列化する必要はありません
    ...
    const url = new URL("https://api.mymemory.translated.net/get");
    // Note: url.searchParamsプロパティは読み取り専用なので、代わりにurl.searchプロパティに代入して上書きします
    url.search = new URLSearchParams({
      q: text,
      langpair: `${langpair}|${dstLanguage}`,
      de: mainState.atp.session?.email,
    }).toString();
    const response = await fetch(url).catch(() => {
    ...
    const url = `https://api.mymemory.translated.net/get?`${new URLSearchParams({
      q: text,
      langpair: `${langpair}|${dstLanguage}`,
      de: mainState.atp.session?.email,
    }).toString()}`;
    const response = await fetch(url).catch(() => {
    ...
  • encodeURIComponentの代わりにstrict-uri-encodeのようなRFC3986準拠のエンコード関数を使う

のどちらかが良いかもしれません。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.