diff --git a/src/lambda/get-comments/index.py b/src/lambda/get-comments/index.py index f3a5eb7a8..09dbd625e 100644 --- a/src/lambda/get-comments/index.py +++ b/src/lambda/get-comments/index.py @@ -1,7 +1,9 @@ +from encodings import utf_8 from boto3.dynamodb.conditions import Key from utils import JsonPayloadBuilder from utils import resp_handler from utils import table +from utils import uid_encoder @resp_handler @@ -12,13 +14,12 @@ def get_comments(thread_id, uid=""): r["mod"] = False if r["uid"] == uid: r["mod"] = True - del r["uid"] + r["uid"] = uid_encoder(uid) body = JsonPayloadBuilder().add_status( True).add_data(results).add_message('').compile() return body - def handler(event, context): params = { "thread_id": event["pathParameters"]["thread_id"], diff --git a/src/lambda/get-comments/utils.py b/src/lambda/get-comments/utils.py index 05f0218dc..c3711632b 100644 --- a/src/lambda/get-comments/utils.py +++ b/src/lambda/get-comments/utils.py @@ -3,6 +3,7 @@ import logging import os from decimal import Decimal +import hashlib db = boto3.resource("dynamodb", region_name="ap-northeast-1") table = db.Table(os.getenv('TABLE_NAME')) @@ -32,6 +33,18 @@ def add_message(self, msg): def compile(self): return json.dumps(self.payload, cls=DecimalEncoder, ensure_ascii=False).encode('utf8') + +# New code for returning encoded uid +def uid_encoder(uid): + """Trnasform the uid so that it does not resemble the original one + + :param uid: Original uid + :return: Sha256 encoded uid + """ + hashed_uid = hashlib.sha256(uid.encode()).hexdigest() + transformed_uid = hashed_uid + # transformed_uid = hashed_uid[:6] #! Might cause collision if shorten it + return transformed_uid def api_response(code, body): diff --git a/src/lambda/sync-image/index.py b/src/lambda/sync-image/index.py index 1c23dc62c..48ad0ab2b 100644 --- a/src/lambda/sync-image/index.py +++ b/src/lambda/sync-image/index.py @@ -16,6 +16,7 @@ def post_imgskey(key): item = { 'board_id': board_id, 'ad_id': ad_id, + # Do not use `{}` to enclose the item, it will make it into a SS type which will cause error 'timestamp': dt_now }