HTTP API for capture, pause and change engine#75
Open
meh3lp wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Use the built-in http.server to expose:
state_handlers.engine_change_handlerstate_handlers.pause_handlerscreenshot_request_queue.putServe new file
api.htmlcontaining API documentation on GET requestsAdd api-related options to config:
api_enabled = Falseapi_host = localhostapi_port = 7332Why
Though this can have a variety of applications, the goal is to provide another solution for keybinds on wayland as most DEs I know of offer a native way to bind keys to custom commands.
For example, this can be used on hyprland to bind screenshot capture to Ctrl+Alt+O:
~/.config/hypr/hyprland.confbind = Ctrl+Alt, O, exec, curl -X POST http://localhost:7332/action/captureLimitations
The documentation file is read at path
owocr/api.htmlwhich works in dev environment, but I haven't tested if it will work in a build and I did not dive deep enough into the codebase to figure it out.content = Path("owocr/api.html").read_bytes()If it turns out to cause issues consider reverting commit 4e5346 and only keeping commit eca493 which contains the core post request handlers.
There is no authentication, meaning the server blindly trusts any request it receives. While none of the exposed functionality is immediately exploitable and I expect users to have the server behind a firewall anyway, implementing authentication should be a consideration if the API functionality is expanded in the future.
This pull request only implements handlers necessary to fix keybinds on wayland, more work is needed to expose full control over all features of owocr
The built-in http.server is not suited for anything remotely complex, so if there's ever need for more API features the thing better be rewritten with flask of fastapi