diff --git a/cgi-bin/play_recording.py b/cgi-bin/play_recording.py new file mode 100755 index 0000000..e841f94 --- /dev/null +++ b/cgi-bin/play_recording.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +""" +Created on Sat Mar 28 19:29:28 2020 + +This module implements a CGI service for uploading voice records in the coughvid web application. + +@author: T. Teijeiro +""" +import cgi +import glob +import sys +import os.path +#TODO disable cgitb in production +# import cgitb +# cgitb.enable() + +#Point this variable to the folder where the data will be stored +DB_PATH = '/tmp' + +form = cgi.FieldStorage() +#First we check if we are receiving a recording or metadata +rec_id = form.getvalue('id') +if rec_id is not None: + files = glob.glob(f'{DB_PATH}/{rec_id}_*') + if len(files) == 1: + file = files[0] + _, ext = os.path.splitext(file) + if len(ext) > 1: + with open(file, 'rb') as f: + print(f"Content-Type: audio/{ext[1:]}\n") + sys.stdout.flush() + sys.stdout.buffer.write(f.read()) + sys.exit(0) +print(f"""\ +Content-Type: text/html\n + + +

Unexpected.

+ + +""")