in background/function/main.py [0:0]
def document_name(message):
""" Messages are saved in a Firestore database with document IDs generated
from the original string and destination language. If the exact same
translation is requested a second time, the result will overwrite the
prior result.
message - a dictionary with fields named Language and Original, and
optionally other fields with any names
Returns a unique name that is an allowed Firestore document ID
"""
key = '{}/{}'.format(message['Language'], message['Original'])
hashed = hashlib.sha512(key.encode()).digest()
# Note that document IDs should not contain the '/' character
name = base64.b64encode(hashed, altchars=b'+-').decode('utf-8')
return name