File tree Expand file tree Collapse file tree 8 files changed +48
-7
lines changed Expand file tree Collapse file tree 8 files changed +48
-7
lines changed Original file line number Diff line number Diff line change @@ -145,12 +145,14 @@ def upload_presentation() -> (dict, int):
145145 'message' : 'Presentation file should not exceed {}MB.' .format (
146146 Config .c .constants .presentation_file_max_size_in_megabytes
147147 )
148- }, 404
148+ }, 413
149149 # check if file can be stored (*2.5 is an estimate of pdf and preview)
150150 if not DBManager ().check_storage_limit (request .content_length * 2.5 ):
151151 return {
152- 'message' : "Not enough place in database to store file"
153- }, 404
152+ 'message' : "Not enough space in database to store file. "
153+ "Please contact at email: "
154+ f"<a href='mailto:{ Config .c .bugreport .report_mail } '>{ Config .c .bugreport .report_mail } </a>"
155+ }, 413
154156
155157 presentation_file = request .files ['presentation' ]
156158
Original file line number Diff line number Diff line change 3333BYTES_PER_MB = 1024 * 1024
3434
3535class DBManager :
36- def __new__ (cls , max_size = 20000 ): # max_size only on first creation, in MB
36+ def __new__ (cls ):
3737 if not hasattr (cls , 'init_done' ):
3838 cls .instance = super (DBManager , cls ).__new__ (cls )
3939 connect (Config .c .mongodb .url + Config .c .mongodb .database_name )
4040 cls .instance .storage = GridFSStorage (GridFSBucket (_get_db ()))
41- cls .instance .max_size = max_size * BYTES_PER_MB
41+ cls .instance .max_size = float ( Config . c . constants . storage_max_size_mbytes ) * BYTES_PER_MB
4242 cls .init_done = True
4343 return cls .instance
4444
@@ -111,7 +111,15 @@ def check_storage_limit(self, new_file_size):
111111 )
112112 logger .info (inf_msg )
113113 return False if current_size + new_file_size > self .max_size else True
114-
114+
115+ def recalculate_used_storage_data (self ):
116+ total_size = 0
117+ db = _get_db ()
118+ for file_doc in db .fs .files .find ():
119+ total_size += file_doc ['length' ]
120+ self .set_used_storage_size (total_size )
121+ logger .info (f"Storage size recalculated: { total_size / BYTES_PER_MB :.2f} MB" )
122+
115123
116124class TrainingsDBManager :
117125 def __new__ (cls ):
Original file line number Diff line number Diff line change @@ -23,4 +23,10 @@ def storage_capacity():
2323 max_size = round (max_size / BYTES_PER_MB , 2 ),
2424 ratio = round (ratio * 100 , 1 )
2525 )
26-
26+
27+ @routes_capacity .route ('/refresh_capacity' , methods = ['POST' ])
28+ def refresh_capacity ():
29+ if not is_admin ():
30+ return {}, 404
31+ DBManager ().recalculate_used_storage_data ()
32+ return {'message' : 'OK' }
Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ $(function(){
2626 return ;
2727 }
2828 $ ( "#spinner" ) . hide ( ) ;
29+
30+ if ( response . status == 413 ) {
31+ response . json ( ) . then ( responseJson => {
32+ $ ( "#alert" ) . show ( ) ;
33+ $ ( "#error-text" ) . html ( responseJson [ "message" ] || "Файл слишком большой или превышает лимит хранилища" ) ;
34+ } ) ;
35+ $ ( '#button-submit' ) [ 0 ] . value = button_value ;
36+
37+ return ;
38+ }
39+
2940 response . json ( ) . then ( responseJson => {
3041 if ( responseJson [ "message" ] !== "OK" ) {
3142 $ ( "#alert" ) . show ( ) ;
Original file line number Diff line number Diff line change 1313 < a href ="{{ url_for( "routes_admin.view_dumps ")}}" target="_blank "> {{ t("Архивы БД") }}</ a >
1414 < br >
1515 < a href ="{{ url_for( "routes_version.view_version ")}}" target="_blank "> {{ t("Версия") }}</ a >
16+ < br >
17+ < a href ="{{ url_for( "routes_capacity.storage_capacity ")}}" target="_blank "> {{ t("Заполненность БД") }}</ a >
1618</ div >
1719{% endblock %}
Original file line number Diff line number Diff line change @@ -14,6 +14,16 @@ <h4 class="card-title">Загруженность Базы Данных</h4>
1414 </ div >
1515 </ div >
1616 </ div >
17+ < button type ="button " id ="refresh_button "> Обновить данные</ button >
18+
19+ < script src ="/static/js/libraries/jquery.min.js "> </ script >
20+ < script >
21+ $ ( '#refresh_button' ) . click ( function ( ) {
22+ $ . post ( "{{ url_for('routes_capacity.refresh_capacity') }}" , { } , function ( data ) {
23+ location . reload ( ) ;
24+ } ) ;
25+ } ) ;
26+ </ script >
1727 </ div >
1828</ div >
1929{% endblock %}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ lti_consumer_key=secretconsumerkey
55lti_consumer_secret =supersecretconsumersecret
66version_file =VERSION.json
77backup_path =../dump/database-dump/
8+ storage_max_size_mbytes =20000
89
910[mongodb]
1011url =mongodb://db:27017/
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ lti_consumer_key=testing_lti_consumer_key
55lti_consumer_secret =testing_lti_consumer_secret
66version_file =VERSION.json
77backup_path =../dump/database-dump/
8+ storage_max_size_mbytes =20000
89
910[mongodb]
1011url =mongodb://db:27017/
You can’t perform that action at this time.
0 commit comments