neocities-red 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -17
- data/bin/neocities-red +1 -1
- data/lib/neocities/cli.rb +38 -22
- data/lib/neocities/{file_list.rb → services/file_list.rb} +1 -1
- data/lib/neocities/{file_remover.rb → services/file_remover.rb} +1 -1
- data/lib/neocities/services/file_uploader.rb +43 -0
- data/lib/neocities/services/folder_uploader.rb +58 -0
- data/lib/neocities/{pizza.rb → services/pizza.rb} +1 -1
- data/lib/neocities/{profile_info.rb → services/profile_info.rb} +1 -1
- data/lib/neocities/{site_exporter.rb → services/site_exporter.rb} +1 -1
- data/lib/neocities/version.rb +1 -1
- data/lib/neocities.rb +9 -6
- metadata +9 -8
- data/lib/neocities/file_uploader.rb +0 -43
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 979f4ecefbbdda5967fa634639786036b9c46d43c64c90207d7e4b849e19827a
|
|
4
|
+
data.tar.gz: 69fbd007930e5b45457f1445df4b9b0a877213b1dd2e523070a46acd1d2e8fc8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86f21b0d75af228b1a4f5ae2feb0eb00773ada2d1614ed77f959afa38a8438c797b7dfd29032f4ca5a5eafd103c6e852a4c25ad41bf23322d32d610dbb8a386f
|
|
7
|
+
data.tar.gz: 43daf46a7d5bf9355cb81ef4e20557439c8901d00afff12d0787f738447775a7ccac766940a8ae8e68fde103d54c7e13bd885278ff6ce2738986f99f28ece234
|
data/README.md
CHANGED
|
@@ -2,25 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Hello, there is a fork of [neocities-ruby gem](https://github.com/neocities/neocities-ruby) with my own features and implementations. A much of my changes doesn't make sense to be pushed into original repository, so i pushed it here.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### Currently, neocities-red tests and develop with ruby 3.4.* and supports 4.*
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## List of improvements and changes:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
### 0) Refactor all entire project, change dependencies for more flexibility.
|
|
10
|
+
|
|
11
|
+
Currently or implementing new features `neocities-red` is easier than original cli. Also i approaching the philosophy to use modern dependencies to ensure that `neocities-red` will supports newest versions of Ruby.
|
|
12
|
+
|
|
13
|
+
### 1) upload
|
|
14
|
+
|
|
15
|
+
- Uploading is multi-threaded (Instead of uploading by 1 file linnear it uploads 3-5 files at once.)
|
|
16
|
+
- The logic is differs of original gem (please ensure that by typing the `neocities-red upload` command).
|
|
17
|
+
- Command also uploads folders recursively (It also upload the content that is inside of the target directory).
|
|
18
|
+
|
|
19
|
+
### 2) push
|
|
20
|
+
|
|
21
|
+
Now, that command is great for users, which uses static site generators (like Jekyll, Hugo, e.t.c.).
|
|
22
|
+
|
|
23
|
+
- Uploading is multi-threaded (Instead of uploading by 1 file linnear it uploads 3-5 files at once.)
|
|
24
|
+
- `neocities push --optimized` command is uploads only files which differs of already uploaded.
|
|
25
|
+
- `neocities push --ignore-dotfiles .` is ignores all files with '.' at the beginning.
|
|
26
|
+
- `neocities push -e <folder>` is ignores folders recursively (Ignoring the content that is inside of the target directory).
|
|
16
27
|
|
|
17
28
|
## TODO'S:
|
|
18
|
-
1)
|
|
19
|
-
2)
|
|
20
|
-
3)
|
|
21
|
-
4) Add tests
|
|
22
|
-
5) Make sure that gem is compatible with Linux, Freebsd, Windows
|
|
23
|
-
6) Make it compatible with ruby 4.0.0
|
|
29
|
+
1) Refactor `cli.rb` or use `rails/thor` gem instead.
|
|
30
|
+
2) Add tests.
|
|
31
|
+
3) Make sure that gem is compatible with Linux, Freebsd and Windows
|
|
24
32
|
|
|
25
33
|
# The Neocities Gem
|
|
26
34
|
|
|
@@ -28,8 +36,14 @@ A CLI and library for using the Neocities API. Makes it easy to quickly upload,
|
|
|
28
36
|
|
|
29
37
|
## Installation
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
1) Install Ruby Programming Language to your system.
|
|
40
|
+
- If you're not a programmer - just install version directly from https://www.ruby-lang.org/en/.
|
|
41
|
+
- If you're programmes, just use any of tools which supports programming language supports. I am prefer to use `asdf` of `mise`.
|
|
42
|
+
|
|
43
|
+
2) Install gem just typing:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
gem install neocities-red
|
|
33
47
|
```
|
|
34
48
|
|
|
35
49
|
### Running
|
|
@@ -62,3 +76,9 @@ client.delete(path)
|
|
|
62
76
|
client.push(path)
|
|
63
77
|
client.list(path)
|
|
64
78
|
```
|
|
79
|
+
|
|
80
|
+
# Contributions ..?
|
|
81
|
+
|
|
82
|
+
I'm glad to see everyone, so for contribution you need to check issues and take one typing something like "i'd like to take this issue". After that you should to make fork of this repository, create new branch, complete the task and share with solution via pull request.
|
|
83
|
+
|
|
84
|
+
If there are no tasks, just ping me (o-200) for the new issue, and we will think together about what can be implemented or fixed.
|
data/bin/neocities-red
CHANGED
data/lib/neocities/cli.rb
CHANGED
|
@@ -10,12 +10,13 @@ require 'whirly'
|
|
|
10
10
|
require 'digest'
|
|
11
11
|
require 'time'
|
|
12
12
|
|
|
13
|
-
# warning - the big quantity of working threads could be considered like-a DDOS.
|
|
13
|
+
# warning - the big quantity of working threads could be considered like-a DDOS.
|
|
14
|
+
# Your ip-address could get banned for a few days.
|
|
14
15
|
MAX_THREADS = 5
|
|
15
16
|
|
|
16
17
|
module Neocities
|
|
17
18
|
class CLI
|
|
18
|
-
SUBCOMMANDS = %w[upload delete list info push logout pizza pull].freeze
|
|
19
|
+
SUBCOMMANDS = %w[upload delete list info push logout pizza pull purge].freeze
|
|
19
20
|
HELP_SUBCOMMANDS = ['-h', '--help', 'help'].freeze
|
|
20
21
|
PENELOPE_MOUTHS = %w[^ o ~ - v U].freeze
|
|
21
22
|
PENELOPE_EYES = %w[o ~ O].freeze
|
|
@@ -62,6 +63,7 @@ module Neocities
|
|
|
62
63
|
display_help_and_exit
|
|
63
64
|
elsif @subargs.join('').match(HELP_SUBCOMMANDS.join('|')) && @subcmd != 'info'
|
|
64
65
|
send "display_#{@subcmd}_help_and_exit"
|
|
66
|
+
|
|
65
67
|
end
|
|
66
68
|
|
|
67
69
|
unless @api_key
|
|
@@ -115,7 +117,7 @@ module Neocities
|
|
|
115
117
|
display_delete_help_and_exit if @subargs.empty?
|
|
116
118
|
|
|
117
119
|
@subargs.each do |path|
|
|
118
|
-
FileRemover.new(@client, path).remove
|
|
120
|
+
Services::FileRemover.new(@client, path).remove
|
|
119
121
|
end
|
|
120
122
|
end
|
|
121
123
|
|
|
@@ -144,7 +146,7 @@ module Neocities
|
|
|
144
146
|
end
|
|
145
147
|
|
|
146
148
|
def info
|
|
147
|
-
profile_info = ProfileInfo.new(@client, @subargs, @sitename).pretty_print
|
|
149
|
+
profile_info = Services::ProfileInfo.new(@client, @subargs, @sitename).pretty_print
|
|
148
150
|
puts TTY::Table.new(profile_info)
|
|
149
151
|
rescue Exception => e
|
|
150
152
|
display_response(e)
|
|
@@ -159,7 +161,7 @@ module Neocities
|
|
|
159
161
|
|
|
160
162
|
path = @subargs[0]
|
|
161
163
|
|
|
162
|
-
FileList.new(@client, path, @detail).show
|
|
164
|
+
Services::FileList.new(@client, path, @detail).show
|
|
163
165
|
end
|
|
164
166
|
|
|
165
167
|
def push
|
|
@@ -303,7 +305,7 @@ module Neocities
|
|
|
303
305
|
end
|
|
304
306
|
next if path.nil? || path.directory?
|
|
305
307
|
|
|
306
|
-
|
|
308
|
+
Services::FileUploader.new(@client, path, path).upload
|
|
307
309
|
end
|
|
308
310
|
end
|
|
309
311
|
end
|
|
@@ -314,19 +316,13 @@ module Neocities
|
|
|
314
316
|
end
|
|
315
317
|
|
|
316
318
|
def upload
|
|
317
|
-
display_upload_help_and_exit if @subargs.
|
|
319
|
+
display_upload_help_and_exit if @subargs[0].nil? || @subargs[1].nil?
|
|
318
320
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
display_upload_help_and_exit
|
|
324
|
-
else
|
|
325
|
-
break
|
|
326
|
-
end
|
|
321
|
+
if File.file?(@subargs[0])
|
|
322
|
+
Services::FileUploader.new(@client, @subargs[0], @subargs[1]).upload
|
|
323
|
+
elsif File.directory?(@subargs[0])
|
|
324
|
+
Services::FolderUploader.new(@client, @subargs[0], @subargs[1]).upload
|
|
327
325
|
end
|
|
328
|
-
|
|
329
|
-
FileUploader.new(@client, @subargs[0], @subargs[1]).upload
|
|
330
326
|
end
|
|
331
327
|
|
|
332
328
|
def pull
|
|
@@ -336,8 +332,25 @@ module Neocities
|
|
|
336
332
|
last_pull_time = data['LAST_PULL']['time']
|
|
337
333
|
last_pull_loc = data['LAST_PULL']['loc']
|
|
338
334
|
|
|
339
|
-
SiteExporter.new(@client, @sitename, data, @app_config_path)
|
|
340
|
-
|
|
335
|
+
Services::SiteExporter.new(@client, @sitename, data, @app_config_path)
|
|
336
|
+
.export(quiet, last_pull_time, last_pull_loc)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# only for development purposes
|
|
340
|
+
def purge
|
|
341
|
+
pruned_dirs = []
|
|
342
|
+
resp = @client.list
|
|
343
|
+
resp[:files].each do |file|
|
|
344
|
+
print @pastel.bold("Deleting #{file[:path]} ... ")
|
|
345
|
+
resp = @client.delete_wrapper_with_dry_run file[:path], @dry_run
|
|
346
|
+
|
|
347
|
+
if resp[:result] == 'success'
|
|
348
|
+
print "#{@pastel.green.bold('SUCCESS')}\n"
|
|
349
|
+
else
|
|
350
|
+
print "\n"
|
|
351
|
+
display_response resp
|
|
352
|
+
end
|
|
353
|
+
end
|
|
341
354
|
end
|
|
342
355
|
|
|
343
356
|
def pizza
|
|
@@ -345,7 +358,7 @@ module Neocities
|
|
|
345
358
|
end
|
|
346
359
|
|
|
347
360
|
def display_pizza_help_and_exit
|
|
348
|
-
puts Pizza.new.make_order
|
|
361
|
+
puts Services::Pizza.new.make_order
|
|
349
362
|
end
|
|
350
363
|
|
|
351
364
|
def display_list_help_and_exit
|
|
@@ -392,7 +405,10 @@ HERE
|
|
|
392
405
|
|
|
393
406
|
#{@pastel.dim 'Examples:'}
|
|
394
407
|
|
|
395
|
-
#{@pastel.green '$ neocities upload
|
|
408
|
+
#{@pastel.green '$ neocities upload ./img.jpg ./images/img2.jpg'} Upload img.jpg to /images folder and with img2.jpg name
|
|
409
|
+
|
|
410
|
+
#{@pastel.green '$ neocities upload images/ images/'} Upload images folder with their content to /images folder
|
|
411
|
+
|
|
396
412
|
HERE
|
|
397
413
|
exit
|
|
398
414
|
end
|
|
@@ -425,7 +441,7 @@ HERE
|
|
|
425
441
|
|
|
426
442
|
#{@pastel.green '$ neocities push --dry-run .'} Just show what would be uploaded
|
|
427
443
|
|
|
428
|
-
#{@pastel.green '$ neocities push --optimized .'}
|
|
444
|
+
#{@pastel.green '$ neocities push --optimized .'} Do not upload unchanged files.#{' '}
|
|
429
445
|
|
|
430
446
|
#{@pastel.green '$ neocities push --prune .'} Delete site files not in dir (be careful!)
|
|
431
447
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pathname'
|
|
4
|
+
require 'pastel'
|
|
5
|
+
|
|
6
|
+
module Neocities
|
|
7
|
+
module Services
|
|
8
|
+
class FileIsNotExists < StandardError; end
|
|
9
|
+
|
|
10
|
+
class FileUploader
|
|
11
|
+
def initialize(client, filepath, remote_path = nil)
|
|
12
|
+
@client = client
|
|
13
|
+
@filepath = filepath
|
|
14
|
+
@remote_path = remote_path
|
|
15
|
+
@pastel = Pastel.new(eachline: "\n")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def upload
|
|
19
|
+
path = Pathname(@filepath)
|
|
20
|
+
|
|
21
|
+
raise FileIsNotExists, "#{path} does not exist locally." unless path.exist?
|
|
22
|
+
|
|
23
|
+
if path.directory?
|
|
24
|
+
puts @pastel.bold("#{path} is a directory, skipping")
|
|
25
|
+
return
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
puts @pastel.bold("Uploading #{path} to #{@remote_path} ...")
|
|
29
|
+
|
|
30
|
+
response = @client.upload(path, @remote_path)
|
|
31
|
+
puts response if response[:result] == 'error'
|
|
32
|
+
|
|
33
|
+
if response[:result] == 'error' && response[:error_type] == 'file_exists'
|
|
34
|
+
puts @pastel.yellow.bold('EXISTS')
|
|
35
|
+
elsif response[:result] == 'success'
|
|
36
|
+
puts @pastel.green.bold('SUCCESS')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
response
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pathname'
|
|
4
|
+
require 'pastel'
|
|
5
|
+
|
|
6
|
+
module Neocities
|
|
7
|
+
module Services
|
|
8
|
+
class FileIsNotExists < StandardError; end
|
|
9
|
+
|
|
10
|
+
# warning - the big quantity of working threads could be considered like-a DDOS.
|
|
11
|
+
# Your ip-address could get banned for a few days.
|
|
12
|
+
MAX_THREADS = 5
|
|
13
|
+
|
|
14
|
+
class FolderUploader
|
|
15
|
+
def initialize(client, filepath, remote_path)
|
|
16
|
+
@client = client
|
|
17
|
+
@filepath = filepath
|
|
18
|
+
@remote_path = remote_path
|
|
19
|
+
@pastel = Pastel.new(eachline: "\n")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def upload
|
|
23
|
+
path = Pathname(@filepath)
|
|
24
|
+
|
|
25
|
+
raise FileIsNotExists, "#{path} does not exist locally." unless path.exist?
|
|
26
|
+
|
|
27
|
+
if path.file?
|
|
28
|
+
puts @pastel.bold("#{path} is not a directory, skipping")
|
|
29
|
+
return
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Dir.chdir(path) do
|
|
33
|
+
files = Dir.glob('**/*', File::FNM_DOTMATCH).select { |f| File.file?(f) }
|
|
34
|
+
|
|
35
|
+
queue = Queue.new
|
|
36
|
+
files.each { |file| queue << file }
|
|
37
|
+
|
|
38
|
+
workers = Array.new(MAX_THREADS) do
|
|
39
|
+
Thread.new do
|
|
40
|
+
loop do
|
|
41
|
+
begin
|
|
42
|
+
file = queue.pop(true)
|
|
43
|
+
rescue ThreadError
|
|
44
|
+
break # queue is empty
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
remote_path = File.join(@remote_path, file)
|
|
48
|
+
FileUploader.new(@client, file, remote_path).upload
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
workers.each(&:join)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/neocities/version.rb
CHANGED
data/lib/neocities.rb
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
require File.join(File.dirname(__FILE__), 'neocities', 'version')
|
|
4
4
|
require File.join(File.dirname(__FILE__), 'neocities', 'client')
|
|
5
5
|
require File.join(File.dirname(__FILE__), 'neocities', 'cli')
|
|
6
|
-
|
|
7
|
-
require File.join(File.dirname(__FILE__), 'neocities', 'file_uploader')
|
|
8
|
-
require File.join(File.dirname(__FILE__), 'neocities', '
|
|
9
|
-
require File.join(File.dirname(__FILE__), 'neocities', '
|
|
10
|
-
require File.join(File.dirname(__FILE__), 'neocities', '
|
|
11
|
-
|
|
6
|
+
|
|
7
|
+
require File.join(File.dirname(__FILE__), 'neocities', 'services', 'file_uploader')
|
|
8
|
+
require File.join(File.dirname(__FILE__), 'neocities', 'services', 'folder_uploader')
|
|
9
|
+
require File.join(File.dirname(__FILE__), 'neocities', 'services', 'file_remover')
|
|
10
|
+
require File.join(File.dirname(__FILE__), 'neocities', 'services', 'file_list')
|
|
11
|
+
|
|
12
|
+
require File.join(File.dirname(__FILE__), 'neocities', 'services', 'profile_info')
|
|
13
|
+
require File.join(File.dirname(__FILE__), 'neocities', 'services', 'site_exporter')
|
|
14
|
+
require File.join(File.dirname(__FILE__), 'neocities', 'services', 'pizza')
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: neocities-red
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kyle Drake
|
|
@@ -174,12 +174,13 @@ files:
|
|
|
174
174
|
- lib/neocities.rb
|
|
175
175
|
- lib/neocities/cli.rb
|
|
176
176
|
- lib/neocities/client.rb
|
|
177
|
-
- lib/neocities/file_list.rb
|
|
178
|
-
- lib/neocities/file_remover.rb
|
|
179
|
-
- lib/neocities/file_uploader.rb
|
|
180
|
-
- lib/neocities/
|
|
181
|
-
- lib/neocities/
|
|
182
|
-
- lib/neocities/
|
|
177
|
+
- lib/neocities/services/file_list.rb
|
|
178
|
+
- lib/neocities/services/file_remover.rb
|
|
179
|
+
- lib/neocities/services/file_uploader.rb
|
|
180
|
+
- lib/neocities/services/folder_uploader.rb
|
|
181
|
+
- lib/neocities/services/pizza.rb
|
|
182
|
+
- lib/neocities/services/profile_info.rb
|
|
183
|
+
- lib/neocities/services/site_exporter.rb
|
|
183
184
|
- lib/neocities/version.rb
|
|
184
185
|
- neocities-red.gemspec
|
|
185
186
|
homepage: https://github.com/o-200/neocities-red
|
|
@@ -200,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
200
201
|
- !ruby/object:Gem::Version
|
|
201
202
|
version: '0'
|
|
202
203
|
requirements: []
|
|
203
|
-
rubygems_version: 4.0.
|
|
204
|
+
rubygems_version: 4.0.3
|
|
204
205
|
specification_version: 4
|
|
205
206
|
summary: Yet Another Neocities.org CLI and API client with improvements
|
|
206
207
|
test_files: []
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'pathname'
|
|
4
|
-
require 'pastel'
|
|
5
|
-
|
|
6
|
-
module Neocities
|
|
7
|
-
class FileIsNotExists < StandardError; end
|
|
8
|
-
|
|
9
|
-
class FileUploader
|
|
10
|
-
def initialize(client, filepath, remote_path = nil)
|
|
11
|
-
@client = client
|
|
12
|
-
@filepath = filepath
|
|
13
|
-
@remote_path = remote_path
|
|
14
|
-
@pastel = Pastel.new(eachline: "\n")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def upload
|
|
18
|
-
path = Pathname(@filepath)
|
|
19
|
-
|
|
20
|
-
raise FileIsNotExists, "#{path} does not exist locally." unless path.exist?
|
|
21
|
-
|
|
22
|
-
if path.directory?
|
|
23
|
-
puts @pastel.bold("#{path} is a directory, skipping")
|
|
24
|
-
return
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
remote_path = @remote_path || path
|
|
28
|
-
|
|
29
|
-
puts @pastel.bold("Uploading #{path} to #{remote_path} ...")
|
|
30
|
-
|
|
31
|
-
response = @client.upload(path, remote_path)
|
|
32
|
-
puts response if response[:result] == 'error'
|
|
33
|
-
|
|
34
|
-
if response[:result] == 'error' && response[:error_type] == 'file_exists'
|
|
35
|
-
puts @pastel.yellow.bold('EXISTS')
|
|
36
|
-
elsif response[:result] == 'success'
|
|
37
|
-
puts @pastel.green.bold('SUCCESS')
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
response
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|