Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
8cbd6a84
Commit
8cbd6a84
authored
Aug 19, 2017
by
Jonathan Rehm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not append query string if file_hash is not found
parent
13c2a53c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
cache_buster.py
cps/cache_buster.py
+8
-6
No files found.
cps/cache_buster.py
View file @
8cbd6a84
...
@@ -25,12 +25,12 @@ def init_cache_busting(app):
...
@@ -25,12 +25,12 @@ def init_cache_busting(app):
# compute version component
# compute version component
rooted_filename
=
os
.
path
.
join
(
dirpath
,
filename
)
rooted_filename
=
os
.
path
.
join
(
dirpath
,
filename
)
with
open
(
rooted_filename
,
'r'
)
as
f
:
with
open
(
rooted_filename
,
'r'
)
as
f
:
version
=
hashlib
.
md5
(
f
.
read
())
.
hexdigest
()[:
7
]
file_hash
=
hashlib
.
md5
(
f
.
read
())
.
hexdigest
()[:
7
]
# save version to tables
# save version to tables
file_path
=
rooted_filename
.
replace
(
static_folder
,
""
)
file_path
=
rooted_filename
.
replace
(
static_folder
,
""
)
file_path
=
file_path
.
replace
(
"
\\
"
,
"/"
)
# Convert Windows path to web path
file_path
=
file_path
.
replace
(
"
\\
"
,
"/"
)
# Convert Windows path to web path
hash_table
[
file_path
]
=
version
hash_table
[
file_path
]
=
file_hash
app
.
logger
.
debug
(
'Finished computing cache-busting values'
)
app
.
logger
.
debug
(
'Finished computing cache-busting values'
)
def
bust_filename
(
filename
):
def
bust_filename
(
filename
):
...
@@ -44,8 +44,10 @@ def init_cache_busting(app):
...
@@ -44,8 +44,10 @@ def init_cache_busting(app):
"""
"""
Make `url_for` produce busted filenames when using the 'static' endpoint.
Make `url_for` produce busted filenames when using the 'static' endpoint.
"""
"""
if
endpoint
==
'static'
:
if
endpoint
==
"static"
:
values
[
"q"
]
=
bust_filename
(
values
[
'filename'
])
file_hash
=
bust_filename
(
values
[
"filename"
])
if
file_hash
:
values
[
"q"
]
=
file_hash
def
debusting_static_view
(
filename
):
def
debusting_static_view
(
filename
):
"""
"""
...
@@ -54,5 +56,5 @@ def init_cache_busting(app):
...
@@ -54,5 +56,5 @@ def init_cache_busting(app):
return
original_static_view
(
filename
=
unbust_filename
(
filename
))
return
original_static_view
(
filename
=
unbust_filename
(
filename
))
# Replace the default static file view with our debusting view.
# Replace the default static file view with our debusting view.
original_static_view
=
app
.
view_functions
[
'static'
]
original_static_view
=
app
.
view_functions
[
"static"
]
app
.
view_functions
[
'static'
]
=
debusting_static_view
app
.
view_functions
[
"static"
]
=
debusting_static_view
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment