eBooru/db/seeds.rb

75 lines
2.0 KiB
Ruby
Raw Normal View History

2019-07-19 07:23:31 -04:00
# frozen_string_literal: true
2013-04-16 23:23:02 -04:00
2019-07-19 07:23:31 -04:00
require "digest/md5"
require "net/http"
require "tempfile"
# Uncomment to see detailed logs
2022-10-20 12:39:45 -04:00
# ActiveRecord::Base.logger = ActiveSupport::Logger.new($stdout)
2019-07-19 07:23:31 -04:00
admin = User.find_or_create_by!(name: "admin") do |user|
user.created_at = 2.weeks.ago
user.password = "qwerty"
user.password_confirmation = "qwerty"
user.password_hash = ""
user.email = "admin@e621.local"
2019-07-19 07:23:31 -04:00
user.can_upload_free = true
user.can_approve_posts = true
2019-07-19 07:23:31 -04:00
user.level = User::Levels::ADMIN
2011-07-03 19:12:31 -04:00
end
User.find_or_create_by!(name: Danbooru.config.system_user) do |user|
user.password = "ae3n4oie2n3oi4en23oie4noienaorshtaioresnt"
user.password_confirmation = "ae3n4oie2n3oi4en23oie4noienaorshtaioresnt"
user.password_hash = ""
user.email = "system@e621.local"
user.can_upload_free = true
user.can_approve_posts = true
user.level = User::Levels::JANITOR
end
ForumCategory.find_or_create_by!(name: "Tag Alias and Implication Suggestions") do |category|
2021-05-14 09:04:03 -04:00
category.can_view = 0
end
2022-10-20 12:39:45 -04:00
def api_request(path)
response = Faraday.get("https://e621.net#{path}", nil, user_agent: "e621ng/seeding")
2022-10-20 12:39:45 -04:00
JSON.parse(response.body)
end
def import_mascots
api_request("/mascots.json?limit=1").each do |mascot|
puts mascot["url_path"]
Mascot.create!(
creator: CurrentUser.user,
mascot_file: Downloads::File.new(mascot["url_path"]).download!,
display_name: mascot["display_name"],
background_color: mascot["background_color"],
artist_url: mascot["artist_url"],
artist_name: mascot["artist_name"],
available_on_string: Danbooru.config.app_name,
active: mascot["active"],
)
end
end
def setup_upload_whitelist
UploadWhitelist.create do |entry|
entry.pattern = "https://static1.e621.net/*"
end
end
2022-10-20 12:39:45 -04:00
unless Rails.env.test?
CurrentUser.user = admin
CurrentUser.ip_addr = "127.0.0.1"
begin
import_mascots
setup_upload_whitelist
rescue StandardError => e
puts "--------"
puts "#{e.class}: #{e.message}"
puts "Failure during seeding, continuing on..."
puts "--------"
end
2022-10-20 12:39:45 -04:00
end