Skip to content

Commit b442abe

Browse files
committed
first_commit
1 parent 4a09c8c commit b442abe

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ COPY . .
1212

1313
ENV PYTHONPATH='/project/:/project/app/'
1414
WORKDIR /project/app
15+
16+
RUN STATIC_HASH=$(find app/static -type f -exec md5sum {} \; | md5sum | cut -d' ' -f1) && \
17+
echo $STATIC_HASH >> /APP_STATIC_HASH
18+
19+
ENV APP_STATIC_HASH_FILE=/APP_STATIC_HASH

app/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from configparser import ConfigParser
23
from collections import OrderedDict
34

@@ -24,3 +25,21 @@ def init_config(config_path):
2425
config_raw = ConfigParser()
2526
config_raw.read(config_path)
2627
Config.c = DictToObject(config_raw._sections)
28+
29+
class VersionCache:
30+
_instance = None
31+
32+
def __new__(cls):
33+
if cls._instance is None:
34+
cls._instance = super().__new__(cls)
35+
hash_file = os.getenv("APP_STATIC_HASH_FILE", "dev")
36+
if hash_file and os.path.exists(hash_file):
37+
with open(hash_file) as f:
38+
cls._instance.version=f.read().split()
39+
else:
40+
cls._instance.version = "dev"
41+
return cls._instance
42+
43+
@classmethod
44+
def get_version(cls):
45+
return cls().version

app/templates/user_info.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</div>
1212

1313

14-
<script src="/static/js/libraries/jquery.min.js"></script>
15-
<script src="/static/js/user_info.js"></script>
14+
<script src="{{ versioned_url('js/libraries/jquery.min.js') }}"></script>
15+
<script src="{{ versioned_url('js/user_info.js') }}"></script>
1616

1717
{% endblock %}

app/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
import fitz
99
from bson import ObjectId
10-
from flask import json
10+
from flask import json, url_for
1111
import magic
1212
import pymorphy2
1313
from nltk.corpus import stopwords
1414
from pydub import AudioSegment
1515
import subprocess
1616

17-
from app.config import Config
17+
from app.config import Config, VersionCache
1818

1919
PDF_HEX_START = ['25', '50', '44', '46']
2020
SECONDS_PER_MINUTE = 60
@@ -209,6 +209,10 @@ def delete_punctuation(text: str) -> str:
209209
return text.translate(str.maketrans('', '', string.punctuation + "\t\n\r\v\f"))
210210

211211

212+
def versioned_url(filename):
213+
v = VersionCache.get_version()
214+
return url_for('static', filename=filename) + f'?v={v}'
215+
212216
class RepeatedTimer:
213217
"""
214218
Utility class to call a function with a given interval between the end and the beginning of consecutive calls

app/web_speech_trainer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from app.routes.capacity import routes_capacity
3535
from app.status import PassBackStatus, TrainingStatus
3636
from app.training_manager import TrainingManager
37-
from app.utils import ALLOWED_EXTENSIONS, DEFAULT_EXTENSION
37+
from app.utils import ALLOWED_EXTENSIONS, DEFAULT_EXTENSION, versioned_url
3838

3939
app = Flask(__name__)
4040
app.register_blueprint(api_audio)
@@ -57,6 +57,7 @@
5757
app.register_blueprint(routes_task_attempts)
5858
app.register_blueprint(routes_version)
5959
app.register_blueprint(routes_capacity)
60+
app.jinja_env.globals['versioned_url'] = versioned_url
6061

6162
logger = get_root_logger(service_name='web')
6263

0 commit comments

Comments
 (0)