Consolidated the video and channel attribute edits into one javascript function

This commit is contained in:
2023-03-07 11:29:10 -05:00
parent 8905bed454
commit a9c4b29935
5 changed files with 39 additions and 41 deletions

View File

@ -79,14 +79,14 @@ namespace '/channel' do
attrToEdit = params[:attr]
if attrToEdit == 'directory_path'
File.rename(channel.directory_path, params[attrToEdit])
File.rename(channel.directory_path, params[:value])
channel.videos.each do |v|
video_path = v.directory_path.sub(channel.directory_path, params[attrToEdit])
video_path = v.directory_path.sub(channel.directory_path, params[:value])
v.update(directory_path: video_path)
end
end
channel[attrToEdit.to_sym] = params[attrToEdit]
channel[attrToEdit.to_sym] = params[:value]
channel.save()
return "success"

View File

@ -111,7 +111,15 @@ namespace '/video' do
video = Video.where(id: params[:video_id]).first()
attrToEdit = params[:attr]
video[attrToEdit.to_sym] = params[attrToEdit]
# if we update the video's serial, we need to also update the directory path
if attrToEdit == 'serial'
old_path = video.directory_path
new_path = video.directory_path.sub("##{video.serial}", "##{params[:value]}")
File.rename(old_path, new_path)
video[:directory_path] = new_path
end
video[attrToEdit.to_sym] = params[:value]
video.save()
return "success"