xiaoyifang / goldendict-ng

The Next Generation GoldenDict
https://xiaoyifang.github.io/goldendict-ng/
Other
1.48k stars 80 forks source link

[to do ] add an embed http server in goldendict #229

Open xiaoyifang opened 1 year ago

xiaoyifang commented 1 year ago

like the implementation in kiwix image

the benifit of this feature:

  1. can turn the goldendict into an online dictionary search engine. with the help such as ngnix ,can offer service to the internet users.
  2. can make command line implementation easier related to the issues like https://github.com/goldendict/goldendict/issues/618 https://github.com/goldendict/goldendict/issues/37
xiaoyifang commented 1 year ago

The "structured results" I mean something that can be provided as JSON/XML API:

Merriam-Webster's API doc: https://dictionaryapi.com/products/json <- this one is pretty good. Cambridge's API: https://dictionary-api.cambridge.org/api/specification

provide an unified structure is difficult and will cost too much effort and time . This can be set as an new feature alone.

about the embed http server, My initial purpose is to offer the search result through website. and can simply convert html to plain text to satisfy the CLI.

xiaoyifang commented 1 year ago

a video demo?

Anyway this is great if this can be implemented , and should we switch GPL license to AGPL ,as GPL does not provide webservice protection.

With this and nginx, goldendict can be served as a common dictionary server. and I think it can easily embed be as an external local service for other applications.

xiaoyifang commented 1 year ago

Some steps(In future maybe):

xiaoyifang commented 1 year ago

https://github.com/civetweb/civetweb https://github.com/etr/libhttpserver

shenlebantongying commented 1 year ago

I tried civetweb and made another one:

https://github.com/SourceReviver/civetweb_qt_demo

The code includes serving a QImage generated via libcairo.

We just need to reinvent qrc:// with http://

Video:

Peek 2023-04-28 08-08

civetweb is a fork of mangoose, but they are very different now. Mangoose only provides a mechanism to do multi threads, while civetweb manages threads on its own :sweat_smile:.

TAbdiukov commented 6 months ago

WOW I'm glad I discovered this issue thread. I've been waiting for this feature on official GoldenDict repo on and off for 5+ years!

I'm happy to help. Note that regarding GoldenDict, I know more from a user's (and not a developer's) perspective,

Some steps(In future maybe):

  1. change the goldendict's inner protocol to some common http url ,such as http://xxxxxx:/query?originurl=gdlookup:xxxxxx
  2. handle these http request and redirect to gd's inner process logic.

I think this idea stems from this comment of mine. Yes, GoldenDict (for PC at least) uses this gdlookup protocol. IMO, what's important is that:

  1. Its response is HTML, just like HTTP, it's (almost) the same as HTTP in a browser. In fact, GoldenDict for Android requires a WebView engine (either Android Stock or Google Chrome), so GoldenDict sort or internally uses browser functionality. It may require extra CSS and JS, but more or less, it's simple.
  2. Just feeding input to originurl can be a bad idea, because it would likely be possible to inject a command like gdlookup:xyz && cat /../../etc/passwd. Maybe some sanitization can be a good idea.

I know that there is an HTTP server implementation for another dictionary format, SLOB (Sorted BLOB, which is little known), you can check its implementation here, itkach/aard2-web . It uses Java.

Anyway, I'm subscribing to this issue, because I want to see this idea get implemented =)

shenlebantongying commented 6 months ago

While I no longer have time to work on this, I think a reasonable path would be to decouple dict-related code into an independent module/library. Think about it, we can create a python binding to it, and creating a web interface would be as simple as dumping results into an HTML template.

https://github.com/xiaoyifang/goldendict-ng/issues/905

The design of existing code does not consider anything else other than working with the Qt GUI. It is a lot of labour work.

BTW, I highly doubt anyone would want to learn the unnecessary internal indexing implementation used by Goldedict. It has been good for years and does a good job for the original/first GD developer to practice implementing the algorithm after university, but why not use something that is well studied and well known, like sqlite. The core value of GD is obviously not implementing yet another mini database :sweat_smile:

https://github.com/xiaoyifang/goldendict-ng/issues/562

Sorry for just talking and doing nothing, but I do think the above two issues have to be solved first, and the HTTP frontend would be as easy as writing a short script.

kanjieater commented 2 months ago

Also would like to express interest in this. I've been requesting a way to have a dictionary api locally since 2019 along with TAbdiukov 😅

guitarlive722 commented 1 week ago

Some steps(In future maybe):

请问目前有实现计划吗?

xiaoyifang commented 1 week ago

Maybe decouple this into serveral little projects/goals. Need time to rethink.

image