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
|
2024-12-14 20:37:53 -05:00
|
|
|
user.password = "hexerade"
|
|
|
|
user.password_confirmation = "hexerade"
|
2019-09-23 19:16:28 -04:00
|
|
|
user.password_hash = ""
|
2024-07-20 11:30:21 -04:00
|
|
|
user.email = "admin@e621.local"
|
2019-07-19 07:23:31 -04:00
|
|
|
user.can_upload_free = true
|
2021-05-01 07:24:20 -04:00
|
|
|
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
|
|
|
|
|
2019-09-23 19:16:28 -04:00
|
|
|
User.find_or_create_by!(name: Danbooru.config.system_user) do |user|
|
|
|
|
user.password = "ae3n4oie2n3oi4en23oie4noienaorshtaioresnt"
|
2020-03-04 17:00:04 -05:00
|
|
|
user.password_confirmation = "ae3n4oie2n3oi4en23oie4noienaorshtaioresnt"
|
|
|
|
user.password_hash = ""
|
2024-07-20 11:30:21 -04:00
|
|
|
user.email = "system@e621.local"
|
2019-09-23 19:16:28 -04:00
|
|
|
user.can_upload_free = true
|
2021-05-01 07:24:20 -04:00
|
|
|
user.can_approve_posts = true
|
2021-04-30 17:46:28 -04:00
|
|
|
user.level = User::Levels::JANITOR
|
2019-09-23 19:16:28 -04:00
|
|
|
end
|
|
|
|
|
2023-03-23 14:36:54 -04:00
|
|
|
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)
|
2024-04-27 17:01:10 -04:00
|
|
|
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
|
|
|
|
|
2022-10-20 12:52:07 -04:00
|
|
|
def import_mascots
|
2024-07-20 11:30:21 -04:00
|
|
|
api_request("/mascots.json?limit=1").each do |mascot|
|
2022-10-20 12:52:07 -04:00
|
|
|
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"],
|
2023-02-21 10:03:25 -05:00
|
|
|
available_on_string: Danbooru.config.app_name,
|
2022-10-20 12:52:07 -04:00
|
|
|
active: mascot["active"],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-20 11:30:21 -04:00
|
|
|
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"
|
2024-04-05 07:24:58 -04:00
|
|
|
begin
|
|
|
|
import_mascots
|
2024-07-20 11:30:21 -04:00
|
|
|
setup_upload_whitelist
|
2024-04-05 07:24:58 -04:00
|
|
|
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
|