mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
fix for archiver
This commit is contained in:
parent
1b6e12a831
commit
a9380d4554
4 changed files with 55 additions and 1 deletions
1
Gemfile
1
Gemfile
|
@ -30,6 +30,7 @@ gem 'geoip'
|
||||||
gem 'io-extra', require: 'io/extra'
|
gem 'io-extra', require: 'io/extra'
|
||||||
gem 'rye'
|
gem 'rye'
|
||||||
gem 'dnsruby'
|
gem 'dnsruby'
|
||||||
|
gem 'base32'
|
||||||
|
|
||||||
platform :mri, :rbx do
|
platform :mri, :rbx do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
|
@ -16,6 +16,7 @@ GEM
|
||||||
addressable (>= 2.3.1)
|
addressable (>= 2.3.1)
|
||||||
extlib (>= 0.9.15)
|
extlib (>= 0.9.15)
|
||||||
multi_json (>= 1.0.0)
|
multi_json (>= 1.0.0)
|
||||||
|
base32 (0.3.2)
|
||||||
bcrypt (3.1.7)
|
bcrypt (3.1.7)
|
||||||
blankslate (3.1.3)
|
blankslate (3.1.3)
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
|
@ -261,6 +262,7 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
ago
|
ago
|
||||||
|
base32
|
||||||
bcrypt
|
bcrypt
|
||||||
capybara_minitest_spec
|
capybara_minitest_spec
|
||||||
cocaine
|
cocaine
|
||||||
|
|
41
ext/base58.rb
Normal file
41
ext/base58.rb
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
module Base58
|
||||||
|
class << self
|
||||||
|
def int_to_base58(int_val, leading_zero_bytes=0)
|
||||||
|
alpha = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||||
|
base58_val, base = '', alpha.size
|
||||||
|
while int_val > 0
|
||||||
|
int_val, remainder = int_val.divmod(base)
|
||||||
|
base58_val = alpha[remainder] + base58_val
|
||||||
|
end
|
||||||
|
base58_val
|
||||||
|
end
|
||||||
|
|
||||||
|
def base58_to_int(base58_val)
|
||||||
|
alpha = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||||
|
int_val, base = 0, alpha.size
|
||||||
|
base58_val.reverse.each_char.with_index do |char,index|
|
||||||
|
raise ArgumentError, 'Value not a valid Base58 String.' unless char_index = alpha.index(char)
|
||||||
|
int_val += char_index*(base**index)
|
||||||
|
end
|
||||||
|
int_val
|
||||||
|
end
|
||||||
|
|
||||||
|
def base58_to_bytestring(base58_val)
|
||||||
|
[Base58.decode_base58(base58_val)].pack('H*')
|
||||||
|
end
|
||||||
|
|
||||||
|
def encode_base58(hex)
|
||||||
|
leading_zero_bytes = (hex.match(/^([0]+)/) ? $1 : '').size / 2
|
||||||
|
("1"*leading_zero_bytes) + int_to_base58( hex.to_i(16) )
|
||||||
|
end
|
||||||
|
|
||||||
|
def decode_base58(base58_val)
|
||||||
|
s = base58_to_int(base58_val).to_s(16); s = (s.bytesize.odd? ? '0'+s : s)
|
||||||
|
s = '' if s == '00'
|
||||||
|
leading_zero_bytes = (base58_val.match(/^([1]+)/) ? $1 : '').size
|
||||||
|
s = ("00"*leading_zero_bytes) + s if leading_zero_bytes > 0
|
||||||
|
s
|
||||||
|
end
|
||||||
|
alias_method :base58_to_hex, :decode_base58
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,9 +1,19 @@
|
||||||
|
require 'base32'
|
||||||
|
|
||||||
class Archive < Sequel::Model
|
class Archive < Sequel::Model
|
||||||
many_to_one :site
|
many_to_one :site
|
||||||
set_primary_key [:site_id, :ipfs_hash]
|
set_primary_key [:site_id, :ipfs_hash]
|
||||||
unrestrict_primary_key
|
unrestrict_primary_key
|
||||||
|
|
||||||
|
def self.base58_to_hshca(base58)
|
||||||
|
Base32.encode(Base58.base58_to_bytestring(base58)).gsub('=', '').downcase
|
||||||
|
end
|
||||||
|
|
||||||
|
def hshca_hash
|
||||||
|
self.class.base58_to_hshca ipfs_hash
|
||||||
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
"https://#{ipfs_hash}.ipfs.neocities.org"
|
"http://#{hshca_hash}.ipfs.neocitiesops.net"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue