mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
integrate IPFS using remote ssh for now, views
This commit is contained in:
parent
8424cc02e8
commit
59feb09928
8 changed files with 92 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -34,3 +34,4 @@ files/sslsites.zip
|
||||||
.vagrant
|
.vagrant
|
||||||
public/banned_sites
|
public/banned_sites
|
||||||
public/deleted_sites
|
public/deleted_sites
|
||||||
|
tests/stat_logs/*
|
||||||
|
|
1
Gemfile
1
Gemfile
|
@ -28,6 +28,7 @@ gem 'rack-cache'
|
||||||
gem 'rest-client'
|
gem 'rest-client'
|
||||||
gem 'geoip'
|
gem 'geoip'
|
||||||
gem 'io-extra', require: 'io/extra'
|
gem 'io-extra', require: 'io/extra'
|
||||||
|
gem 'rye'
|
||||||
|
|
||||||
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
|
||||||
|
|
19
Gemfile.lock
19
Gemfile.lock
|
@ -9,6 +9,8 @@ GEM
|
||||||
tzinfo (~> 1.1)
|
tzinfo (~> 1.1)
|
||||||
addressable (2.3.7)
|
addressable (2.3.7)
|
||||||
ago (0.1.5)
|
ago (0.1.5)
|
||||||
|
annoy (0.5.6)
|
||||||
|
highline (>= 1.5.0)
|
||||||
ansi (1.4.3)
|
ansi (1.4.3)
|
||||||
autoparse (0.3.3)
|
autoparse (0.3.3)
|
||||||
addressable (>= 2.3.1)
|
addressable (>= 2.3.1)
|
||||||
|
@ -50,6 +52,7 @@ GEM
|
||||||
docile (1.1.3)
|
docile (1.1.3)
|
||||||
domain_name (0.5.23)
|
domain_name (0.5.23)
|
||||||
unf (>= 0.0.5, < 1.0.0)
|
unf (>= 0.0.5, < 1.0.0)
|
||||||
|
drydock (0.6.9)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
extlib (0.9.16)
|
extlib (0.9.16)
|
||||||
fabrication (2.11.0)
|
fabrication (2.11.0)
|
||||||
|
@ -75,6 +78,7 @@ GEM
|
||||||
signet (>= 0.5.0)
|
signet (>= 0.5.0)
|
||||||
uuidtools (>= 2.1.0)
|
uuidtools (>= 2.1.0)
|
||||||
hashie (2.0.5)
|
hashie (2.0.5)
|
||||||
|
highline (1.7.2)
|
||||||
hiredis (0.5.0)
|
hiredis (0.5.0)
|
||||||
http-cookie (1.0.2)
|
http-cookie (1.0.2)
|
||||||
domain_name (~> 0.5)
|
domain_name (~> 0.5)
|
||||||
|
@ -110,6 +114,9 @@ GEM
|
||||||
metaclass (~> 0.0.1)
|
metaclass (~> 0.0.1)
|
||||||
multi_json (1.11.0)
|
multi_json (1.11.0)
|
||||||
multipart-post (2.0.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)
|
netrc (0.10.3)
|
||||||
nokogiri (1.6.6.2)
|
nokogiri (1.6.6.2)
|
||||||
mini_portile (~> 0.6.0)
|
mini_portile (~> 0.6.0)
|
||||||
|
@ -160,6 +167,13 @@ GEM
|
||||||
netrc (~> 0.7)
|
netrc (~> 0.7)
|
||||||
retriable (1.4.1)
|
retriable (1.4.1)
|
||||||
rmagick (2.15.0)
|
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)
|
safe_yaml (1.0.4)
|
||||||
sass (3.3.8)
|
sass (3.3.8)
|
||||||
screencap (0.1.1)
|
screencap (0.1.1)
|
||||||
|
@ -198,6 +212,7 @@ GEM
|
||||||
sinatra-xsendfile (0.4.2)
|
sinatra-xsendfile (0.4.2)
|
||||||
sinatra (>= 0.9.1)
|
sinatra (>= 0.9.1)
|
||||||
slop (3.5.0)
|
slop (3.5.0)
|
||||||
|
storable (0.8.9)
|
||||||
stripe (1.15.0)
|
stripe (1.15.0)
|
||||||
json (~> 1.8.1)
|
json (~> 1.8.1)
|
||||||
mime-types (>= 1.25, < 3.0)
|
mime-types (>= 1.25, < 3.0)
|
||||||
|
@ -206,6 +221,9 @@ GEM
|
||||||
dante (>= 0.2.0)
|
dante (>= 0.2.0)
|
||||||
jimson-temp
|
jimson-temp
|
||||||
stripe (>= 1.15.0)
|
stripe (>= 1.15.0)
|
||||||
|
sysinfo (0.8.1)
|
||||||
|
drydock
|
||||||
|
storable
|
||||||
thread (0.1.4)
|
thread (0.1.4)
|
||||||
thread_safe (0.3.4)
|
thread_safe (0.3.4)
|
||||||
tilt (1.4.1)
|
tilt (1.4.1)
|
||||||
|
@ -273,6 +291,7 @@ DEPENDENCIES
|
||||||
rest-client
|
rest-client
|
||||||
rmagick
|
rmagick
|
||||||
ruby-debug
|
ruby-debug
|
||||||
|
rye
|
||||||
sass
|
sass
|
||||||
screencap
|
screencap
|
||||||
scrypt
|
scrypt
|
||||||
|
|
11
app/site.rb
11
app/site.rb
|
@ -32,6 +32,17 @@ get '/site/:username/?' do |username|
|
||||||
erb :'site', locals: {site: site, is_current_site: site == current_site}
|
erb :'site', locals: {site: site, is_current_site: site == current_site}
|
||||||
end
|
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
|
get '/site/:username/stats' do
|
||||||
@site = Site[username: params[:username]]
|
@site = Site[username: params[:username]]
|
||||||
not_found if @site.nil?
|
not_found if @site.nil?
|
||||||
|
|
|
@ -2,4 +2,8 @@ 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 url
|
||||||
|
"https://#{ipfs_hash}.ipfs.neocities.org"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -558,10 +558,19 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_to_ipfs
|
def add_to_ipfs
|
||||||
line = Cocaine::CommandLine.new('ipfs', 'add -r :path')
|
# Not ideal. An SoA version is in progress.
|
||||||
response = line.run path: files_path
|
if $config['ipfs_ssh_host'] && $config['ipfs_ssh_user']
|
||||||
ipfs_hash = response.split("\n").last.split(' ')[1]
|
Rye::Cmd.add_command :ipfs, nil, 'add', :r
|
||||||
ipfs_hash
|
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
|
||||||
|
output_array = response.to_s.split("\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
output_array.last.split(' ')[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive!
|
def archive!
|
||||||
|
@ -570,6 +579,8 @@ class Site < Sequel::Model
|
||||||
#else
|
#else
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
ipfs_hash = add_to_ipfs
|
||||||
|
|
||||||
archive = archives_dataset.where(ipfs_hash: ipfs_hash).first
|
archive = archives_dataset.where(ipfs_hash: ipfs_hash).first
|
||||||
if archive
|
if archive
|
||||||
archive.updated_at = Time.now
|
archive.updated_at = Time.now
|
||||||
|
@ -579,6 +590,10 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def latest_archive
|
||||||
|
@latest_archive ||= archives_dataset.order(:updated_at.desc).first
|
||||||
|
end
|
||||||
|
|
||||||
def is_directory?(path)
|
def is_directory?(path)
|
||||||
File.directory? files_path(path)
|
File.directory? files_path(path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
<div class="col col-50 profile-info">
|
<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>
|
<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>
|
<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="stats">
|
||||||
<div class="stat"><strong><%= site.views.format_large_number %></strong> <span>view<%= site.views == 1 ? '' : 's' %></span></div>
|
<div class="stat"><strong><%= site.views.format_large_number %></strong> <span>view<%= site.views == 1 ? '' : 's' %></span></div>
|
||||||
<% follows_count = site.follows_dataset.count %>
|
<% 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>
|
<a href="/dashboard" class="btn-Action edit"><i class="fa fa-edit" title="Edit"></i> Edit Site</a>
|
||||||
<% end %>
|
<% 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 %>
|
<% if current_site && current_site != site %>
|
||||||
<% is_following = current_site.is_following?(site) %>
|
<% is_following = current_site.is_following?(site) %>
|
||||||
|
|
||||||
|
|
30
views/site/archives.erb
Normal file
30
views/site/archives.erb
Normal 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>
|
Loading…
Add table
Reference in a new issue