Skip to content

Commit

Permalink
Merge pull request #17 from seatable/session_data_django3.2
Browse files Browse the repository at this point in the history
session_data in django3.2
  • Loading branch information
freeplant authored Dec 18, 2021
2 parents c981d45 + ba1bc49 commit 93e2147
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN rm -f /usr/bin/python && \
ln -s /usr/local/bin/pip3.6 /usr/bin/pip && \
ln -s /usr/local/bin/pip3.6 /usr/bin/pip3

RUN pip3 install uvicorn pillow sqlalchemy==1.4.6 pymysql future requests redis \
RUN pip3 install uvicorn pillow sqlalchemy==1.4.6 pymysql future requests redis django==3.2.* \
-i https://mirrors.aliyun.com/pypi/simple && rm -r /root/.cache/pip


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pymysql
future # seaf-server
requests
redis
django==3.2.*

# psd_tools
# moviepy
11 changes: 7 additions & 4 deletions seatable_thumbnail/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import uuid
import json
import base64
import mimetypes
from datetime import datetime
from email.utils import formatdate
from django.contrib.sessions.backends.db import SessionStore
from django.conf import settings as dj_settings

import seatable_thumbnail.settings as settings
from seatable_thumbnail.constants import TEXT_CONTENT_TYPE, FILE_EXT_TYPE_MAP, \
Expand All @@ -13,6 +14,10 @@
from seatable_thumbnail.utils import get_file_id, get_file_obj


dj_settings.configure(SECRET_KEY=settings.DTABLE_WEB_SECRET_KEY)
session_store = SessionStore()


class ThumbnailSerializer(object):
def __init__(self, db_session, request):
self.db_session = db_session
Expand All @@ -34,9 +39,7 @@ def gen_thumbnail_info(self):

def parse_django_session(self, session_data):
# django/contrib/sessions/backends/base.py
encoded_data = base64.b64decode(session_data.encode('ascii'))
hash_key, serialized = encoded_data.split(b':', 1)
return json.loads(serialized.decode('latin-1'))
return session_store.decode(session_data)

def session_check(self):
session_key = self.request.cookies[settings.SESSION_KEY]
Expand Down
2 changes: 2 additions & 0 deletions seatable_thumbnail/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# session key
SESSION_KEY = 'sessionid'

DTABLE_WEB_SECRET_KEY = ''


# url
URL_PREFIX = '/'
Expand Down

0 comments on commit 93e2147

Please sign in to comment.