Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibreTranslate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Riße, Matthias
LibreTranslate
Commits
c5f47f09
Unverified
Commit
c5f47f09
authored
3 years ago
by
Sébastien Thuret
Browse files
Options
Downloads
Patches
Plain Diff
add scheduler to remove files after 30 minutes instead of after download
parent
738dba74
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/app.py
+12
-2
12 additions, 2 deletions
app/app.py
app/remove_translated_files.py
+26
-0
26 additions, 0 deletions
app/remove_translated_files.py
with
38 additions
and
2 deletions
app/app.py
+
12
−
2
View file @
c5f47f09
...
@@ -14,13 +14,23 @@ from translatehtml import translate_html
...
@@ -14,13 +14,23 @@ from translatehtml import translate_html
from
werkzeug.utils
import
secure_filename
from
werkzeug.utils
import
secure_filename
from
app
import
flood
from
app
import
flood
from
app
import
remove_translated_files
from
app.language
import
detect_languages
,
transliterate
from
app.language
import
detect_languages
,
transliterate
from
.api_keys
import
Database
from
.api_keys
import
Database
from
.suggestions
import
Database
as
SuggestionsDatabase
from
.suggestions
import
Database
as
SuggestionsDatabase
def
get_upload_dir
():
def
get_upload_dir
():
return
os
.
path
.
join
(
tempfile
.
gettempdir
(),
"
libretranslate-files-translate
"
)
upload_dir
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
"
libretranslate-files-translate
"
)
if
not
os
.
path
.
isdir
(
upload_dir
):
os
.
mkdir
(
upload_dir
)
return
upload_dir
remove_translated_files
.
setup
(
get_upload_dir
())
def
get_json_dict
(
request
):
def
get_json_dict
(
request
):
d
=
request
.
get_json
()
d
=
request
.
get_json
()
...
@@ -610,7 +620,7 @@ def create_app(args):
...
@@ -610,7 +620,7 @@ def create_app(args):
return_data
.
write
(
fo
.
read
())
return_data
.
write
(
fo
.
read
())
return_data
.
seek
(
0
)
return_data
.
seek
(
0
)
os
.
remove
(
file
path
)
print
(
file
name
)
return
send_file
(
return_data
,
attachment_filename
=
filename
)
return
send_file
(
return_data
,
attachment_filename
=
filename
)
...
...
This diff is collapsed.
Click to expand it.
app/remove_translated_files.py
0 → 100644
+
26
−
0
View file @
c5f47f09
import
atexit
import
os
import
time
from
datetime
import
datetime
from
apscheduler.schedulers.background
import
BackgroundScheduler
def
remove_translated_files
(
upload_dir
:
str
):
now
=
time
.
mktime
(
datetime
.
now
().
timetuple
())
for
f
in
os
.
listdir
(
upload_dir
):
f
=
os
.
path
.
join
(
upload_dir
,
f
)
if
os
.
path
.
isfile
(
f
):
f_time
=
os
.
path
.
getmtime
(
f
)
if
(
now
-
f_time
)
>
1800
:
# 30 minutes
os
.
remove
(
f
)
def
setup
(
upload_dir
):
scheduler
=
BackgroundScheduler
(
daemon
=
True
)
scheduler
.
add_job
(
remove_translated_files
,
"
interval
"
,
minutes
=
30
,
kwargs
=
{
'
upload_dir
'
:
upload_dir
})
scheduler
.
start
()
# Shut down the scheduler when exiting the app
atexit
.
register
(
lambda
:
scheduler
.
shutdown
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment