Class: NeocitiesRed::Services::File::Uploader
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::File::Uploader
- Defined in:
- lib/neocities_red/services/file/uploader.rb
Overview
Uploads a single file to the Neocities site.
Handles display feedback for the upload lifecycle: progress, success, already-exists, and directory-skip scenarios.
Instance Method Summary collapse
-
#initialize(client, filepath, remote_path = nil, display: NeocitiesRed::CliDisplay.new) ⇒ Uploader
constructor
A new instance of Uploader.
-
#upload ⇒ Hash
Uploads the file to the remote site.
Constructor Details
#initialize(client, filepath, remote_path = nil, display: NeocitiesRed::CliDisplay.new) ⇒ Uploader
Returns a new instance of Uploader.
24 25 26 27 28 29 |
# File 'lib/neocities_red/services/file/uploader.rb', line 24 def initialize(client, filepath, remote_path = nil, display: NeocitiesRed::CliDisplay.new) @client = client @filepath = filepath @remote_path = remote_path @display = display end |
Instance Method Details
#upload ⇒ Hash
Uploads the file to the remote site.
Skips directories with a display message. Computes the SHA1 hash and skips the upload if the remote file is identical.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/neocities_red/services/file/uploader.rb', line 38 def upload path = Pathname.new(@filepath) raise NeocitiesRed::FileNotFoundError, "#{path} does not exist locally." unless path.exist? if path.directory? @display.display_skip_directory(path) return end @display.display_upload_progress(path, @remote_path) response = @client.upload(path, @remote_path) if response[:result] == "success" @display.display_upload_success elsif response[:result] == "error" && response[:error_type] == "file_exists" @display.display_upload_exists else @display.display_response(response) end response end |