Merge remote-tracking branch 'parent/main' into upstream-20240310
This commit is contained in:
commit
5979c0ea1d
345 changed files with 4304 additions and 2540 deletions
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../mastodon/database'
|
||||
require_relative '../mastodon/snowflake'
|
||||
|
||||
module ActiveRecord
|
||||
|
@ -8,6 +9,8 @@ module ActiveRecord
|
|||
original_load_schema = instance_method(:load_schema)
|
||||
|
||||
define_method(:load_schema) do |db_config, *args|
|
||||
Mastodon::Database.add_post_migrate_path_to_rails(force: true)
|
||||
|
||||
ActiveRecord::Base.establish_connection(db_config)
|
||||
Mastodon::Snowflake.define_timestamp_id
|
||||
|
||||
|
|
46
lib/mastodon/database.rb
Normal file
46
lib/mastodon/database.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# This file is entirely lifted from GitLab.
|
||||
|
||||
# The original file:
|
||||
# https://gitlab.com/gitlab-org/gitlab/-/blob/69127d59467185cf4ff1109d88ceec1f499f354f/lib/gitlab/database.rb#L244-258
|
||||
|
||||
# Copyright (c) 2011-present GitLab B.V.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
module Mastodon
|
||||
module Database
|
||||
def self.add_post_migrate_path_to_rails(force: false)
|
||||
return if ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS'] && !force
|
||||
|
||||
Rails.application.config.paths['db'].each do |db_path|
|
||||
path = Rails.root.join(db_path, 'post_migrate').to_s
|
||||
|
||||
next if Rails.application.config.paths['db/migrate'].include?(path)
|
||||
|
||||
Rails.application.config.paths['db/migrate'] << path
|
||||
|
||||
# Rails memoizes migrations at certain points where it won't read the above
|
||||
# path just yet. As such we must also update the following list of paths.
|
||||
ActiveRecord::Migrator.migrations_paths << path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/mastodon/feature.rb
Normal file
26
lib/mastodon/feature.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Mastodon::Feature
|
||||
class << self
|
||||
def enabled_features
|
||||
@enabled_features ||=
|
||||
(Rails.configuration.x.mastodon.experimental_features || '').split(',').map(&:strip)
|
||||
end
|
||||
|
||||
def method_missing(name)
|
||||
if respond_to_missing?(name)
|
||||
feature = name.to_s.delete_suffix('_enabled?')
|
||||
enabled = enabled_features.include?(feature)
|
||||
define_singleton_method(name) { enabled }
|
||||
|
||||
return enabled
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
def respond_to_missing?(name)
|
||||
name.to_s.end_with?('_enabled?')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -96,7 +96,7 @@ module Mastodon
|
|||
|
||||
def api_versions
|
||||
{
|
||||
mastodon: 3,
|
||||
mastodon: 4,
|
||||
kmyblue: KMYBLUE_API_VERSION,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -103,4 +103,36 @@ namespace :emojis do
|
|||
gen_border map[emoji], 'white'
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Download the JSON sheet data of emojis'
|
||||
task :download_sheet_json do
|
||||
source = 'https://raw.githubusercontent.com/iamcal/emoji-data/refs/tags/v15.1.2/emoji.json'
|
||||
dest = Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_sheet.json')
|
||||
|
||||
puts "Downloading emoji data from source... (#{source})"
|
||||
|
||||
res = HTTP.get(source).to_s
|
||||
data = JSON.parse(res)
|
||||
|
||||
filtered_data = data.map do |emoji|
|
||||
filtered_item = {
|
||||
'unified' => emoji['unified'],
|
||||
'sheet_x' => emoji['sheet_x'],
|
||||
'sheet_y' => emoji['sheet_y'],
|
||||
'skin_variations' => {},
|
||||
}
|
||||
|
||||
emoji['skin_variations']&.each do |key, variation|
|
||||
filtered_item['skin_variations'][key] = {
|
||||
'unified' => variation['unified'],
|
||||
'sheet_x' => variation['sheet_x'],
|
||||
'sheet_y' => variation['sheet_y'],
|
||||
}
|
||||
end
|
||||
|
||||
filtered_item
|
||||
end
|
||||
|
||||
File.write(dest, JSON.generate(filtered_data))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue