integrate IPFS using remote ssh for now, views

This commit is contained in:
Kyle Drake 2015-05-27 16:06:56 -07:00
parent 8424cc02e8
commit 59feb09928
8 changed files with 92 additions and 4 deletions

1
.gitignore vendored
View file

@ -34,3 +34,4 @@ files/sslsites.zip
.vagrant
public/banned_sites
public/deleted_sites
tests/stat_logs/*

View file

@ -28,6 +28,7 @@ gem 'rack-cache'
gem 'rest-client'
gem 'geoip'
gem 'io-extra', require: 'io/extra'
gem 'rye'
platform :mri, :rbx do
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic

View file

@ -9,6 +9,8 @@ GEM
tzinfo (~> 1.1)
addressable (2.3.7)
ago (0.1.5)
annoy (0.5.6)
highline (>= 1.5.0)
ansi (1.4.3)
autoparse (0.3.3)
addressable (>= 2.3.1)
@ -50,6 +52,7 @@ GEM
docile (1.1.3)
domain_name (0.5.23)
unf (>= 0.0.5, < 1.0.0)
drydock (0.6.9)
erubis (2.7.0)
extlib (0.9.16)
fabrication (2.11.0)
@ -75,6 +78,7 @@ GEM
signet (>= 0.5.0)
uuidtools (>= 2.1.0)
hashie (2.0.5)
highline (1.7.2)
hiredis (0.5.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
@ -110,6 +114,9 @@ GEM
metaclass (~> 0.0.1)
multi_json (1.11.0)
multipart-post (2.0.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.2)
netrc (0.10.3)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
@ -160,6 +167,13 @@ GEM
netrc (~> 0.7)
retriable (1.4.1)
rmagick (2.15.0)
rye (0.9.13)
annoy
docile (>= 1.0.1)
highline (>= 1.5.1)
net-scp (>= 1.0.2)
net-ssh (>= 2.0.13)
sysinfo (>= 0.8.1)
safe_yaml (1.0.4)
sass (3.3.8)
screencap (0.1.1)
@ -198,6 +212,7 @@ GEM
sinatra-xsendfile (0.4.2)
sinatra (>= 0.9.1)
slop (3.5.0)
storable (0.8.9)
stripe (1.15.0)
json (~> 1.8.1)
mime-types (>= 1.25, < 3.0)
@ -206,6 +221,9 @@ GEM
dante (>= 0.2.0)
jimson-temp
stripe (>= 1.15.0)
sysinfo (0.8.1)
drydock
storable
thread (0.1.4)
thread_safe (0.3.4)
tilt (1.4.1)
@ -273,6 +291,7 @@ DEPENDENCIES
rest-client
rmagick
ruby-debug
rye
sass
screencap
scrypt

View file

@ -32,6 +32,17 @@ get '/site/:username/?' do |username|
erb :'site', locals: {site: site, is_current_site: site == current_site}
end
get '/site/:username/archives' do
require_login
@site = Site[username: params[:username]]
not_found if @site.nil?
redirect request.referrer unless current_site.id == @site.id
@archives = @site.archives_dataset.limit(300).order(:updated_at.desc).all
erb :'site/archives'
end
get '/site/:username/stats' do
@site = Site[username: params[:username]]
not_found if @site.nil?

View file

@ -2,4 +2,8 @@ class Archive < Sequel::Model
many_to_one :site
set_primary_key [:site_id, :ipfs_hash]
unrestrict_primary_key
def url
"https://#{ipfs_hash}.ipfs.neocities.org"
end
end

View file

@ -558,10 +558,19 @@ class Site < Sequel::Model
end
def add_to_ipfs
# Not ideal. An SoA version is in progress.
if $config['ipfs_ssh_host'] && $config['ipfs_ssh_user']
Rye::Cmd.add_command :ipfs, nil, 'add', :r
rbox = Rye::Box.new $config['ipfs_ssh_host'], :user => $config['ipfs_ssh_user']
response = rbox.ipfs "sites/#{self.username.gsub(/\/|\.\./, '')}"
output_array = response
else
line = Cocaine::CommandLine.new('ipfs', 'add -r :path')
response = line.run path: files_path
ipfs_hash = response.split("\n").last.split(' ')[1]
ipfs_hash
output_array = response.to_s.split("\n")
end
output_array.last.split(' ')[1]
end
def archive!
@ -570,6 +579,8 @@ class Site < Sequel::Model
#else
#end
ipfs_hash = add_to_ipfs
archive = archives_dataset.where(ipfs_hash: ipfs_hash).first
if archive
archive.updated_at = Time.now
@ -579,6 +590,10 @@ class Site < Sequel::Model
end
end
def latest_archive
@latest_archive ||= archives_dataset.order(:updated_at.desc).first
end
def is_directory?(path)
File.directory? files_path(path)
end

View file

@ -21,6 +21,9 @@
<div class="col col-50 profile-info">
<h2 class="eps title-with-badge"><span><%= site.title %></span> <% if site.supporter? %><a href="/plan" class="supporter-badge" title="Neocities Supporter"></a> <% end %></h2>
<p class="site-url"><a href="<%= site.uri %>"><%= site.host %></a></p>
<% if site.latest_archive %>
<p><a href="https://<%= site.latest_archive.url %>" style="margin-right: 5px">IPFS Link</a><small style="font-size: 7pt"><a href="/permanent-web">(what is this?)</a></small></p>
<% end %>
<div class="stats">
<div class="stat"><strong><%= site.views.format_large_number %></strong> <span>view<%= site.views == 1 ? '' : 's' %></span></div>
<% follows_count = site.follows_dataset.count %>
@ -33,6 +36,10 @@
<a href="/dashboard" class="btn-Action edit"><i class="fa fa-edit" title="Edit"></i> Edit Site</a>
<% end %>
<% if current_site && current_site.id == site.id && site.latest_archive %>
<a href="/site/<%= site.username %>/archives" class="btn-Action edit"><i class="fa fa-history" title="Edit"></i> Archives</a>
<% end %>
<% if current_site && current_site != site %>
<% is_following = current_site.is_following?(site) %>

30
views/site/archives.erb Normal file
View file

@ -0,0 +1,30 @@
<div class="header-Outro">
<div class="row content single-Col">
<h1>Permanent Web Archives</h1>
</div>
</div>
<div class="content single-Col misc-page">
<article role="article">
<% if @archives.length == 0 %>
No archives yet.
<% else %>
<table class="table">
<tr>
<th>IPFS Hash <small style="display: inline"><a href="/permanent-web">(what is this?)</a></small></th>
<th>Archived Time</th>
</tr>
<% @archives.each do |archive| %>
<tr>
<td><a href="<%= archive.url %>"><%= archive.ipfs_hash %></a></td>
<td><%= archive.updated_at.ago.downcase %></td>
</tr>
<% end %>
</table>
<p>
Note: This is a very early preview release of a new technology! We're still figuring things out. We may stop hosting archives without notice. <a href="/permanent-web">Learn how you can host your own copies of these archives</a>.
</p>
<% end %>
</article>
</div>