-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c6ba5c
commit 1865921
Showing
5 changed files
with
55 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import urllib.request | ||
import urllib.parse | ||
|
||
from seaserv import seafile_api | ||
import seatable_thumbnail.settings as settings | ||
|
||
|
||
def get_file_id(repo_id, file_path): | ||
file_id = seafile_api.get_file_id_by_path(repo_id, file_path) | ||
if not file_id: | ||
raise ValueError(404, 'file_id not found.') | ||
|
||
return file_id | ||
|
||
|
||
def get_inner_path(repo_id, file_id, file_name): | ||
token = seafile_api.get_fileserver_access_token( | ||
repo_id, file_id, 'view', '', use_onetime=True) | ||
if not token: | ||
raise ValueError(404, 'token not found.') | ||
inner_path = '%s/files/%s/%s' % ( | ||
settings.INNER_FILE_SERVER_ROOT.rstrip('/'), token, urllib.parse.quote(file_name)) | ||
|
||
return inner_path | ||
|
||
|
||
def cache_check(request, info): | ||
etag = info.get('etag') | ||
if_none_match_headers = request.headers.get('if-none-match') | ||
if_none_match = if_none_match_headers[0] if if_none_match_headers else '' | ||
|
||
last_modified = info.get('last_modified') | ||
if_modified_since_headers = request.headers.get('if-modified-since') | ||
if_modified_since = if_modified_since_headers[0] if if_modified_since_headers else '' | ||
|
||
if (if_none_match and if_none_match == etag) \ | ||
or (if_modified_since and if_modified_since == last_modified): | ||
return True | ||
else: | ||
return False |