mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
unpin code for pruning excessive ipfs archives
This commit is contained in:
parent
7cce210f90
commit
8aa0061ab4
3 changed files with 32 additions and 1 deletions
|
@ -4,6 +4,12 @@ class Archive < Sequel::Model
|
|||
many_to_one :site
|
||||
set_primary_key [:site_id, :ipfs_hash]
|
||||
unrestrict_primary_key
|
||||
MAXIMUM_ARCHIVES_PER_SITE = 500
|
||||
|
||||
def before_destroy
|
||||
unpin
|
||||
super
|
||||
end
|
||||
|
||||
def self.base58_to_hshca(base58)
|
||||
Base32.encode(Base58.base58_to_bytestring(base58)).gsub('=', '').downcase
|
||||
|
@ -13,6 +19,25 @@ class Archive < Sequel::Model
|
|||
self.class.base58_to_hshca ipfs_hash
|
||||
end
|
||||
|
||||
def unpin
|
||||
# Not ideal. An SoA version is in progress.
|
||||
if ENV['RACK_ENV'] == 'production' && $config['ipfs_ssh_host'] && $config['ipfs_ssh_user']
|
||||
rbox = Rye::Box.new $config['ipfs_ssh_host'], :user => $config['ipfs_ssh_user']
|
||||
rbox.disable_safe_mode
|
||||
begin
|
||||
response = rbox.execute "ipfs pin rm #{ipfs_hash}"
|
||||
output_array = response
|
||||
ensure
|
||||
rbox.disconnect
|
||||
end
|
||||
else
|
||||
line = Cocaine::CommandLine.new('ipfs', 'pin rm :ipfs_hash')
|
||||
binding.pry
|
||||
response = line.run ipfs_hash: ipfs_hash
|
||||
output_array = response.to_s.split("\n")
|
||||
end
|
||||
end
|
||||
|
||||
def url
|
||||
"http://#{hshca_hash}.ipfs.neocitiesops.net"
|
||||
end
|
||||
|
|
|
@ -641,6 +641,12 @@ class Site < Sequel::Model
|
|||
output_array.last.split(' ')[1]
|
||||
end
|
||||
|
||||
def purge_old_archives
|
||||
archives_dataset.order(:updated_at).offset(Archive::MAXIMUM_ARCHIVES_PER_SITE).all.each do |archive|
|
||||
archive.destroy
|
||||
end
|
||||
end
|
||||
|
||||
def archive!
|
||||
#if ENV["RACK_ENV"] == 'test'
|
||||
# ipfs_hash = "QmcKi2ae3uGb1kBg1yBpsuwoVqfmcByNdMiZ2pukxyLWD8"
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue