Skip to content

Commit

Permalink
Merge branch 'master' into private-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Aug 30, 2023
2 parents 4c460e2 + da24f74 commit 30ce16c
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/Libraries/BBCodeForDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function ($m) {
public function parseYoutube($text)
{
return preg_replace_callback(
'#\[youtube\](.+?)\[/youtube\]#',
'#\[youtube\](?:https?://(?:youtu\.be/|(?:m\.|www\.|)youtube\.com/(?:embed/|shorts/|watch\?v=))|)(.+?)\[/youtube\]#',
function ($m) {
$videoId = preg_replace('/\?.*/', '', $this->extraEscapes($m[1]));

Expand Down
15 changes: 10 additions & 5 deletions app/Transformers/ScoreTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,26 @@ public function transformSolo(ScoreModel|SoloScore $score)
if ($best !== null) {
$bestId = $best->getKey();
$pp = $best->pp;
$replay = $best->replay;
$hasReplay = $best->replay;
}
} elseif ($score instanceof SoloScore) {
$pp = $score->pp;
$replay = $score->has_replay;
$hasReplay = $score->has_replay;
}

return array_merge($score->data->jsonSerialize(), [
$hasReplay ??= false;

return [
...$score->data->jsonSerialize(),
'best_id' => $bestId ?? null,
'has_replay' => $hasReplay,
'id' => $score->getKey(),
'legacy_perfect' => $legacyPerfect ?? null,
'pp' => $pp ?? null,
'replay' => $replay ?? false,
// TODO: remove this redundant field sometime after 2024-02
'replay' => $hasReplay,
'type' => $score->getMorphClass(),
]);
];
}

public function transformLegacy(LegacyMatch\Score|ScoreModel|SoloScore $score)
Expand Down
4 changes: 2 additions & 2 deletions resources/js/interfaces/solo-score-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type SoloScoreJsonDefaultAttributes = {
best_id: number | null;
build_id: number | null;
ended_at: string;
has_replay: boolean;
id: number;
legacy_score_id: number | null;
legacy_total_score: number | null;
Expand All @@ -39,7 +40,6 @@ type SoloScoreJsonDefaultAttributes = {
passed: boolean;
pp: number | null;
rank: Rank;
replay: boolean | null;
ruleset_id: number;
started_at: string | null;
statistics: Partial<Record<SoloScoreStatisticsAttribute, number>>;
Expand All @@ -61,7 +61,7 @@ export default SoloScoreJson;
export type SoloScoreJsonForBeatmap = SoloScoreJson & Required<Pick<SoloScoreJson, 'user'>>;

export type SoloScoreJsonForShow = SoloScoreJson
& Required<Pick<SoloScoreJson, 'beatmapset' | 'best_id' | 'rank_global' | 'replay' | 'user'>>
& Required<Pick<SoloScoreJson, 'beatmapset' | 'best_id' | 'rank_global' | 'user'>>
& {
beatmap: BeatmapExtendedJson & Required<Pick<BeatmapJson, 'user'>>;
};
Expand Down
2 changes: 1 addition & 1 deletion resources/js/utils/score-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function hasMenu(score: SoloScoreJson) {
}

export function hasReplay(score: SoloScoreJson) {
return score.replay != null && score.replay;
return score.has_replay;
}

export function hasShow(score: SoloScoreJson) {
Expand Down
19 changes: 19 additions & 0 deletions tests/Libraries/bbcode_examples/basic_youtube.base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[youtube]https://youtube.com/shorts/mT5vq7egFqQ?si=ThgVtuwBmOJ3QFq9[/youtube]

[youtube]https://m.youtube.com/shorts/mT5vq7egFqQ?si=ThgVtuwBmOJ3QFq9[/youtube]

[youtube]https://www.youtube.com/shorts/mT5vq7egFqQ[/youtube]

[youtube]https://www.youtube.com/embed/mT5vq7egFqQ?rel=0[/youtube]

[youtube]mT5vq7egFqQ[/youtube]

[youtube]https://youtu.be/YOeKD8ig3eM?si=DM3l66PIt6uXhv0K[/youtube]

[youtube]https://m.youtube.com/watch?v=YOeKD8ig3eM[/youtube]

[youtube]https://www.youtube.com/watch?v=YOeKD8ig3eM[/youtube]

[youtube]https://www.youtube.com/embed/YOeKD8ig3eM?rel=0[/youtube]

[youtube]YOeKD8ig3eM[/youtube]
19 changes: 19 additions & 0 deletions tests/Libraries/bbcode_examples/basic_youtube.db.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[youtube:1]mT5vq7egFqQ[/youtube:1]

[youtube:1]mT5vq7egFqQ[/youtube:1]

[youtube:1]mT5vq7egFqQ[/youtube:1]

[youtube:1]mT5vq7egFqQ[/youtube:1]

[youtube:1]mT5vq7egFqQ[/youtube:1]

[youtube:1]YOeKD8ig3eM[/youtube:1]

[youtube:1]YOeKD8ig3eM[/youtube:1]

[youtube:1]YOeKD8ig3eM[/youtube:1]

[youtube:1]YOeKD8ig3eM[/youtube:1]

[youtube:1]YOeKD8ig3eM[/youtube:1]
39 changes: 39 additions & 0 deletions tests/Libraries/bbcode_examples/basic_youtube.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/mT5vq7egFqQ?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/mT5vq7egFqQ?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/mT5vq7egFqQ?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/mT5vq7egFqQ?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/mT5vq7egFqQ?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/YOeKD8ig3eM?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/YOeKD8ig3eM?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/YOeKD8ig3eM?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/YOeKD8ig3eM?rel=0"></iframe>
</div></div>
<br /><br />
<div class="bbcode__video-box"><div class="u-embed-wide">
<iframe src="https://www.youtube.com/embed/YOeKD8ig3eM?rel=0"></iframe>
</div></div>

0 comments on commit 30ce16c

Please sign in to comment.