Skip to content

Commit

Permalink
Plugin obj
Browse files Browse the repository at this point in the history
  • Loading branch information
SkywalkerSpace committed Sep 23, 2020
1 parent 01ab123 commit 67ebb6b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docker/scripts/init_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
# location /thumbnail/ {
# proxy_pass https://thumbnail.seatable.cn/thumbnail/;
# }
#
# location /dtable-plugins/ {
# proxy_pass https://thumbnail.seatable.cn/dtable-plugins/;
# }
}
"""
Expand Down
2 changes: 1 addition & 1 deletion seatable_thumbnail/http_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def gen_thumbnail_response(thumbnail, etag, last_modified):


def gen_plugin_response(plugin, content_type, etag, last_modified):
response_start = gen_response_start(200, content_type)
response_start = gen_response_start(200, content_type.encode('utf-8'))
response_body = gen_response_body(plugin)

# cache
Expand Down
27 changes: 27 additions & 0 deletions seatable_thumbnail/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests
import urllib.request
import urllib.parse

from seaserv import seafile_api
import seatable_thumbnail.settings as settings
from seatable_thumbnail.constants import EMPTY_BYTES


class Plugin(object):
def __init__(self, **info):
self.__dict__.update(info)
self.body = EMPTY_BYTES
self.get()

def get(self):
self.get_inner_path()
response = requests.get(self.inner_path)
self.body = response.content

def get_inner_path(self):
token = seafile_api.get_fileserver_access_token(
settings.PLUGINS_REPO_ID, self.file_id, 'view', '', use_onetime=True)
if not token:
raise ValueError(404, 'token not found.')
self.inner_path = '%s/files/%s/%s' % (
settings.INNER_FILE_SERVER_ROOT.rstrip('/'), token, urllib.parse.quote(self.file_path.lstrip('/')))
14 changes: 7 additions & 7 deletions seatable_thumbnail/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from seaserv import seafile_api
import seatable_thumbnail.settings as settings
from seatable_thumbnail.constants import FILE_EXT_TYPE_MAP, \
from seatable_thumbnail.constants import TEXT_CONTENT_TYPE, FILE_EXT_TYPE_MAP, \
IMAGE, PSD, VIDEO, XMIND
from seatable_thumbnail.models import Workspaces, DjangoSession, DTableSystemPlugins

Expand Down Expand Up @@ -157,7 +157,7 @@ def params_check(self):
plugin_name = self.request.url.split('/')[1]
timestamp = self.request.query_dict['t'][0] if self.request.query_dict.get('t') else ''
version = self.request.query_dict['version'][0] if self.request.query_dict.get('version') else ''
content_type = mimetypes.guess_type(path)
content_type = mimetypes.guess_type(path)[0] if mimetypes.guess_type(path) else TEXT_CONTENT_TYPE.decode('utf-8')

self.params = {
'path': path,
Expand All @@ -175,18 +175,18 @@ def resource_check(self):
DTableSystemPlugins).filter_by(name=plugin_name).first()

file_path ='/' + plugin.name + path
repo_id = settings.PLUGINS_REPO_ID
file_id = seafile_api.get_file_id_by_path(repo_id, file_path)
file_id = seafile_api.get_file_id_by_path(settings.PLUGINS_REPO_ID, file_path)
if not file_id:
raise ValueError(404, 'file_id not found.')

info = json.loads(plugin.info)
last_modified = info['last_modified']
file_info = json.loads(plugin.info)
last_modified = file_info['last_modified']
etag = '"' + file_id + '"'

self.resource = {
'file_path': file_path,
'file_id': file_id,
'info': info,
'file_info': file_info,
'last_modified': last_modified,
'etag': etag,
}

0 comments on commit 67ebb6b

Please sign in to comment.