コミットを比較
13 コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| 546a212e74 | |||
| 201fe72e5a | |||
| 6e338c8616 | |||
| be2df723fe | |||
| 39d86f4778 | |||
| 69820265fd | |||
| 4b26f017b4 | |||
| a50c29cc35 | |||
| 364d154b6a | |||
| b1362d327c | |||
| 81e620c33a | |||
| 62857adb87 | |||
| 09763982b5 |
@@ -126,16 +126,12 @@ npm run preview
|
|||||||
- In TypeScript and TSX only, replace every leading run of 8 spaces with a tab.
|
- In TypeScript and TSX only, replace every leading run of 8 spaces with a tab.
|
||||||
- Tabs are only for leading indentation, never for spaces after non-space text.
|
- Tabs are only for leading indentation, never for spaces after non-space text.
|
||||||
- Do not add production dependencies without explicit approval.
|
- Do not add production dependencies without explicit approval.
|
||||||
- Do not create, modify, or run tests unless the user explicitly asks for
|
|
||||||
test work. When the user asks for tests, keep working and rerun them until
|
|
||||||
they pass or the remaining failure is clearly blocked.
|
|
||||||
|
|
||||||
## Backend rules
|
## Backend rules
|
||||||
|
|
||||||
- Inspect existing routes, controllers, models, services, and specs before
|
- Inspect existing routes, controllers, models, services, and specs before
|
||||||
editing backend behavior.
|
editing backend behavior.
|
||||||
- For API behavior changes, add or update request specs under
|
- For API behavior changes, add or update request specs under `backend/spec/requests`.
|
||||||
`backend/spec/requests` only when the user explicitly asks for tests.
|
|
||||||
- Prefer RSpec for new backend tests; existing minitest files under
|
- Prefer RSpec for new backend tests; existing minitest files under
|
||||||
`backend/test` do not make minitest the default for new coverage.
|
`backend/test` do not make minitest the default for new coverage.
|
||||||
- Do not weaken authentication, BAN user checks, or IP BAN checks.
|
- Do not weaken authentication, BAN user checks, or IP BAN checks.
|
||||||
@@ -215,11 +211,10 @@ function PostFormTagsArea ({ tags, setTags }: Props) {
|
|||||||
`node_modules`, `dist`, `tmp`, `log`, and `storage` unless explicitly needed.
|
`node_modules`, `dist`, `tmp`, `log`, and `storage` unless explicitly needed.
|
||||||
- Before touching wiki, tag, versioning, BAN, IP BAN, or authentication
|
- Before touching wiki, tag, versioning, BAN, IP BAN, or authentication
|
||||||
behavior, inspect the related request specs and service objects.
|
behavior, inspect the related request specs and service objects.
|
||||||
- If frontend code changes, run only non-test verification commands that
|
- If frontend code changes, run the existing frontend verification commands
|
||||||
apply, such as `npm run build` and `npm run lint`. Run `npm run test:run`
|
that apply: `npm run build`, `npm run lint`, and `npm run test:run`.
|
||||||
only when the user explicitly asks for tests.
|
- If backend code changes, run the relevant RSpec command; for broad backend
|
||||||
- If backend code changes, do not run RSpec unless the user explicitly asks
|
changes, run `bundle exec rspec`.
|
||||||
for tests.
|
|
||||||
- If a verification command cannot be run or fails, report the exact command and failure.
|
- If a verification command cannot be run or fails, report the exact command and failure.
|
||||||
|
|
||||||
## Completion criteria
|
## Completion criteria
|
||||||
@@ -227,8 +222,7 @@ function PostFormTagsArea ({ tags, setTags }: Props) {
|
|||||||
A task is complete only when:
|
A task is complete only when:
|
||||||
|
|
||||||
- implementation is complete,
|
- implementation is complete,
|
||||||
- relevant non-test verification commands pass, or failures are clearly
|
- relevant verification commands pass, or failures are clearly explained,
|
||||||
explained,
|
|
||||||
- unrelated files are not changed,
|
- unrelated files are not changed,
|
||||||
- migrations and schema are consistent when schema changes are made,
|
- migrations and schema are consistent when schema changes are made,
|
||||||
- user-facing behavior is documented when needed.
|
- user-facing behavior is documented when needed.
|
||||||
|
|||||||
+4
-11
@@ -47,10 +47,6 @@ bundle exec rspec
|
|||||||
|
|
||||||
If a command cannot be run or fails, report the exact command and failure.
|
If a command cannot be run or fails, report the exact command and failure.
|
||||||
|
|
||||||
Do not create, modify, or run tests unless the user explicitly asks for test
|
|
||||||
work. When the user asks for tests, keep working and rerun them until they
|
|
||||||
pass or the remaining failure is clearly blocked.
|
|
||||||
|
|
||||||
## Rails structure
|
## Rails structure
|
||||||
|
|
||||||
- `app/controllers`: API controllers.
|
- `app/controllers`: API controllers.
|
||||||
@@ -120,8 +116,7 @@ service, representation, and spec.
|
|||||||
- `User#banned?` and `IpAddress#banned?` check `banned_at.present?`.
|
- `User#banned?` and `IpAddress#banned?` check `banned_at.present?`.
|
||||||
- Do not weaken BAN or IP BAN behavior.
|
- Do not weaken BAN or IP BAN behavior.
|
||||||
- If changing request authentication or controller before actions, add or
|
- If changing request authentication or controller before actions, add or
|
||||||
update request specs covering banned users and banned IP addresses only when
|
update request specs covering banned users and banned IP addresses.
|
||||||
the user explicitly asks for tests.
|
|
||||||
|
|
||||||
## RSpec
|
## RSpec
|
||||||
|
|
||||||
@@ -135,9 +130,8 @@ service, representation, and spec.
|
|||||||
- `AuthHelper#sign_in_as(user)` stubs
|
- `AuthHelper#sign_in_as(user)` stubs
|
||||||
`ApplicationController#current_user`; use it when matching existing
|
`ApplicationController#current_user`; use it when matching existing
|
||||||
request spec style.
|
request spec style.
|
||||||
- Add or update request specs for API behavior changes only when the user
|
- Add or update request specs for API behavior changes, especially status
|
||||||
explicitly asks for tests, especially status codes, permissions, response
|
codes, permissions, response shape, and version conflict behavior.
|
||||||
shape, and version conflict behavior.
|
|
||||||
|
|
||||||
## Migrations
|
## Migrations
|
||||||
|
|
||||||
@@ -170,8 +164,7 @@ service, representation, and spec.
|
|||||||
the record `version_no`.
|
the record `version_no`.
|
||||||
- Do not update versioned records without considering whether a version snapshot must be created.
|
- Do not update versioned records without considering whether a version snapshot must be created.
|
||||||
- For optimistic concurrency paths, preserve `base_version_no`, `force`, and
|
- For optimistic concurrency paths, preserve `base_version_no`, `force`, and
|
||||||
`merge` semantics. Cover conflicts in request specs only when the user
|
`merge` semantics and cover conflicts in request specs.
|
||||||
explicitly asks for tests.
|
|
||||||
|
|
||||||
## Domain cautions
|
## Domain cautions
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
class GekanatorGamesController < ApplicationController
|
|
||||||
def create
|
|
||||||
return head :not_found unless current_user&.admin?
|
|
||||||
|
|
||||||
guessed_post_id = params.require(:guessed_post_id)
|
|
||||||
correct_post_id = params[:correct_post_id].presence
|
|
||||||
answers = params.require(:answers).as_json
|
|
||||||
|
|
||||||
game = GekanatorGame.new(
|
|
||||||
user: current_user,
|
|
||||||
guessed_post_id:,
|
|
||||||
correct_post_id:,
|
|
||||||
won: correct_post_id.present? && guessed_post_id.to_i == correct_post_id.to_i,
|
|
||||||
question_count: answers.length,
|
|
||||||
answers:)
|
|
||||||
|
|
||||||
if game.save
|
|
||||||
render json: { id: game.id }, status: :created
|
|
||||||
else
|
|
||||||
render json: { errors: game.errors.full_messages }, status: :unprocessable_entity
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
class GekanatorPostsController < ApplicationController
|
|
||||||
def index
|
|
||||||
return head :not_found unless current_user&.admin?
|
|
||||||
|
|
||||||
posts =
|
|
||||||
Post
|
|
||||||
.preload(tags: :tag_name)
|
|
||||||
.with_attached_thumbnail
|
|
||||||
.order(Arel.sql(
|
|
||||||
'COALESCE(posts.original_created_before - INTERVAL 1 MINUTE, ' \
|
|
||||||
'posts.original_created_from, posts.created_at) DESC, posts.id DESC'))
|
|
||||||
|
|
||||||
render json: { posts: posts.map { |post| post_json(post) } }
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def post_json post
|
|
||||||
{
|
|
||||||
id: post.id,
|
|
||||||
url: post.url,
|
|
||||||
title: post.title,
|
|
||||||
thumbnail: thumbnail_url(post),
|
|
||||||
thumbnail_base: post.thumbnail_base,
|
|
||||||
original_created_from: post.original_created_from,
|
|
||||||
original_created_before: post.original_created_before,
|
|
||||||
tags: post.tags.map { |tag| tag_json(tag) }
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def tag_json tag
|
|
||||||
{
|
|
||||||
id: tag.id,
|
|
||||||
name: tag.name,
|
|
||||||
category: tag.category
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def thumbnail_url post
|
|
||||||
return nil unless post.thumbnail.attached?
|
|
||||||
|
|
||||||
rails_storage_proxy_url(post.thumbnail, only_path: false)
|
|
||||||
rescue
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
class GekanatorQuestionSuggestionsController < ApplicationController
|
|
||||||
def create
|
|
||||||
return head :not_found unless current_user&.admin?
|
|
||||||
|
|
||||||
game = GekanatorGame.find_by(id: params.require(:gekanator_game_id))
|
|
||||||
return head :not_found unless game
|
|
||||||
|
|
||||||
suggestion = GekanatorQuestionSuggestion.new(
|
|
||||||
gekanator_game: game,
|
|
||||||
user: current_user,
|
|
||||||
question_text: params.require(:question_text),
|
|
||||||
answer: params.require(:answer))
|
|
||||||
|
|
||||||
if suggestion.save
|
|
||||||
render json: {
|
|
||||||
id: suggestion.id,
|
|
||||||
count: game.question_suggestions.count
|
|
||||||
}, status: :created
|
|
||||||
else
|
|
||||||
render_validation_error suggestion
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def ai_convert
|
|
||||||
return head :not_found unless current_user&.admin?
|
|
||||||
|
|
||||||
suggestion = GekanatorQuestionSuggestion.find_by(id: params[:id])
|
|
||||||
return head :not_found unless suggestion
|
|
||||||
if Gekanator::AiRunBudget.exceeded_after_next_run?
|
|
||||||
suggestion.gekanator_ai_runs.create!(
|
|
||||||
model: 'budget_guard',
|
|
||||||
status: 'blocked_budget',
|
|
||||||
input_tokens: 0,
|
|
||||||
output_tokens: 0,
|
|
||||||
estimated_cost_jpy: 0)
|
|
||||||
return head :payment_required
|
|
||||||
end
|
|
||||||
|
|
||||||
Gekanator::QuestionSuggestionAiConverter.call(
|
|
||||||
suggestion: suggestion,
|
|
||||||
user: current_user)
|
|
||||||
head :no_content
|
|
||||||
rescue NotImplementedError
|
|
||||||
head :not_implemented
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
class GekanatorQuestionsController < ApplicationController
|
|
||||||
def index
|
|
||||||
return head :not_found unless current_user&.admin?
|
|
||||||
|
|
||||||
questions = GekanatorQuestion.accepted.order(priority_weight: :desc, id: :asc)
|
|
||||||
|
|
||||||
render json: {
|
|
||||||
questions: questions.map { |question| question_json(question) }
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def question_json question
|
|
||||||
{
|
|
||||||
id: question_id_for(question),
|
|
||||||
text: question.text,
|
|
||||||
kind: question.kind,
|
|
||||||
condition: condition_json(question.condition),
|
|
||||||
source: question.source,
|
|
||||||
priority_weight: question.priority_weight
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def question_id_for question
|
|
||||||
condition = condition_json(question.condition).deep_symbolize_keys
|
|
||||||
|
|
||||||
case condition[:type]
|
|
||||||
when 'tag'
|
|
||||||
"tag:#{ condition[:key] }"
|
|
||||||
when 'source'
|
|
||||||
"source:#{ condition[:host] }"
|
|
||||||
when 'original-year'
|
|
||||||
"original-year:#{ condition[:year] }"
|
|
||||||
when 'original-month'
|
|
||||||
"original-month:#{ condition[:month] }"
|
|
||||||
when 'original-month-day'
|
|
||||||
"original-month-day:#{ condition[:monthDay] || condition[:month_day] }"
|
|
||||||
when 'title-length-greater-than'
|
|
||||||
"title:length-greater-than:#{ condition[:length] }"
|
|
||||||
when 'title-has-ascii'
|
|
||||||
'title:ascii'
|
|
||||||
else
|
|
||||||
"catalog:#{ question.id }"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def condition_json condition
|
|
||||||
json = condition.deep_dup.as_json
|
|
||||||
|
|
||||||
if json['type'] == 'original-month-day' && json['monthDay'].blank?
|
|
||||||
json['monthDay'] = json.delete('month_day')
|
|
||||||
end
|
|
||||||
|
|
||||||
json
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
class GekanatorAiRun < ApplicationRecord
|
|
||||||
STATUSES = ['pending', 'running', 'succeeded', 'failed', 'blocked_budget'].freeze
|
|
||||||
|
|
||||||
belongs_to :gekanator_question_suggestion
|
|
||||||
|
|
||||||
validates :model, presence: true, length: { maximum: 255 }
|
|
||||||
validates :status, presence: true, inclusion: { in: STATUSES }
|
|
||||||
validates :input_tokens,
|
|
||||||
presence: true,
|
|
||||||
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
|
||||||
validates :output_tokens,
|
|
||||||
presence: true,
|
|
||||||
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
|
||||||
validates :estimated_cost_jpy,
|
|
||||||
presence: true,
|
|
||||||
numericality: { greater_than_or_equal_to: 0 }
|
|
||||||
|
|
||||||
scope :this_month, lambda {
|
|
||||||
where(created_at: Time.current.beginning_of_month..Time.current.end_of_month)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
class GekanatorGame < ApplicationRecord
|
|
||||||
belongs_to :user
|
|
||||||
belongs_to :guessed_post, class_name: 'Post'
|
|
||||||
belongs_to :correct_post, class_name: 'Post'
|
|
||||||
has_many :question_suggestions,
|
|
||||||
class_name: 'GekanatorQuestionSuggestion',
|
|
||||||
dependent: :delete_all
|
|
||||||
|
|
||||||
validates :answers, presence: true
|
|
||||||
validates :question_count, numericality: { greater_than_or_equal_to: 0 }
|
|
||||||
validates :won, inclusion: { in: [true, false] }
|
|
||||||
end
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
class GekanatorQuestion < ApplicationRecord
|
|
||||||
KINDS = ['tag', 'source', 'title', 'original_date'].freeze
|
|
||||||
SOURCES = ['user_suggested', 'ai_generated', 'admin_curated'].freeze
|
|
||||||
STATUSES = ['pending', 'accepted', 'rejected'].freeze
|
|
||||||
|
|
||||||
belongs_to :gekanator_question_suggestion, optional: true
|
|
||||||
belongs_to :created_by, class_name: 'User', optional: true
|
|
||||||
|
|
||||||
validates :kind, presence: true, inclusion: { in: KINDS }
|
|
||||||
validates :source, presence: true, inclusion: { in: SOURCES }
|
|
||||||
validates :status, presence: true, inclusion: { in: STATUSES }
|
|
||||||
validates :text, presence: true, length: { maximum: 1000 }
|
|
||||||
validates :condition, presence: true
|
|
||||||
validates :priority_weight,
|
|
||||||
presence: true,
|
|
||||||
numericality: {
|
|
||||||
greater_than: 0,
|
|
||||||
less_than_or_equal_to: 3
|
|
||||||
}
|
|
||||||
|
|
||||||
scope :accepted, -> { where(status: 'accepted') }
|
|
||||||
end
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
class GekanatorQuestionSuggestion < ApplicationRecord
|
|
||||||
MAX_QUESTIONS_PER_GAME = 3
|
|
||||||
ANSWERS = ['yes', 'no', 'partial', 'probably_no', 'unknown'].freeze
|
|
||||||
|
|
||||||
belongs_to :gekanator_game
|
|
||||||
belongs_to :user
|
|
||||||
has_many :gekanator_questions, dependent: :nullify
|
|
||||||
has_many :gekanator_ai_runs, dependent: :destroy
|
|
||||||
|
|
||||||
validates :question_text, presence: true, length: { maximum: 1000 }
|
|
||||||
validates :answer, presence: true, inclusion: { in: ANSWERS }
|
|
||||||
validates :processed, inclusion: { in: [true, false] }
|
|
||||||
validate :question_suggestion_limit_per_game, on: :create
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def question_suggestion_limit_per_game
|
|
||||||
return if gekanator_game_id.blank?
|
|
||||||
|
|
||||||
count = GekanatorQuestionSuggestion.where(gekanator_game_id:).count
|
|
||||||
if count >= MAX_QUESTIONS_PER_GAME
|
|
||||||
errors.add(:base, '質問追加数を超えてゐます.')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -11,16 +11,6 @@ class Post < ApplicationRecord
|
|||||||
has_many :user_post_views, dependent: :delete_all
|
has_many :user_post_views, dependent: :delete_all
|
||||||
has_many :post_similarities, dependent: :delete_all
|
has_many :post_similarities, dependent: :delete_all
|
||||||
has_many :post_versions
|
has_many :post_versions
|
||||||
has_many :gekanator_guessed_games,
|
|
||||||
class_name: 'GekanatorGame',
|
|
||||||
foreign_key: :guessed_post_id,
|
|
||||||
dependent: :delete_all,
|
|
||||||
inverse_of: :guessed_post
|
|
||||||
has_many :gekanator_correct_games,
|
|
||||||
class_name: 'GekanatorGame',
|
|
||||||
foreign_key: :correct_post_id,
|
|
||||||
dependent: :delete_all,
|
|
||||||
inverse_of: :correct_post
|
|
||||||
|
|
||||||
has_many :parent_post_implications,
|
has_many :parent_post_implications,
|
||||||
class_name: 'PostImplication',
|
class_name: 'PostImplication',
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
module Gekanator
|
|
||||||
class AiRunBudget
|
|
||||||
MONTHLY_LIMIT_JPY = BigDecimal('450').freeze
|
|
||||||
MAX_RUN_ESTIMATED_COST_JPY = BigDecimal('5').freeze
|
|
||||||
|
|
||||||
def self.remaining_monthly_budget_jpy
|
|
||||||
MONTHLY_LIMIT_JPY - monthly_cost_jpy
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.monthly_cost_jpy
|
|
||||||
GekanatorAiRun.this_month.sum(:estimated_cost_jpy)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.exceeded?
|
|
||||||
monthly_cost_jpy >= MONTHLY_LIMIT_JPY
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.exceeded_after_next_run?
|
|
||||||
monthly_cost_jpy + MAX_RUN_ESTIMATED_COST_JPY >= MONTHLY_LIMIT_JPY
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
module Gekanator
|
|
||||||
class QuestionSuggestionAiConverter
|
|
||||||
def self.call(...) = new(...).call
|
|
||||||
|
|
||||||
def initialize suggestion:, user:
|
|
||||||
@suggestion = suggestion
|
|
||||||
@user = user
|
|
||||||
end
|
|
||||||
|
|
||||||
def call
|
|
||||||
raise NotImplementedError, 'AI question conversion is not implemented yet.'
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
attr_reader :suggestion, :user
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -63,19 +63,6 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :gekanator do
|
|
||||||
resources :games, only: [:create], controller: '/gekanator_games'
|
|
||||||
resources :posts, only: [:index], controller: '/gekanator_posts'
|
|
||||||
resources :questions, only: [:index], controller: '/gekanator_questions'
|
|
||||||
resources :question_suggestions,
|
|
||||||
only: [:create],
|
|
||||||
controller: '/gekanator_question_suggestions' do
|
|
||||||
member do
|
|
||||||
post :ai_convert
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
resources :users, only: [:create, :update] do
|
resources :users, only: [:create, :update] do
|
||||||
collection do
|
collection do
|
||||||
post :verify
|
post :verify
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
class CreateGekanatorGames < ActiveRecord::Migration[8.0]
|
|
||||||
def change
|
|
||||||
create_table :gekanator_games do |t|
|
|
||||||
t.references :user, null: false, foreign_key: true
|
|
||||||
t.references :guessed_post, null: false, foreign_key: { to_table: :posts }
|
|
||||||
t.references :correct_post, null: false, foreign_key: { to_table: :posts }
|
|
||||||
t.boolean :won, null: false
|
|
||||||
t.integer :question_count, null: false
|
|
||||||
t.json :answers, null: false
|
|
||||||
|
|
||||||
t.timestamps
|
|
||||||
end
|
|
||||||
|
|
||||||
add_check_constraint :gekanator_games,
|
|
||||||
'question_count >= 0',
|
|
||||||
name: 'chk_gekanator_games_question_count_nonnegative'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
class CreateGekanatorQuestionSuggestions < ActiveRecord::Migration[8.0]
|
|
||||||
def change
|
|
||||||
create_table :gekanator_question_suggestions do |t|
|
|
||||||
t.references :gekanator_game,
|
|
||||||
null: false,
|
|
||||||
foreign_key: { on_delete: :cascade }
|
|
||||||
t.references :user, null: false, foreign_key: true
|
|
||||||
t.text :question_text, null: false
|
|
||||||
t.boolean :processed, null: false, default: false
|
|
||||||
|
|
||||||
t.timestamps
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
class AddAnswerToGekanatorQuestionSuggestions < ActiveRecord::Migration[8.0]
|
|
||||||
def change
|
|
||||||
add_column :gekanator_question_suggestions, :answer, :string, null: false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
class CreateGekanatorQuestions < ActiveRecord::Migration[8.0]
|
|
||||||
def change
|
|
||||||
create_table :gekanator_questions do |t|
|
|
||||||
t.string :text, null: false
|
|
||||||
t.string :kind, null: false
|
|
||||||
t.json :condition, null: false
|
|
||||||
t.string :source, null: false, default: 'ai_generated'
|
|
||||||
t.string :status, null: false, default: 'pending'
|
|
||||||
t.float :priority_weight, null: false, default: 1.0
|
|
||||||
t.references :gekanator_question_suggestion,
|
|
||||||
null: true,
|
|
||||||
foreign_key: true
|
|
||||||
t.references :created_by,
|
|
||||||
null: true,
|
|
||||||
foreign_key: { to_table: :users }
|
|
||||||
t.timestamps
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
class CreateGekanatorAiRuns < ActiveRecord::Migration[8.0]
|
|
||||||
def change
|
|
||||||
create_table :gekanator_ai_runs do |t|
|
|
||||||
t.string :model, null: false
|
|
||||||
t.integer :input_tokens, null: false, default: 0
|
|
||||||
t.integer :output_tokens, null: false, default: 0
|
|
||||||
t.decimal :estimated_cost_jpy, precision: 8, scale: 3, null: false, default: 0
|
|
||||||
t.string :status, null: false, default: 'pending'
|
|
||||||
t.references :gekanator_question_suggestion, null: false, foreign_key: true
|
|
||||||
t.timestamps
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
生成ファイル
+1
-82
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2026_06_09_001000) do
|
ActiveRecord::Schema[8.0].define(version: 2026_06_06_000000) do
|
||||||
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
@@ -48,60 +48,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_09_001000) do
|
|||||||
t.index ["tag_id"], name: "index_deerjikists_on_tag_id"
|
t.index ["tag_id"], name: "index_deerjikists_on_tag_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "gekanator_ai_runs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
|
||||||
t.string "model", null: false
|
|
||||||
t.integer "input_tokens", default: 0, null: false
|
|
||||||
t.integer "output_tokens", default: 0, null: false
|
|
||||||
t.decimal "estimated_cost_jpy", precision: 8, scale: 3, default: "0.0", null: false
|
|
||||||
t.string "status", default: "pending", null: false
|
|
||||||
t.bigint "gekanator_question_suggestion_id", null: false
|
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
t.index ["gekanator_question_suggestion_id"], name: "index_gekanator_ai_runs_on_gekanator_question_suggestion_id"
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "gekanator_games", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
|
||||||
t.bigint "user_id", null: false
|
|
||||||
t.bigint "guessed_post_id", null: false
|
|
||||||
t.bigint "correct_post_id", null: false
|
|
||||||
t.boolean "won", null: false
|
|
||||||
t.integer "question_count", null: false
|
|
||||||
t.json "answers", null: false
|
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
t.index ["correct_post_id"], name: "index_gekanator_games_on_correct_post_id"
|
|
||||||
t.index ["guessed_post_id"], name: "index_gekanator_games_on_guessed_post_id"
|
|
||||||
t.index ["user_id"], name: "index_gekanator_games_on_user_id"
|
|
||||||
t.check_constraint "`question_count` >= 0", name: "chk_gekanator_games_question_count_nonnegative"
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "gekanator_question_suggestions", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
|
||||||
t.bigint "gekanator_game_id", null: false
|
|
||||||
t.bigint "user_id", null: false
|
|
||||||
t.text "question_text", null: false
|
|
||||||
t.boolean "processed", default: false, null: false
|
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
t.string "answer", null: false
|
|
||||||
t.index ["gekanator_game_id"], name: "index_gekanator_question_suggestions_on_gekanator_game_id"
|
|
||||||
t.index ["user_id"], name: "index_gekanator_question_suggestions_on_user_id"
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "gekanator_questions", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
|
||||||
t.string "text", null: false
|
|
||||||
t.string "kind", null: false
|
|
||||||
t.json "condition", null: false
|
|
||||||
t.string "source", default: "ai_generated", null: false
|
|
||||||
t.string "status", default: "pending", null: false
|
|
||||||
t.float "priority_weight", default: 1.0, null: false
|
|
||||||
t.bigint "gekanator_question_suggestion_id"
|
|
||||||
t.bigint "created_by_id"
|
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
t.index ["created_by_id"], name: "index_gekanator_questions_on_created_by_id"
|
|
||||||
t.index ["gekanator_question_suggestion_id"], name: "index_gekanator_questions_on_gekanator_question_suggestion_id"
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "ip_addresses", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "ip_addresses", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.binary "ip_address", limit: 16, null: false
|
t.binary "ip_address", limit: 16, null: false
|
||||||
t.datetime "banned_at"
|
t.datetime "banned_at"
|
||||||
@@ -191,19 +137,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_09_001000) do
|
|||||||
t.index ["target_post_id"], name: "index_post_similarities_on_target_post_id"
|
t.index ["target_post_id"], name: "index_post_similarities_on_target_post_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "post_tag_sections", primary_key: ["post_id", "tag_id", "begin_ms"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
|
||||||
t.bigint "post_id", null: false
|
|
||||||
t.bigint "tag_id", null: false
|
|
||||||
t.integer "begin_ms", null: false
|
|
||||||
t.integer "end_ms", null: false
|
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
t.index ["post_id", "begin_ms"], name: "idx_post_tag_sections_post_id_begin_ms"
|
|
||||||
t.index ["tag_id"], name: "fk_rails_8be3847903"
|
|
||||||
t.check_constraint "`begin_ms` < `end_ms`", name: "chk_post_tag_sections_end_ms_after_begin_ms"
|
|
||||||
t.check_constraint "`begin_ms` >= 0", name: "chk_post_tag_sections_begin_ms_natural"
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "post_tags", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.bigint "post_id", null: false
|
t.bigint "post_id", null: false
|
||||||
t.bigint "tag_id", null: false
|
t.bigint "tag_id", null: false
|
||||||
@@ -254,11 +187,8 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_09_001000) do
|
|||||||
t.datetime "original_created_before"
|
t.datetime "original_created_before"
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "version_no", null: false
|
t.integer "version_no", null: false
|
||||||
t.integer "video_ms"
|
|
||||||
t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id"
|
t.index ["uploaded_user_id"], name: "index_posts_on_uploaded_user_id"
|
||||||
t.index ["url"], name: "index_posts_on_url", unique: true
|
t.index ["url"], name: "index_posts_on_url", unique: true
|
||||||
t.index ["video_ms", "id"], name: "idx_posts_video_ms_id"
|
|
||||||
t.check_constraint "(`video_ms` is null) or (`video_ms` > 0)", name: "chk_posts_video_ms_positive"
|
|
||||||
t.check_constraint "`version_no` > 0", name: "chk_posts_version_no_positive"
|
t.check_constraint "`version_no` > 0", name: "chk_posts_version_no_positive"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -409,7 +339,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_09_001000) do
|
|||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["expires_at"], name: "index_theatre_watching_users_on_expires_at"
|
t.index ["expires_at"], name: "index_theatre_watching_users_on_expires_at"
|
||||||
t.index ["theatre_id", "expires_at"], name: "idx_on_theatre_id_skip_expires_at_4c8de1dd42"
|
|
||||||
t.index ["theatre_id", "expires_at"], name: "index_theatre_watching_users_on_theatre_id_and_expires_at"
|
t.index ["theatre_id", "expires_at"], name: "index_theatre_watching_users_on_theatre_id_and_expires_at"
|
||||||
t.index ["theatre_id"], name: "index_theatre_watching_users_on_theatre_id"
|
t.index ["theatre_id"], name: "index_theatre_watching_users_on_theatre_id"
|
||||||
t.index ["user_id"], name: "index_theatre_watching_users_on_user_id"
|
t.index ["user_id"], name: "index_theatre_watching_users_on_user_id"
|
||||||
@@ -549,14 +478,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_09_001000) do
|
|||||||
|
|
||||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||||
add_foreign_key "gekanator_ai_runs", "gekanator_question_suggestions"
|
|
||||||
add_foreign_key "gekanator_games", "posts", column: "correct_post_id"
|
|
||||||
add_foreign_key "gekanator_games", "posts", column: "guessed_post_id"
|
|
||||||
add_foreign_key "gekanator_games", "users"
|
|
||||||
add_foreign_key "gekanator_question_suggestions", "gekanator_games", on_delete: :cascade
|
|
||||||
add_foreign_key "gekanator_question_suggestions", "users"
|
|
||||||
add_foreign_key "gekanator_questions", "gekanator_question_suggestions"
|
|
||||||
add_foreign_key "gekanator_questions", "users", column: "created_by_id"
|
|
||||||
add_foreign_key "material_versions", "materials"
|
add_foreign_key "material_versions", "materials"
|
||||||
add_foreign_key "material_versions", "materials", column: "parent_id"
|
add_foreign_key "material_versions", "materials", column: "parent_id"
|
||||||
add_foreign_key "material_versions", "tags"
|
add_foreign_key "material_versions", "tags"
|
||||||
@@ -574,8 +495,6 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_09_001000) do
|
|||||||
add_foreign_key "post_implications", "posts", column: "parent_post_id"
|
add_foreign_key "post_implications", "posts", column: "parent_post_id"
|
||||||
add_foreign_key "post_similarities", "posts"
|
add_foreign_key "post_similarities", "posts"
|
||||||
add_foreign_key "post_similarities", "posts", column: "target_post_id"
|
add_foreign_key "post_similarities", "posts", column: "target_post_id"
|
||||||
add_foreign_key "post_tag_sections", "posts"
|
|
||||||
add_foreign_key "post_tag_sections", "tags"
|
|
||||||
add_foreign_key "post_tags", "posts"
|
add_foreign_key "post_tags", "posts"
|
||||||
add_foreign_key "post_tags", "tags"
|
add_foreign_key "post_tags", "tags"
|
||||||
add_foreign_key "post_tags", "users", column: "created_user_id"
|
add_foreign_key "post_tags", "users", column: "created_user_id"
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe 'Gekanator games API', type: :request do
|
|
||||||
let!(:admin) { create_admin_user! }
|
|
||||||
let!(:user) { create_member_user! }
|
|
||||||
let!(:guessed_post) { Post.create!(title: 'guess', url: 'https://example.com/guess') }
|
|
||||||
let!(:correct_post) { Post.create!(title: 'correct', url: 'https://example.com/correct') }
|
|
||||||
|
|
||||||
describe 'POST /gekanator/games' do
|
|
||||||
it 'stores a won game' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: guessed_post.id,
|
|
||||||
answers: [{ question_id: 'tag:1', answer: 'yes' }] }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
|
||||||
game = GekanatorGame.find(json['id'])
|
|
||||||
expect(game.user).to eq(admin)
|
|
||||||
expect(game.guessed_post).to eq(guessed_post)
|
|
||||||
expect(game.correct_post).to eq(guessed_post)
|
|
||||||
expect(game.won).to eq(true)
|
|
||||||
expect(game.question_count).to eq(1)
|
|
||||||
expect(game.answers).to eq([{ 'question_id' => 'tag:1', 'answer' => 'yes' }])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'stores a lost game with the correct post' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: correct_post.id,
|
|
||||||
question_count: 4,
|
|
||||||
answers: [{ question_id: 'tag:1', answer: 'no' }] }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:created)
|
|
||||||
game = GekanatorGame.find(json['id'])
|
|
||||||
expect(game.correct_post).to eq(correct_post)
|
|
||||||
expect(game.won).to eq(false)
|
|
||||||
expect(game.question_count).to eq(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'rejects a game without the correct post' do
|
|
||||||
sign_in_as admin
|
|
||||||
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
question_count: 4,
|
|
||||||
answers: [{ question_id: 'tag:1', answer: 'no' }] }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:unprocessable_entity)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns not found without an admin user' do
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: guessed_post.id,
|
|
||||||
answers: [] }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:not_found)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns not found for a non-admin user' do
|
|
||||||
sign_in_as user
|
|
||||||
|
|
||||||
post '/gekanator/games', params: {
|
|
||||||
guessed_post_id: guessed_post.id,
|
|
||||||
correct_post_id: guessed_post.id,
|
|
||||||
answers: [{ question_id: 'tag:1', answer: 'yes' }] }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(:not_found)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -33,10 +33,6 @@ npm run lint
|
|||||||
|
|
||||||
If either command cannot be run or fails, report the exact command and failure.
|
If either command cannot be run or fails, report the exact command and failure.
|
||||||
|
|
||||||
Do not create, modify, or run tests unless the user explicitly asks for test
|
|
||||||
work. When the user asks for tests, keep working and rerun them until they
|
|
||||||
pass or the remaining failure is clearly blocked.
|
|
||||||
|
|
||||||
## TypeScript
|
## TypeScript
|
||||||
|
|
||||||
- TypeScript is strict. `tsconfig.app.json` enables `strict`,
|
- TypeScript is strict. `tsconfig.app.json` enables `strict`,
|
||||||
|
|||||||
+1
-16
@@ -18,7 +18,6 @@ import MaterialListPage from '@/pages/materials/MaterialListPage'
|
|||||||
import MaterialNewPage from '@/pages/materials/MaterialNewPage'
|
import MaterialNewPage from '@/pages/materials/MaterialNewPage'
|
||||||
// import MaterialSearchPage from '@/pages/materials/MaterialSearchPage'
|
// import MaterialSearchPage from '@/pages/materials/MaterialSearchPage'
|
||||||
import MorePage from '@/pages/MorePage'
|
import MorePage from '@/pages/MorePage'
|
||||||
import GekanatorPage from '@/pages/GekanatorPage'
|
|
||||||
import NicoTagListPage from '@/pages/tags/NicoTagListPage'
|
import NicoTagListPage from '@/pages/tags/NicoTagListPage'
|
||||||
import NotFound from '@/pages/NotFound'
|
import NotFound from '@/pages/NotFound'
|
||||||
import TOSPage from '@/pages/TOSPage.mdx'
|
import TOSPage from '@/pages/TOSPage.mdx'
|
||||||
@@ -40,7 +39,7 @@ import WikiHistoryPage from '@/pages/wiki/WikiHistoryPage'
|
|||||||
import WikiNewPage from '@/pages/wiki/WikiNewPage'
|
import WikiNewPage from '@/pages/wiki/WikiNewPage'
|
||||||
import WikiSearchPage from '@/pages/wiki/WikiSearchPage'
|
import WikiSearchPage from '@/pages/wiki/WikiSearchPage'
|
||||||
|
|
||||||
import type { Dispatch, FC, ReactNode, SetStateAction } from 'react'
|
import type { Dispatch, FC, SetStateAction } from 'react'
|
||||||
|
|
||||||
import type { User } from '@/types'
|
import type { User } from '@/types'
|
||||||
|
|
||||||
@@ -81,10 +80,6 @@ const RouteTransitionWrapper = ({ user, setUser }: {
|
|||||||
<Route path="/users/settings" element={<SettingPage user={user} setUser={setUser}/>}/>
|
<Route path="/users/settings" element={<SettingPage user={user} setUser={setUser}/>}/>
|
||||||
<Route path="/settings" element={<Navigate to="/users/settings" replace/>}/>
|
<Route path="/settings" element={<Navigate to="/users/settings" replace/>}/>
|
||||||
<Route path="/tos" element={<TOSPage/>}/>
|
<Route path="/tos" element={<TOSPage/>}/>
|
||||||
<Route path="/gekanator" element={
|
|
||||||
<AdminOnly user={user}>
|
|
||||||
<GekanatorPage/>
|
|
||||||
</AdminOnly>}/>
|
|
||||||
<Route path="/more" element={<MorePage/>}/>
|
<Route path="/more" element={<MorePage/>}/>
|
||||||
<Route path="*" element={<NotFound/>}/>
|
<Route path="*" element={<NotFound/>}/>
|
||||||
</Routes>
|
</Routes>
|
||||||
@@ -92,16 +87,6 @@ const RouteTransitionWrapper = ({ user, setUser }: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const AdminOnly = ({ user, children }: {
|
|
||||||
user: User | null
|
|
||||||
children: ReactNode }) => {
|
|
||||||
if (user?.role !== 'admin')
|
|
||||||
return <NotFound/>
|
|
||||||
|
|
||||||
return <>{children}</>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const PostDetailRoute = ({ user }: { user: User | null }) => {
|
const PostDetailRoute = ({ user }: { user: User | null }) => {
|
||||||
const location = useLocation ()
|
const location = useLocation ()
|
||||||
const key = location.pathname
|
const key = location.pathname
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
import { act, fireEvent, render } from '@testing-library/react'
|
|
||||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
||||||
import { createRef } from 'react'
|
|
||||||
|
|
||||||
import NicoViewer from '@/components/NicoViewer'
|
|
||||||
|
|
||||||
import type { NiconicoViewerHandle } from '@/types'
|
|
||||||
|
|
||||||
|
|
||||||
describe ('NicoViewer', () => {
|
|
||||||
afterEach (() => {
|
|
||||||
vi.useRealTimers ()
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('does not time out after metadata reports a playable duration', () => {
|
|
||||||
vi.useFakeTimers ()
|
|
||||||
|
|
||||||
const onError = vi.fn ()
|
|
||||||
const onMetadataChange = vi.fn ()
|
|
||||||
const { container } = render (
|
|
||||||
<NicoViewer
|
|
||||||
id="sm12345"
|
|
||||||
width={640}
|
|
||||||
height={360}
|
|
||||||
onMetadataChange={onMetadataChange}
|
|
||||||
onError={onError}/>,
|
|
||||||
)
|
|
||||||
const iframe = container.querySelector ('iframe')
|
|
||||||
expect (iframe).not.toBeNull ()
|
|
||||||
|
|
||||||
fireEvent.load (iframe!)
|
|
||||||
act (() => {
|
|
||||||
window.dispatchEvent (new MessageEvent ('message', {
|
|
||||||
origin: 'https://embed.nicovideo.jp',
|
|
||||||
source: iframe!.contentWindow,
|
|
||||||
data: {
|
|
||||||
eventName: 'playerMetadataChange',
|
|
||||||
data: {
|
|
||||||
currentTime: 7,
|
|
||||||
duration: 120,
|
|
||||||
isVideoMetaDataLoaded: true,
|
|
||||||
maximumBuffered: 30,
|
|
||||||
muted: false,
|
|
||||||
showComment: true,
|
|
||||||
volume: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
act (() => {
|
|
||||||
vi.advanceTimersByTime (8_000)
|
|
||||||
})
|
|
||||||
|
|
||||||
expect (onMetadataChange).toHaveBeenCalled ()
|
|
||||||
expect (onError).not.toHaveBeenCalled ()
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('seeks with milliseconds', () => {
|
|
||||||
const ref = createRef<NiconicoViewerHandle> ()
|
|
||||||
const { container } = render (
|
|
||||||
<NicoViewer
|
|
||||||
ref={ref}
|
|
||||||
id="sm12345"
|
|
||||||
width={640}
|
|
||||||
height={360}/>,
|
|
||||||
)
|
|
||||||
const iframe = container.querySelector ('iframe')!
|
|
||||||
const postMessage = vi.spyOn (iframe.contentWindow!, 'postMessage')
|
|
||||||
|
|
||||||
act (() => {
|
|
||||||
ref.current!.seek (7_000)
|
|
||||||
})
|
|
||||||
|
|
||||||
expect (postMessage).toHaveBeenCalledWith (
|
|
||||||
expect.objectContaining ({
|
|
||||||
eventName: 'seek',
|
|
||||||
data: { time: 7_000 },
|
|
||||||
}),
|
|
||||||
'https://embed.nicovideo.jp',
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -129,9 +129,7 @@ export default forwardRef ((props: Props, ref: ForwardedRef<NiconicoViewerHandle
|
|||||||
}, [playerId, postToPlayer])
|
}, [playerId, postToPlayer])
|
||||||
|
|
||||||
const seek = useCallback ((time: number) => {
|
const seek = useCallback ((time: number) => {
|
||||||
postToPlayer (
|
postToPlayer ({ eventName: 'seek', sourceConnectorType: 1, playerId, data: { time } })
|
||||||
{ eventName: 'seek', sourceConnectorType: 1, playerId,
|
|
||||||
data: { time } })
|
|
||||||
}, [playerId, postToPlayer])
|
}, [playerId, postToPlayer])
|
||||||
|
|
||||||
const mute = useCallback (() => {
|
const mute = useCallback (() => {
|
||||||
@@ -204,9 +202,6 @@ export default forwardRef ((props: Props, ref: ForwardedRef<NiconicoViewerHandle
|
|||||||
|
|
||||||
if (data.eventName === 'playerMetadataChange')
|
if (data.eventName === 'playerMetadataChange')
|
||||||
{
|
{
|
||||||
if (Number.isFinite (data.data.duration) && data.data.duration > 0)
|
|
||||||
clearLoadCompleteTimer ()
|
|
||||||
|
|
||||||
onMetadataChange?.(data.data)
|
onMetadataChange?.(data.data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,19 +8,12 @@ const dialogue = vi.hoisted (() => ({
|
|||||||
confirm: vi.fn (),
|
confirm: vi.fn (),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const nicoViewer = vi.hoisted (() => ({
|
|
||||||
props: vi.fn (),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock ('@/components/dialogues/DialogueProvider', () => ({
|
vi.mock ('@/components/dialogues/DialogueProvider', () => ({
|
||||||
useDialogue: () => dialogue,
|
useDialogue: () => dialogue,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock ('@/components/NicoViewer', () => ({
|
vi.mock ('@/components/NicoViewer', () => ({
|
||||||
default: (props: { id: string }) => {
|
default: ({ id }: { id: string }) => <div>Nico:{id}</div>,
|
||||||
nicoViewer.props (props)
|
|
||||||
return <div>Nico:{props.id}</div>
|
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock ('react-youtube', () => ({
|
vi.mock ('react-youtube', () => ({
|
||||||
@@ -38,64 +31,6 @@ describe ('PostEmbed', () => {
|
|||||||
expect (screen.getByText ('Nico:sm12345')).toBeInTheDocument ()
|
expect (screen.getByText ('Nico:sm12345')).toBeInTheDocument ()
|
||||||
})
|
})
|
||||||
|
|
||||||
it ('reports niconico metadata as milliseconds', () => {
|
|
||||||
const onVideoReady = vi.fn ()
|
|
||||||
const onPlaybackChange = vi.fn ()
|
|
||||||
render (
|
|
||||||
<PostEmbed
|
|
||||||
post={buildPost ({ url: 'https://www.nicovideo.jp/watch/sm12345' })}
|
|
||||||
onVideoReady={onVideoReady}
|
|
||||||
onPlaybackChange={onPlaybackChange}/>,
|
|
||||||
)
|
|
||||||
|
|
||||||
nicoViewer.props.mock.calls[0][0].onMetadataChange ({
|
|
||||||
currentTime: 7_000,
|
|
||||||
duration: 120_000,
|
|
||||||
isVideoMetaDataLoaded: true,
|
|
||||||
maximumBuffered: 30,
|
|
||||||
muted: false,
|
|
||||||
showComment: true,
|
|
||||||
volume: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect (onVideoReady).toHaveBeenCalledWith (120_000)
|
|
||||||
expect (onPlaybackChange).toHaveBeenCalledWith (7_000)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('reports niconico video readiness only once', () => {
|
|
||||||
const onVideoReady = vi.fn ()
|
|
||||||
render (
|
|
||||||
<PostEmbed
|
|
||||||
post={buildPost ({ url: 'https://www.nicovideo.jp/watch/sm12345' })}
|
|
||||||
onVideoReady={onVideoReady}/>,
|
|
||||||
)
|
|
||||||
|
|
||||||
nicoViewer.props.mock.calls[0][0].onLoadComplete ({
|
|
||||||
title: '動画',
|
|
||||||
videoId: 'sm12345',
|
|
||||||
lengthInSeconds: 120,
|
|
||||||
thumbnailUrl: 'https://example.com/thumb.jpg',
|
|
||||||
description: '',
|
|
||||||
viewCount: 1,
|
|
||||||
commentCount: 2,
|
|
||||||
mylistCount: 3,
|
|
||||||
postedAt: '2026-01-02T03:04:05.000Z',
|
|
||||||
watchId: 12345,
|
|
||||||
})
|
|
||||||
nicoViewer.props.mock.calls[0][0].onMetadataChange ({
|
|
||||||
currentTime: 7_000,
|
|
||||||
duration: 120_000,
|
|
||||||
isVideoMetaDataLoaded: true,
|
|
||||||
maximumBuffered: 30,
|
|
||||||
muted: false,
|
|
||||||
showComment: true,
|
|
||||||
volume: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect (onVideoReady).toHaveBeenCalledTimes (1)
|
|
||||||
expect (onVideoReady).toHaveBeenCalledWith (120_000)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('embeds x/twitter status URLs', () => {
|
it ('embeds x/twitter status URLs', () => {
|
||||||
render (<PostEmbed post={buildPost ({ url: 'https://x.com/someone/status/12345' })}/>)
|
render (<PostEmbed post={buildPost ({ url: 'https://x.com/someone/status/12345' })}/>)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import YoutubeEmbed from 'react-youtube'
|
import YoutubeEmbed from 'react-youtube'
|
||||||
|
|
||||||
import NicoViewer from '@/components/NicoViewer'
|
import NicoViewer from '@/components/NicoViewer'
|
||||||
@@ -36,17 +36,6 @@ const PostEmbed: FC<Props> = ({
|
|||||||
const dialogue = useDialogue ()
|
const dialogue = useDialogue ()
|
||||||
const [framed, setFramed] = useState (false)
|
const [framed, setFramed] = useState (false)
|
||||||
const [youtubePlayer, setYoutubePlayer] = useState<YouTubePlayer | null> (null)
|
const [youtubePlayer, setYoutubePlayer] = useState<YouTubePlayer | null> (null)
|
||||||
const niconicoVideoReadyRef = useRef (false)
|
|
||||||
|
|
||||||
const notifyNiconicoVideoReady = useCallback ((durationMs: number) => {
|
|
||||||
if (niconicoVideoReadyRef.current
|
|
||||||
|| !(Number.isFinite (durationMs))
|
|
||||||
|| durationMs <= 0)
|
|
||||||
return
|
|
||||||
|
|
||||||
niconicoVideoReadyRef.current = true
|
|
||||||
onVideoReady?.(durationMs)
|
|
||||||
}, [onVideoReady])
|
|
||||||
|
|
||||||
const reportYoutubePlayback = useCallback (async (player: YouTubePlayer) => {
|
const reportYoutubePlayback = useCallback (async (player: YouTubePlayer) => {
|
||||||
const currentTime = await player.getCurrentTime ()
|
const currentTime = await player.getCurrentTime ()
|
||||||
@@ -91,20 +80,15 @@ const PostEmbed: FC<Props> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleNiconicoLoadComplete = (info: NiconicoVideoInfo) => {
|
const handleNiconicoLoadComplete = (info: NiconicoVideoInfo) => {
|
||||||
notifyNiconicoVideoReady (info.lengthInSeconds * 1_000)
|
onVideoReady?.(info.lengthInSeconds * 1_000)
|
||||||
onLoadComplete?.(info)
|
onLoadComplete?.(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleNiconicoMetadataChange = (meta: NiconicoMetadata) => {
|
const handleNiconicoMetadataChange = (meta: NiconicoMetadata) => {
|
||||||
notifyNiconicoVideoReady (meta.duration)
|
|
||||||
onPlaybackChange?.(meta.currentTime)
|
onPlaybackChange?.(meta.currentTime)
|
||||||
onMetadataChange?.(meta)
|
onMetadataChange?.(meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect (() => {
|
|
||||||
niconicoVideoReadyRef.current = false
|
|
||||||
}, [post.url])
|
|
||||||
|
|
||||||
useEffect (() => {
|
useEffect (() => {
|
||||||
if (!(youtubePlayer) || !(onPlaybackChange))
|
if (!(youtubePlayer) || !(onPlaybackChange))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,395 +0,0 @@
|
|||||||
import { apiGet, apiPost } from '@/lib/api'
|
|
||||||
|
|
||||||
import type { Post } from '@/types'
|
|
||||||
|
|
||||||
export type GekanatorAnswerValue =
|
|
||||||
| 'yes'
|
|
||||||
| 'no'
|
|
||||||
| 'partial'
|
|
||||||
| 'probably_no'
|
|
||||||
| 'unknown'
|
|
||||||
|
|
||||||
export type GekanatorAnswerLog = {
|
|
||||||
questionId: string
|
|
||||||
questionText: string
|
|
||||||
questionCondition?: GekanatorQuestionCondition
|
|
||||||
answer: GekanatorAnswerValue
|
|
||||||
originalAnswer: GekanatorAnswerValue }
|
|
||||||
|
|
||||||
export type GekanatorQuestionKind =
|
|
||||||
| 'tag'
|
|
||||||
| 'source'
|
|
||||||
| 'title'
|
|
||||||
| 'original_date'
|
|
||||||
|
|
||||||
export type GekanatorQuestionSource =
|
|
||||||
| 'default'
|
|
||||||
| 'user_suggested'
|
|
||||||
| 'ai_generated'
|
|
||||||
| 'admin_curated'
|
|
||||||
|
|
||||||
export type GekanatorQuestionCondition =
|
|
||||||
| { type: 'tag'; key: string }
|
|
||||||
| { type: 'source'; host: string }
|
|
||||||
| { type: 'original-year'; year: number }
|
|
||||||
| { type: 'original-month'; month: number }
|
|
||||||
| { type: 'original-month-day'; monthDay: string }
|
|
||||||
| { type: 'title-length-greater-than'; length: number }
|
|
||||||
| { type: 'title-has-ascii' }
|
|
||||||
|
|
||||||
export type StoredGekanatorQuestion = {
|
|
||||||
id: string
|
|
||||||
text: string
|
|
||||||
kind: GekanatorQuestionKind
|
|
||||||
condition: GekanatorQuestionCondition
|
|
||||||
source?: GekanatorQuestionSource
|
|
||||||
priorityWeight?: number }
|
|
||||||
|
|
||||||
export type GekanatorQuestion = {
|
|
||||||
id: string
|
|
||||||
text: string
|
|
||||||
kind: GekanatorQuestionKind
|
|
||||||
condition: GekanatorQuestionCondition
|
|
||||||
source: GekanatorQuestionSource
|
|
||||||
priorityWeight: number
|
|
||||||
test: (post: Post) => boolean }
|
|
||||||
|
|
||||||
const countBy = <T extends string | number> (values: T[]): Map<T, number> => {
|
|
||||||
const counts = new Map<T, number> ()
|
|
||||||
values.forEach (value => counts.set (value, (counts.get (value) ?? 0) + 1))
|
|
||||||
return counts
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const median = (values: number[]): number => {
|
|
||||||
const sorted = [...values].sort ((a, b) => a - b)
|
|
||||||
return sorted[Math.floor (sorted.length / 2)] ?? 0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const hostOf = (post: Post): string | null => {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new URL (post.url).hostname.replace (/^www\./, '')
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const originalYearOf = (post: Post): number | null => {
|
|
||||||
const value = post.originalCreatedFrom || post.originalCreatedBefore
|
|
||||||
if (!(value))
|
|
||||||
return null
|
|
||||||
|
|
||||||
const date = new Date (value)
|
|
||||||
if (Number.isNaN (date.getTime ()))
|
|
||||||
return null
|
|
||||||
|
|
||||||
return date.getFullYear ()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const originalDateOf = (post: Post): Date | null => {
|
|
||||||
const value = post.originalCreatedFrom || post.originalCreatedBefore
|
|
||||||
if (!(value))
|
|
||||||
return null
|
|
||||||
|
|
||||||
const date = new Date (value)
|
|
||||||
if (Number.isNaN (date.getTime ()))
|
|
||||||
return null
|
|
||||||
|
|
||||||
return date
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const originalMonthOf = (post: Post): number | null => {
|
|
||||||
const date = originalDateOf (post)
|
|
||||||
if (!(date))
|
|
||||||
return null
|
|
||||||
|
|
||||||
return date.getMonth () + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const originalMonthDayOf = (post: Post): string | null => {
|
|
||||||
const date = originalDateOf (post)
|
|
||||||
if (!(date))
|
|
||||||
return null
|
|
||||||
|
|
||||||
return `${ date.getMonth () + 1 }-${ date.getDate () }`
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const tagQuestionKey = ({ category, name }: { category: string; name: string }): string =>
|
|
||||||
`${ category }:${ name }`
|
|
||||||
|
|
||||||
|
|
||||||
const tagFromQuestionKey = (key: string): { category: string; name: string } => {
|
|
||||||
const [category, ...rest] = key.split (':')
|
|
||||||
return { category: category ?? '', name: rest.join (':') }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const nicoTagLabel = (name: string): string => name.replace (/^nico:/, '')
|
|
||||||
|
|
||||||
|
|
||||||
const tagQuestionText = (category: string, label: string): string => {
|
|
||||||
switch (category)
|
|
||||||
{
|
|
||||||
case 'deerjikist':
|
|
||||||
return `作者・ニジラーとして「${ label }」に関係してゐる?`
|
|
||||||
case 'meme':
|
|
||||||
return `元ネタ・ミームとして「${ label }」に関係しさう?`
|
|
||||||
case 'character':
|
|
||||||
return `「${ label }」といふキャラクターが関係してゐる?`
|
|
||||||
case 'material':
|
|
||||||
return `素材として「${ label }」に関係してゐる?`
|
|
||||||
case 'nico':
|
|
||||||
return `ニコニコに「${ label }」といふタグが付いてゐる?`
|
|
||||||
case 'general':
|
|
||||||
case 'meta':
|
|
||||||
default:
|
|
||||||
return `内容として「${ label }」に関係しさう?`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const questionableTag = (post: Post, key: string): boolean => {
|
|
||||||
const { category, name } = tagFromQuestionKey (key)
|
|
||||||
|
|
||||||
return (
|
|
||||||
post.tags.some (tag =>
|
|
||||||
tag.name === name
|
|
||||||
&& tag.category === category
|
|
||||||
&& !(tag.category === 'meta')
|
|
||||||
&& !(tag.name.includes ('タグ希望'))
|
|
||||||
&& !(tag.name.includes ('bot操作'))))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const questionMatches = (
|
|
||||||
post: Post,
|
|
||||||
condition: GekanatorQuestionCondition,
|
|
||||||
): boolean => {
|
|
||||||
switch (condition.type)
|
|
||||||
{
|
|
||||||
case 'tag':
|
|
||||||
return questionableTag (post, condition.key)
|
|
||||||
case 'source':
|
|
||||||
return hostOf (post) === condition.host
|
|
||||||
case 'original-year':
|
|
||||||
return originalYearOf (post) === condition.year
|
|
||||||
case 'original-month':
|
|
||||||
return originalMonthOf (post) === condition.month
|
|
||||||
case 'original-month-day':
|
|
||||||
return originalMonthDayOf (post) === condition.monthDay
|
|
||||||
case 'title-length-greater-than':
|
|
||||||
return (post.title?.length ?? 0) > condition.length
|
|
||||||
case 'title-has-ascii':
|
|
||||||
return /[A-Za-z0-9]/.test (post.title ?? '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const restoreGekanatorQuestion = (
|
|
||||||
question: StoredGekanatorQuestion,
|
|
||||||
): GekanatorQuestion => ({
|
|
||||||
...question,
|
|
||||||
source: question.source ?? 'default',
|
|
||||||
priorityWeight: question.priorityWeight ?? 1,
|
|
||||||
test: (post: Post) => questionMatches (post, question.condition) })
|
|
||||||
|
|
||||||
|
|
||||||
export const storeGekanatorQuestion = (
|
|
||||||
question: GekanatorQuestion,
|
|
||||||
): StoredGekanatorQuestion => ({
|
|
||||||
id: question.id,
|
|
||||||
text: question.text,
|
|
||||||
kind: question.kind,
|
|
||||||
condition: question.condition,
|
|
||||||
source: question.source,
|
|
||||||
priorityWeight: question.priorityWeight })
|
|
||||||
|
|
||||||
|
|
||||||
export const fetchGekanatorPosts = async (): Promise<Post[]> => {
|
|
||||||
const data = await apiGet<{ posts: Post[] }> ('/gekanator/posts')
|
|
||||||
return data.posts
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const fetchGekanatorQuestions = async (): Promise<StoredGekanatorQuestion[]> => {
|
|
||||||
const data = await apiGet<{ questions: StoredGekanatorQuestion[] }> ('/gekanator/questions')
|
|
||||||
return data.questions
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const buildGekanatorQuestions = (posts: Post[]): GekanatorQuestion[] => {
|
|
||||||
const tagCounts = countBy (posts.flatMap (post =>
|
|
||||||
post.tags
|
|
||||||
.filter (tag =>
|
|
||||||
!(tag.category === 'meta')
|
|
||||||
&& !(tag.name.includes ('タグ希望'))
|
|
||||||
&& !(tag.name.includes ('bot操作')))
|
|
||||||
.map (tag => tagQuestionKey (tag))))
|
|
||||||
const hosts = countBy (posts.map (hostOf).filter ((host): host is string => Boolean (host)))
|
|
||||||
const originalYears = countBy (
|
|
||||||
posts
|
|
||||||
.map (originalYearOf)
|
|
||||||
.filter ((year): year is number => year !== null))
|
|
||||||
const originalMonths = countBy (
|
|
||||||
posts
|
|
||||||
.map (originalMonthOf)
|
|
||||||
.filter ((month): month is number => month !== null))
|
|
||||||
const originalMonthDays = countBy (
|
|
||||||
posts
|
|
||||||
.map (originalMonthDayOf)
|
|
||||||
.filter ((monthDay): monthDay is string => monthDay !== null))
|
|
||||||
const titleLengthMedian = median (posts.map (post => post.title?.length ?? 0))
|
|
||||||
|
|
||||||
const usefulEntries = <T extends string | number> (counts: Map<T, number>) =>
|
|
||||||
[...counts.entries ()]
|
|
||||||
.filter (([, count]) => count > 0 && count < posts.length)
|
|
||||||
.sort ((a, b) => Math.abs (posts.length / 2 - a[1])
|
|
||||||
- Math.abs (posts.length / 2 - b[1]))
|
|
||||||
.slice (0, 80)
|
|
||||||
|
|
||||||
const tagQuestions = usefulEntries (tagCounts)
|
|
||||||
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
|
||||||
.slice (0, 80)
|
|
||||||
.map (([key]) => {
|
|
||||||
const { category, name } = tagFromQuestionKey (String (key))
|
|
||||||
const label = category === 'nico' ? nicoTagLabel (name) : name
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: `tag:${ key }`,
|
|
||||||
text: tagQuestionText (category, label),
|
|
||||||
kind: 'tag' as const,
|
|
||||||
condition: { type: 'tag' as const, key: String (key) },
|
|
||||||
source: 'default' as const,
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: (post: Post) => questionableTag (post, String (key)) }
|
|
||||||
})
|
|
||||||
|
|
||||||
const sourceQuestions = usefulEntries (hosts)
|
|
||||||
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
|
||||||
.slice (0, 20)
|
|
||||||
.map (([host]) => ({
|
|
||||||
id: `source:${ host }`,
|
|
||||||
text: `${ host } の投稿を思ひ浮かべてゐる?`,
|
|
||||||
kind: 'source' as const,
|
|
||||||
condition: { type: 'source' as const, host },
|
|
||||||
source: 'default' as const,
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: (post: Post) => hostOf (post) === host }))
|
|
||||||
|
|
||||||
const originalYearQuestions = usefulEntries (originalYears)
|
|
||||||
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
|
||||||
.slice (0, 20)
|
|
||||||
.map (([year]) => ({
|
|
||||||
id: `original-year:${ year }`,
|
|
||||||
text: `オリジナルの投稿年は ${ year } 年?`,
|
|
||||||
kind: 'original_date' as const,
|
|
||||||
condition: { type: 'original-year' as const, year },
|
|
||||||
source: 'default' as const,
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: (post: Post) => originalYearOf (post) === year }))
|
|
||||||
|
|
||||||
const originalMonthQuestions = usefulEntries (originalMonths)
|
|
||||||
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
|
||||||
.slice (0, 20)
|
|
||||||
.map (([month]) => ({
|
|
||||||
id: `original-month:${ month }`,
|
|
||||||
text: `オリジナルの投稿月は ${ month } 月?`,
|
|
||||||
kind: 'original_date' as const,
|
|
||||||
condition: { type: 'original-month' as const, month },
|
|
||||||
source: 'default' as const,
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: (post: Post) => originalMonthOf (post) === month }))
|
|
||||||
|
|
||||||
const originalMonthDayQuestions = usefulEntries (originalMonthDays)
|
|
||||||
.filter (([, count]) => count >= 2 && count <= Math.max (2, posts.length * .7))
|
|
||||||
.slice (0, 20)
|
|
||||||
.map (([monthDay]) => {
|
|
||||||
const [month, day] = String (monthDay).split ('-')
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: `original-month-day:${ monthDay }`,
|
|
||||||
text: `オリジナルの投稿日は ${ month } 月 ${ day } 日?`,
|
|
||||||
kind: 'original_date' as const,
|
|
||||||
condition: { type: 'original-month-day' as const, monthDay: String (monthDay) },
|
|
||||||
source: 'default' as const,
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: (post: Post) => originalMonthDayOf (post) === monthDay }
|
|
||||||
})
|
|
||||||
|
|
||||||
const titleQuestions = [
|
|
||||||
{
|
|
||||||
id: 'title:long',
|
|
||||||
text: '題名が長めの投稿?',
|
|
||||||
kind: 'title' as const,
|
|
||||||
condition: {
|
|
||||||
type: 'title-length-greater-than' as const,
|
|
||||||
length: titleLengthMedian },
|
|
||||||
source: 'default' as const,
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: (post: Post) => (post.title?.length ?? 0) > titleLengthMedian },
|
|
||||||
{
|
|
||||||
id: 'title:ascii',
|
|
||||||
text: '題名に英数字が混じってゐる?',
|
|
||||||
kind: 'title' as const,
|
|
||||||
condition: { type: 'title-has-ascii' as const },
|
|
||||||
source: 'default' as const,
|
|
||||||
priorityWeight: 1,
|
|
||||||
test: (post: Post) => /[A-Za-z0-9]/.test (post.title ?? '') }]
|
|
||||||
.filter (question => {
|
|
||||||
const yes = posts.filter (post => question.test (post)).length
|
|
||||||
const no = posts.length - yes
|
|
||||||
return yes >= 2 && no >= 2 && yes <= posts.length * .7 && no <= posts.length * .7
|
|
||||||
})
|
|
||||||
|
|
||||||
return [
|
|
||||||
...sourceQuestions,
|
|
||||||
...originalYearQuestions,
|
|
||||||
...originalMonthQuestions,
|
|
||||||
...originalMonthDayQuestions,
|
|
||||||
...titleQuestions,
|
|
||||||
...tagQuestions]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const saveGekanatorGame = async ({
|
|
||||||
guessedPostId,
|
|
||||||
correctPostId,
|
|
||||||
answers,
|
|
||||||
}: {
|
|
||||||
guessedPostId: number
|
|
||||||
correctPostId: number
|
|
||||||
answers: GekanatorAnswerLog[]
|
|
||||||
}): Promise<{ id: number }> =>
|
|
||||||
await apiPost ('/gekanator/games', {
|
|
||||||
guessed_post_id: guessedPostId,
|
|
||||||
correct_post_id: correctPostId,
|
|
||||||
answers: answers.map (answer => ({
|
|
||||||
question_id: answer.questionId,
|
|
||||||
question_text: answer.questionText,
|
|
||||||
question_condition: answer.questionCondition ?? null,
|
|
||||||
answer: answer.answer,
|
|
||||||
original_answer: answer.originalAnswer })) })
|
|
||||||
|
|
||||||
|
|
||||||
export const saveGekanatorQuestionSuggestion = async ({
|
|
||||||
gekanatorGameId,
|
|
||||||
questionText,
|
|
||||||
answer,
|
|
||||||
}: {
|
|
||||||
gekanatorGameId: number
|
|
||||||
questionText: string
|
|
||||||
answer: GekanatorAnswerValue
|
|
||||||
}): Promise<{ id: number; count: number }> =>
|
|
||||||
await apiPost ('/gekanator/question_suggestions', {
|
|
||||||
gekanator_game_id: gekanatorGameId,
|
|
||||||
question_text: questionText,
|
|
||||||
answer })
|
|
||||||
@@ -8,11 +8,6 @@ export const postsKeys = {
|
|||||||
changes: (p: { post?: string; tag?: string; page: number; limit: number }) =>
|
changes: (p: { post?: string; tag?: string; page: number; limit: number }) =>
|
||||||
['posts', 'changes', p] as const }
|
['posts', 'changes', p] as const }
|
||||||
|
|
||||||
export const gekanatorKeys = {
|
|
||||||
root: ['gekanator'] as const,
|
|
||||||
posts: () => ['gekanator', 'posts'] as const,
|
|
||||||
questions: () => ['gekanator', 'questions'] as const }
|
|
||||||
|
|
||||||
export const tagsKeys = {
|
export const tagsKeys = {
|
||||||
root: ['tags'] as const,
|
root: ['tags'] as const,
|
||||||
index: (p: FetchTagsParams) => ['tags', 'index', p] as const,
|
index: (p: FetchTagsParams) => ['tags', 'index', p] as const,
|
||||||
|
|||||||
ファイル差分が大きすぎるため省略します
差分を読込み
@@ -1,4 +1,4 @@
|
|||||||
import { act, fireEvent, screen, waitFor } from '@testing-library/react'
|
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||||
import { Route, Routes } from 'react-router-dom'
|
import { Route, Routes } from 'react-router-dom'
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
@@ -31,31 +31,15 @@ const dialogue = vi.hoisted (() => ({
|
|||||||
confirm: vi.fn (),
|
confirm: vi.fn (),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const postEmbed = vi.hoisted (() => ({
|
|
||||||
props: vi.fn (),
|
|
||||||
play: vi.fn (),
|
|
||||||
seek: vi.fn (),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock ('@/lib/api', () => api)
|
vi.mock ('@/lib/api', () => api)
|
||||||
vi.mock ('@/lib/posts', () => postsApi)
|
vi.mock ('@/lib/posts', () => postsApi)
|
||||||
vi.mock ('@/components/dialogues/DialogueProvider', () => ({
|
vi.mock ('@/components/dialogues/DialogueProvider', () => ({
|
||||||
useDialogue: () => dialogue,
|
useDialogue: () => dialogue,
|
||||||
}))
|
}))
|
||||||
vi.mock ('@/components/PostEmbed', () => ({
|
vi.mock ('@/components/PostEmbed', () => ({
|
||||||
default: (props: {
|
default: ({ post }: {
|
||||||
ref?: { current: unknown }
|
|
||||||
post: { title: string | null; url: string }
|
post: { title: string | null; url: string }
|
||||||
}) => {
|
}) => <div>Embed:{post.title || post.url}</div>,
|
||||||
postEmbed.props (props)
|
|
||||||
if (props.ref)
|
|
||||||
props.ref.current = {
|
|
||||||
play: postEmbed.play,
|
|
||||||
seek: postEmbed.seek,
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div>Embed:{props.post.title || props.post.url}</div>
|
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
vi.mock ('@/components/PostEditForm', () => ({
|
vi.mock ('@/components/PostEditForm', () => ({
|
||||||
default: () => <div>Post edit form</div>,
|
default: () => <div>Post edit form</div>,
|
||||||
@@ -169,7 +153,6 @@ const mockDefaultApi = () => {
|
|||||||
|
|
||||||
describe ('TheatreDetailPage', () => {
|
describe ('TheatreDetailPage', () => {
|
||||||
beforeEach (() => {
|
beforeEach (() => {
|
||||||
vi.useRealTimers ()
|
|
||||||
vi.clearAllMocks ()
|
vi.clearAllMocks ()
|
||||||
mockDefaultApi ()
|
mockDefaultApi ()
|
||||||
})
|
})
|
||||||
@@ -205,83 +188,6 @@ describe ('TheatreDetailPage', () => {
|
|||||||
.toBeInTheDocument ()
|
.toBeInTheDocument ()
|
||||||
})
|
})
|
||||||
|
|
||||||
it ('does not seek to zero while applying video length from the player', async () => {
|
|
||||||
api.apiPut.mockImplementation ((path: string) => {
|
|
||||||
switch (path)
|
|
||||||
{
|
|
||||||
case '/theatres/7/watching':
|
|
||||||
return Promise.resolve (buildTheatreInfo ({
|
|
||||||
hostFlg: true,
|
|
||||||
postId: currentPost.id,
|
|
||||||
postStartedAt: '2026-01-02T03:04:05.000Z',
|
|
||||||
postElapsedMs: 7_000,
|
|
||||||
watchingUsers: [{ id: 1, name: 'tester' }],
|
|
||||||
skipVote: {
|
|
||||||
votesCount: 0,
|
|
||||||
requiredCount: 2,
|
|
||||||
watchingUsersCount: 1,
|
|
||||||
voted: false,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
default:
|
|
||||||
return Promise.reject (new Error (`Unexpected PUT ${ path }`))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
renderPage ()
|
|
||||||
await screen.findByText ('Embed:上映中の投稿')
|
|
||||||
|
|
||||||
const props = postEmbed.props.mock.calls.at (-1)![0]
|
|
||||||
|
|
||||||
act (() => {
|
|
||||||
props.onVideoReady (120_000)
|
|
||||||
props.onPlaybackChange (0)
|
|
||||||
})
|
|
||||||
|
|
||||||
const seekMs = postEmbed.seek.mock.calls[0][0]
|
|
||||||
expect (seekMs).toBeGreaterThanOrEqual (7_000)
|
|
||||||
expect (seekMs).toBeLessThan (10_000)
|
|
||||||
expect (postEmbed.seek).not.toHaveBeenCalledWith (0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('does not advance host post while video length is unknown', async () => {
|
|
||||||
api.apiPut.mockImplementation ((path: string) => {
|
|
||||||
switch (path)
|
|
||||||
{
|
|
||||||
case '/theatres/7/watching':
|
|
||||||
return Promise.resolve (buildTheatreInfo ({
|
|
||||||
hostFlg: true,
|
|
||||||
postId: currentPost.id,
|
|
||||||
postStartedAt: '2026-01-02T03:04:05.000Z',
|
|
||||||
postElapsedMs: 4_000,
|
|
||||||
watchingUsers: [{ id: 1, name: 'tester' }],
|
|
||||||
skipVote: {
|
|
||||||
votesCount: 0,
|
|
||||||
requiredCount: 2,
|
|
||||||
watchingUsersCount: 1,
|
|
||||||
voted: false,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
default:
|
|
||||||
return Promise.reject (new Error (`Unexpected PUT ${ path }`))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
renderPage ()
|
|
||||||
|
|
||||||
await screen.findByText ('Embed:上映中の投稿')
|
|
||||||
await waitFor (() => {
|
|
||||||
expect (api.apiPut).toHaveBeenCalledWith ('/theatres/7/watching')
|
|
||||||
})
|
|
||||||
|
|
||||||
await waitFor (() => {
|
|
||||||
expect (api.apiPut).toHaveBeenCalledTimes (2)
|
|
||||||
}, { timeout: 2_500 })
|
|
||||||
expect (api.apiPatch).not.toHaveBeenCalledWith ('/theatres/7/next_post')
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('deletes an owned comment after confirmation', async () => {
|
it ('deletes an owned comment after confirmation', async () => {
|
||||||
renderPage ()
|
renderPage ()
|
||||||
|
|
||||||
|
|||||||
@@ -443,13 +443,9 @@ const TheatreDetailPage: FC<Props> = ({ user }: Props) => {
|
|||||||
if (!(theatreInfo.postStartedAt))
|
if (!(theatreInfo.postStartedAt))
|
||||||
return
|
return
|
||||||
|
|
||||||
const currentVideoLength = videoLengthRef.current
|
|
||||||
if (currentVideoLength <= 0)
|
|
||||||
return
|
|
||||||
|
|
||||||
const targetTime = Math.min (
|
const targetTime = Math.min (
|
||||||
currentPostElapsedMs (theatreInfo),
|
currentPostElapsedMs (theatreInfo),
|
||||||
currentVideoLength)
|
videoLength)
|
||||||
|
|
||||||
const drift = Math.abs (currentTimeMs - targetTime)
|
const drift = Math.abs (currentTimeMs - targetTime)
|
||||||
|
|
||||||
@@ -481,7 +477,6 @@ const TheatreDetailPage: FC<Props> = ({ user }: Props) => {
|
|||||||
: 0
|
: 0
|
||||||
|
|
||||||
setVideoLength (playableDurationMs)
|
setVideoLength (playableDurationMs)
|
||||||
videoLengthRef.current = playableDurationMs
|
|
||||||
|
|
||||||
if (playableDurationMs <= 0)
|
if (playableDurationMs <= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする