From 920f779ce3ac63d9032d18492b64f104678b8bd3 Mon Sep 17 00:00:00 2001 From: Dominik Menke Date: Sun, 20 Mar 2022 19:38:24 +0100 Subject: [PATCH] docs: describe reference store --- README.md | 118 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 6d82ba8..e2f4f3e 100644 --- a/README.md +++ b/README.md @@ -450,57 +450,87 @@ A reference hash is simply the Base64-encoded SHA256 checksum of the file conten "sha256:". (Canonically, we use the URL-safe alphabet without padding for the Base64 encoder, but texd also accepts the standard alphabet, and padding characters are ignored in both cases.) -
Python script to generate reference hashes (click to open details) +To *use* a file reference, you need to set a special content type in the request, and include the +reference hash instead of the file contents. The content type must be `pplication/x.texd; ref=use`. -```python -#!/usr/bin/python3 -""" -Save this file as texd-refhash.py, and call it like to: +The resulting HTTP request should then look something like this: - python3 texd-refhash.py FILE [FILE2 [...]] +```http +POST /render HTTP/1.1 +Content-Type: multipart/form-data; boundary=boundary + +--boundary +Content-Disposition: form-data; name=input.tex; filename=input.tex +Content-Type: application/octet-stream -This will print the texd file reference hash for FILE, FILE2, etc., each -on a separate line. -""" +[content of input.tex omitted] +--boundary +Content-Disposition: form-data; name=logo.pdf; filename=logo.pdf +Content-Type: application/x.texd; ref=use -from base64 import urlsafe_b64encode -from hashlib import sha256 -from sys import argv +sha256:p5w-x0VQUh2kXyYbbv1ubkc-oZ0z7aZYNjSKVVzaZuo= +--boundary-- +``` -def refhash(filename: str): - h = sha256() - with open(filename, 'rb') as f: - for block in iter(lambda: f.read(4096), b''): - h.update(block) +For unknown reference hashes, texd will respond with an error, and list all unknown references: - digest = urlsafe_b64encode(h.digest()).decode('ascii') - return f'sha256:{digest}' +```http +HTTP/1.1 422 Unprocessable Entity +Content-Type: application/json -if __name__ == '__main__': - for file in argv[1:]: - print(refhash(file)) +{ + "category": "reference", + "error": "unknown file references", + "reference": [ + "sha256:p5w-x0VQUh2kXyYbbv1ubkc-oZ0z7aZYNjSKVVzaZuo=" + ] +} ``` -
+In such a case, you can repeat you HTTP request, and change the `ref=use` to `ref=store` for +matching documents: -To *use* a file reference, you need to set a special content type in the request (calculated -using the script above), and include the reference hash instead of the file contents: +```http +POST /render HTTP/1.1 +Content-Type: multipart/form-data; boundary=boundary -```console -$ python3 texd-refhash.py ../Hausschrift.otf | curl -X POST \ - -F "input.tex=