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: use vapor to start local http server #619

Merged
merged 27 commits into from
Aug 6, 2024
Merged

feat: use vapor to start local http server #619

merged 27 commits into from
Aug 6, 2024

Conversation

tisfeng
Copy link
Owner

@tisfeng tisfeng commented Jul 22, 2024

Close #580

@tisfeng tisfeng marked this pull request as draft July 22, 2024 14:59
@tisfeng
Copy link
Owner Author

tisfeng commented Aug 3, 2024

This PR initially uses vapor to implement Easydict as a local server, currently supporting two APIs: translate and streamTranslate (Debug).

Usage:

curl -X POST http://localhost:8080/translate \
-H "Content-Type: application/json" \
-d '{
    "text": "good",
    "targetLanguage": "zh-Hans",
    "serviceType": "Apple"
}'
81106 24827

@tisfeng
Copy link
Owner Author

tisfeng commented Aug 3, 2024

streamTranslate API

curl -X POST http://localhost:8080/streamTranslate \
-H "Content-Type: application/json" \
-d '{
    "text": "Then I'\''d take you home, slip off your little black dress and just piledrive you into oblivion.~",
    "targetLanguage": "zh-Hans",
    "serviceType": "CustomOpenAI"
}'
83104

@tisfeng
Copy link
Owner Author

tisfeng commented Aug 3, 2024

AppleDictionary

curl -X POST http://localhost:8080/translate \
-H "Content-Type: application/json" \
-d '{
    "targetLanguage": "zh-Hans",
    "text": "easy",
    "serviceType": "AppleDictionary",
    "appleDictionaryNames": ["牛津英汉汉英词典", "朗文当代高级英语辞典"]
}'
26108

@tisfeng tisfeng marked this pull request as ready for review August 3, 2024 03:51
@tisfeng
Copy link
Owner Author

tisfeng commented Aug 3, 2024

I used Cloudflare Tunnel to publish the Easydict local server to the web https://easydict.izual.me , just for fun, don't guarantee 🙂

curl -X POST https://easydict.izual.me/translate \
-H "Content-Type: application/json" \
-d '{
    "targetLanguage": "zh-Hans",
    "text": "good",
    "serviceType": "Apple"
}'

Easydict/App/Localizable.xcstrings Outdated Show resolved Hide resolved
@tisfeng tisfeng merged commit 2546f4d into dev Aug 6, 2024
5 checks passed
@tisfeng tisfeng deleted the http-server branch August 6, 2024 14:29
@tisfeng
Copy link
Owner Author

tisfeng commented Aug 6, 2024

Later, I plan to add a few more APIs, such as:

  • detect: Identify the language of the text;
  • selectedText: Get the currently selected text;
  • ocr: Perform OCR on images and return the text in the images.

If anyone is interested in this feature or writing a server in Swift vapor , you can give it a try.

@tisfeng
Copy link
Owner Author

tisfeng commented Aug 11, 2024

Added support for ocr api a8a018f

71010 ocr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants