changed to consistently use restore instead of awful undelete

This commit is contained in:
2021-06-10 17:55:44 +10:00
parent 804c7cbf56
commit 0b6acd1899
3 changed files with 17 additions and 17 deletions

View File

@@ -345,16 +345,16 @@ def rm_dups():
return render_template("base.html")
@app.route("/undelete_files", methods=["POST"])
def undelete_files():
@app.route("/restore_files", methods=["POST"])
def restore_files():
jex=[]
for el in request.form:
print( f"{el}={request.form[el]}" )
jex.append( JobExtra( name=f"{el}", value=request.form[el] ) )
job=NewJob( "undelete_files", 0, None, jex )
job=NewJob( "restore_files", 0, None, jex )
st.SetAlert("success")
st.SetMessage( f"Created&nbsp;<a href=/job/{job.id}>Job #{job.id}</a>&nbsp;to undelete selected file(s)")
st.SetMessage( f"Created&nbsp;<a href=/job/{job.id}>Job #{job.id}</a>&nbsp;to restore selected file(s)")
return render_template("base.html")
@app.route("/delete_files", methods=["POST"])

View File

@@ -399,8 +399,8 @@ def RunJob(job):
RemoveDups(job)
elif job.name == "delete_files":
JobDeleteFiles(job)
elif job.name == "undelete_files":
JobUnDeleteFiles(job)
elif job.name == "restore_files":
JobRestoreFiles(job)
elif job.name == "processai":
JobProcessAI(job)
else:
@@ -608,10 +608,10 @@ def RemoveFileFromFS( del_me ):
print( f"ERROR: Failed to remove file from filesystem - which={src}, err: {e}")
return
# Function that undeletes a file that was deleted (moved into the Bin)
# Function that restores a file that was deleted (moved into the Bin)
# it moves file on the filesystem back to its original path and then changes the database path from the Bin path
# to the original import or storage path and appropriate dir
def UnDeleteFile(job,restore_me):
def RestoreFile(job,restore_me):
try:
# rel_path for a file in the Bin, is like 'Import/images_to_process/1111', so just prepend static/
dst_dir='static/' + restore_me.in_dir.rel_path + '/'
@@ -620,7 +620,7 @@ def UnDeleteFile(job,restore_me):
dst=dst_dir + '/' + restore_me.name
os.replace( src, dst )
except Exception as e:
print( f"ERROR: Failed to undelete (mv) file on filesystem - which={src} to {dst}, err: {e}")
print( f"ERROR: Failed to restores (mv) file on filesystem - which={src} to {dst}, err: {e}")
# need these for AddDir calls below to work
orig_file_details = session.query(DelFile).get(restore_me.id)
@@ -670,7 +670,7 @@ def MoveFileToRecycleBin(job,del_me):
parent_dir=session.query(Dir).join(PathDirLink).filter(PathDirLink.path_id==bin_path.id).first()
print( f"need to keep this (ind): {del_me.in_dir.in_path.path_prefix}" )
# if we ever need to undelete, lets remember this file's original path
# if we ever need to restore, lets remember this file's original path
# (use a string in case the dir/path is ever deleted from FS (and then DB) and we need to recreate)
del_file_details = DelFile( file_eid=del_me.id, orig_path_prefix=del_me.in_dir.in_path.path_prefix )
session.add( del_file_details )
@@ -1178,14 +1178,14 @@ def JobDeleteFiles(job):
FinishJob(job, f"Finished deleting selected file(s)")
return
def JobUnDeleteFiles(job):
AddLogForJob(job, f"INFO: Starting Undelete Files job...")
def JobRestoreFiles(job):
AddLogForJob(job, f"INFO: Starting Restore Files job...")
for jex in job.extra:
if 'eid-' in jex.name:
restore_me=session.query(Entry).join(File).filter(Entry.id==jex.value).first()
AddLogForJob(job, f"INFO: Removing file: #{restore_me.id} -> {restore_me}" )
UnDeleteFile(job,restore_me)
FinishJob(job, f"Finished undeleting selected file(s)")
RestoreFile(job,restore_me)
FinishJob(job, f"Finished restoring selected file(s)")
return
def ValidateSettingsPaths():

View File

@@ -246,10 +246,10 @@ function DelDBox(del_or_undel)
if( del_or_undel == "Delete" )
div+="'/delete_files', "
else
div+="'/undelete_files', "
div+="'/restore_files', "
div+=`
data: to_del,
success: function(data){ console.log('Delete File(s) succeeded - TODO: need a FE msg' ); return false; } })" class="btn btn-outline-danger col-lg-2">Ok</button>
success: function(data){ console.log('Delete/Restore File(s) succeeded - TODO: need a FE msg' ); return false; } })" class="btn btn-outline-danger col-lg-2">Ok</button>
</div>
`
$('#dbox-content').html(div)
@@ -340,7 +340,7 @@ $.contextMenu({
view: { name: "View File" },
sep: "---",
move: { name: "Move selected file(s) to new storage folder" },
undel: { name: "Undelete Selected file(s)" }
undel: { name: "Restore selected file(s)" }
}
} else {
item_list = {