Skip to content

feat(cli): add --scheme and --with-name to the send URL - #398

Open
claudiodangelis wants to merge 1 commit into
mainfrom
scheme-with-name
Open

claudiodangelis wants to merge 1 commit into
mainfrom
scheme-with-name

Conversation

@claudiodangelis

Copy link
Copy Markdown
Owner

Closes #397.

Some apps download files from links with their own scheme, and some need the URL to end with the name of the file. For example, the Zepp app installs watch faces on Amazfit watches from QR codes of links like zpkd1://host/path/watchface.zpk. This adds two independent options to send:

  • --scheme puts another scheme in the send URL instead of http or https. It only changes the URL: the server still uses HTTP, or HTTPS with --secure. The URL used to open the QR code in the browser (--browser) and the receive URL are unchanged. Invalid schemes (per RFC 3986) are rejected, and a trailing :// is ignored.
  • --with-name / -w adds the name of the file, escaped, to the end of the send URL, e.g. /send/abc/watchface.zpk. Only that exact name is served; the URL without the name keeps working.
qrcp --scheme zpkd1 -w watchface.zpk
# zpkd1://192.168.1.10:8080/send/abc/watchface.zpk

Both work with qrcp and qrcp send (not receive), and can be set in the configuration file (scheme, withName) or with QRCP_SCHEME and QRCP_WITHNAME. The README documents them in a new "Links for Other Apps" section.

Tests

  • server/url_test.go: scheme validation; the scheme only changes SendURL, and the file is still served over HTTP; the default URL has no name and the named URL isn't served without -w; with -w the file is served at its name, which is escaped (spaces, %, #, ?, non-ASCII), only the exact name is served, and the URL follows a new Send; both options together; receive is unchanged.
  • config/load_test.go: the keys are read from the file and the environment, flags override them, and the defaults are unchanged.
  • cmd/send_test.go: both qrcp and qrcp send take the flags, -w is --with-name, receive doesn't take them, and they are parsed.
  • CI: a new e2e step on Linux and macOS runs qrcp --scheme zpkd1 -w "watch face.zpk", checks the printed URL and downloads the file over HTTP.

Not verified

Whether the Zepp app downloads zpkd1:// links over plain HTTP from a local server; the issue author is asked to try it.

Some apps download files from links with their own scheme, and need the
URL to end with the name of the file: the Zepp app installs watch faces
on Amazfit watches from QR codes of links like
zpkd1://host/path/watchface.zpk (#397).

- --scheme puts another scheme in the send URL instead of http or https.
  It only changes the URL: the server still uses http, or https with
  --secure, and the URL used to open the QR code in the browser and the
  receive URL are unchanged. Invalid schemes are rejected.
- --with-name (-w) adds the name of the file, escaped, to the end of the
  send URL. Only that exact name is served; the URL without the name
  keeps working.

The two are independent, both work with qrcp and qrcp send, and can be
set in the configuration file (scheme, withName) or with QRCP_SCHEME and
QRCP_WITHNAME. The CI e2e jobs check both on Linux and macOS.

This branch has not been deployed

No deployments
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.

Ability to change the protocol in the address string

1 participant