mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
Merge branch 'v2' of github.com:neocities/neocities into v2
This commit is contained in:
commit
fd22635f28
4 changed files with 58 additions and 9 deletions
|
@ -52,6 +52,9 @@ class Site < Sequel::Model
|
|||
LOSSLESS_IMAGE_REGEX = /png|bmp|gif/
|
||||
LOSSY_IMAGE_REGEX = /jpg|jpeg/
|
||||
HTML_REGEX = /htm|html/
|
||||
|
||||
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162']
|
||||
THUMBNAIL_RESOLUTIONS = ['105x63']
|
||||
|
||||
many_to_one :server
|
||||
|
||||
|
@ -180,7 +183,7 @@ class Site < Sequel::Model
|
|||
FileUtils.mv uploaded.path, file_path(filename)
|
||||
File.chmod(0640, file_path(filename))
|
||||
|
||||
ext = File.extname(filename).gsub('.', '')
|
||||
ext = File.extname(filename).gsub(/^./, '')
|
||||
|
||||
if ext.match HTML_REGEX
|
||||
ScreenshotWorker.perform_async values[:username], filename
|
||||
|
@ -218,8 +221,13 @@ class Site < Sequel::Model
|
|||
begin
|
||||
FileUtils.rm file_path(filename)
|
||||
rescue Errno::ENOENT
|
||||
return false
|
||||
end
|
||||
|
||||
ext = File.extname(filename).gsub(/^./, '')
|
||||
|
||||
screenshots_delete(filename) if ext.match HTML_REGEX
|
||||
thumbnails_delete(filename) if ext.match IMAGE_REGEX
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
|
@ -369,6 +377,28 @@ class Site < Sequel::Model
|
|||
values[:title] || values[:username]
|
||||
end
|
||||
|
||||
def screenshots_delete(filename)
|
||||
SCREENSHOT_RESOLUTIONS.each do |res|
|
||||
begin
|
||||
FileUtils.rm screenshot_path(filename, res)
|
||||
rescue Errno::ENOENT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def thumbnails_delete(filename)
|
||||
THUMBNAIL_RESOLUTIONS.each do |res|
|
||||
begin
|
||||
FileUtils.rm thumbnail_path(filename, res)
|
||||
rescue Errno::ENOENT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def screenshot_path(filename, resolution)
|
||||
File.join(SCREENSHOTS_ROOT, values[:username], "#{filename}.#{resolution}.jpg")
|
||||
end
|
||||
|
||||
def screenshot_exists?(filename, resolution)
|
||||
File.exist? File.join(SCREENSHOTS_ROOT, values[:username], "#{filename}.#{resolution}.jpg")
|
||||
end
|
||||
|
@ -377,9 +407,17 @@ class Site < Sequel::Model
|
|||
"#{SCREENSHOTS_URL_ROOT}/#{values[:username]}/#{filename}.#{resolution}.jpg"
|
||||
end
|
||||
|
||||
def thumbnail_exists?(filename, resolution)
|
||||
def thumbnail_path(filename, resolution)
|
||||
ext = File.extname(filename).gsub('.', '').match(LOSSY_IMAGE_REGEX) ? 'jpg' : 'png'
|
||||
File.exist?(File.join(THUMBNAILS_ROOT, values[:username], "#{filename}.#{resolution}.#{ext}"))
|
||||
File.join THUMBNAILS_ROOT, values[:username], "#{filename}.#{resolution}.#{ext}"
|
||||
end
|
||||
|
||||
def thumbnail_exists?(filename, resolution)
|
||||
File.exist? thumbnail_path(filename, resolution)
|
||||
end
|
||||
|
||||
def thumbnail_delete(filename, resolution)
|
||||
File.rm thumbnail_path(filename, resolution)
|
||||
end
|
||||
|
||||
def thumbnail_url(filename, resolution)
|
||||
|
|
|
@ -54,17 +54,30 @@
|
|||
|
||||
<div class="content wide">
|
||||
|
||||
<% unless current_site.changed_count > 5 %>
|
||||
<div class="welcome">
|
||||
<div class="close-button"></div>
|
||||
<!-- <div class="close-button"></div> -->
|
||||
<h4>Hello! Welcome to your new site.</h4>
|
||||
To get started, click on the <strong>index.html</strong> file below to edit it. It's your home page! You can add more files (such as images) from your computer by dragging them into the box below. Need help building web sites? Check out these <a href="/tutorials">tutorials</a>!
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @error %>
|
||||
<div class="alert alert-block alert-error">
|
||||
<p><%= @error %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if flash.keys.length > 0 %>
|
||||
<div class="alert alert-block">
|
||||
<p>
|
||||
<% flash.keys.each do |key| %>
|
||||
<%= flash[key] %>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<div class="files">
|
||||
<div class="header">
|
||||
|
|
|
@ -27,7 +27,6 @@ module Phantomjs
|
|||
end
|
||||
|
||||
class ScreenshotWorker
|
||||
REQUIRED_RESOLUTIONS = ['235x141', '105x63', '270x162']
|
||||
SCREENSHOTS_PATH = File.join DIR_ROOT, 'public', 'site_screenshots'
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: :screenshots, retry: 3, backtrace: true
|
||||
|
@ -82,7 +81,7 @@ class ScreenshotWorker
|
|||
user_screenshots_path = File.join SCREENSHOTS_PATH, username
|
||||
FileUtils.mkdir_p user_screenshots_path
|
||||
|
||||
REQUIRED_RESOLUTIONS.each do |res|
|
||||
Site::SCREENSHOT_RESOLUTIONS.each do |res|
|
||||
img.scale(*res.split('x').collect {|r| r.to_i}).write(File.join(user_screenshots_path, "#{filename}.#{res}.jpg")) {
|
||||
self.quality = 90
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'RMagick'
|
||||
|
||||
class ThumbnailWorker
|
||||
REQUIRED_RESOLUTIONS = ['105x63']
|
||||
THUMBNAILS_PATH = File.join DIR_ROOT, 'public', 'site_thumbnails'
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: :thumbnails, retry: 3, backtrace: true
|
||||
|
@ -14,7 +13,7 @@ class ThumbnailWorker
|
|||
user_thumbnails_path = File.join THUMBNAILS_PATH, username
|
||||
FileUtils.mkdir_p user_thumbnails_path
|
||||
|
||||
REQUIRED_RESOLUTIONS.each do |res|
|
||||
Site::THUMBNAIL_RESOLUTIONS.each do |res|
|
||||
resimg = img.resize_to_fit(*res.split('x').collect {|r| r.to_i})
|
||||
format = File.extname(filename).gsub('.', '')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue