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

✨ feat: import settings from url #2226

Merged
merged 11 commits into from Apr 30, 2024
Merged

Conversation

cy948
Copy link
Contributor

@cy948 cy948 commented Apr 26, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • ⚡️ perf
  • 📝 docs

🔀 变更说明 | Description of Change

支持从 URL search params 中导入全局设置,目前支持的设置有:

  • languageModel: 设置语言模型的设置;

除此设置外,其他设置尚未补充测试用例验证参数正确性,期待贡献;

代码变更:

  • src/const/url.ts: 添加了标识 search param 参数名的constant;
  • src/services/share.ts:增加了将 “设置从URL导入” 或 “导出设置到URL” 功能的方法;
  • 🧪 src/services/__tests__/share.test.ts :为上述方法补充测试;
  • src/hooks/useImportConfig.ts: 添加调用 shareService 中的方法进行解析的 hook;
  • src/layout/GlobalProvider/StoreInitialization.tsx:获取 search params ,调用 hook 进行解析并导入。

📝 补充信息 | Additional Information

  1. Use Case
  • settings 使用 encodeURI(JSON.stringify(settings)), 转化为 URL:
      const settings: DeepPartial<GlobalSettings> = {
        languageModel: {
          openai: {
            apiKey: 'user-key',
          },
        },
      };
      const url = shareGPTService.createShareSettingsUrl(settings);
      expect(url).toBe(
        `/?${LOBE_URL_IMPORT_NAME}=%7B%22languageModel%22:%7B%22openai%22:%7B%22apiKey%22:%22user-key%22%7D%7D%7D`,
      );
  • 使用该 URL 配合任意页面路径均能完成设置导入。
  1. Limitations
  • 当前feat不足1:目前是静默全部导入的,用户没有选择部分导入设置的方法,未来需要有界面能够让用户选择性地从URL中导入设置,或分享设置;
  • 当前feat不足2:导入时可能包含一些会令产生系统崩溃的设置,没有能够从禁止用户导入某些设置;
  1. Thanks
  • 感谢 @arvinxx 对 Store Initialization 的重构,使这个需求能够得到实现;
  1. Preview

Copy link

vercel bot commented Apr 26, 2024

@cy948 is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@lobehubbot
Copy link
Member

👍 @cy948

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.84%. Comparing base (8900445) to head (a18ee57).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #2226    +/-   ##
========================================
  Coverage   92.83%   92.84%            
========================================
  Files         290      290            
  Lines       16613    16641    +28     
  Branches     1196     1928   +732     
========================================
+ Hits        15423    15450    +27     
- Misses       1190     1191     +1     

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

src/services/share.ts Outdated Show resolved Hide resolved
src/hooks/useImportConfig.ts Outdated Show resolved Hide resolved
@arvinxx
Copy link
Contributor

arvinxx commented Apr 29, 2024

@cy948 我在 #2264 重构了 globalStore,需要你对应改下 globalStore 的调用了,setSettings 挪到 userStore 里了

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@cy948 I reconstructed globalStore in #2264. You need to change the call of globalStore accordingly. SetSettings has been moved to userStore.

src/hooks/useSTT.ts Outdated Show resolved Hide resolved
@arvinxx
Copy link
Contributor

arvinxx commented Apr 30, 2024

@arvinxx 我试了下还是改成用 hash 吧,不要用 search 。search 会被服务端感知到,然后可能会有水合问题。

image

但是 hash 的话只会在client 被感知,这样可以减少相关的调用问题。

Copy link

vercel bot commented Apr 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-community ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 30, 2024 3:36pm

@arvinxx arvinxx merged commit b1f6c20 into lobehub:main Apr 30, 2024
6 checks passed
@lobehubbot
Copy link
Member

❤️ Great PR @cy948 ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

github-actions bot pushed a commit that referenced this pull request Apr 30, 2024
## [Version&nbsp;0.152.0](v0.151.11...v0.152.0)
<sup>Released on **2024-04-30**</sup>

#### ✨ Features

- **misc**: Import settings from url.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Import settings from url, closes [#2226](#2226) ([b1f6c20](b1f6c20))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

🎉 This PR is included in version 0.152.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request Apr 30, 2024
## [Version&nbsp;1.32.0](v1.31.3...v1.32.0)
<sup>Released on **2024-04-30**</sup>

#### ✨ Features

- **misc**: Import settings from url.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Import settings from url, closes [lobehub#2226](https://github.com/bentwnghk/lobe-chat/issues/2226) ([b1f6c20](b1f6c20))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@cy948 cy948 deleted the feat/url-import-settings branch May 1, 2024 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants