50 lines
1.3 KiB
Ruby
50 lines
1.3 KiB
Ruby
class StorageLocationsController < ApplicationController
|
|
before_action :set_storage_location, only: [:show, :destroy, :scan]
|
|
|
|
def index
|
|
@storage_locations = StorageLocation.all
|
|
# Auto-discover storage locations on index page load
|
|
StorageDiscoveryService.discover_and_create
|
|
end
|
|
|
|
def show
|
|
@videos = @storage_location.videos.includes(:work).recent
|
|
end
|
|
|
|
def create
|
|
@storage_location = StorageLocation.new(storage_location_params)
|
|
|
|
if @storage_location.save
|
|
redirect_to @storage_location, notice: 'Storage location was successfully created.'
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@storage_location.destroy
|
|
redirect_to storage_locations_url, notice: 'Storage location was successfully destroyed.'
|
|
end
|
|
|
|
def scan
|
|
scanner = FileScannerService.new(@storage_location)
|
|
result = scanner.scan
|
|
|
|
if result[:success]
|
|
redirect_to @storage_location, notice: result[:message]
|
|
else
|
|
redirect_to @storage_location, alert: result[:message]
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_storage_location
|
|
@storage_location = StorageLocation.find(params[:id])
|
|
end
|
|
|
|
def storage_location_params
|
|
params.require(:storage_location).permit(:name, :path, :storage_type)
|
|
end
|
|
end
|