Merge remote-tracking branch 'upstream/master'
Some checks failed
Build WorldGuessr / build (push) Failing after 1m53s
Some checks failed
Build WorldGuessr / build (push) Failing after 1m53s
This commit is contained in:
commit
76e1c9b8c6
4 changed files with 28 additions and 12 deletions
|
|
@ -7,7 +7,7 @@ export default async function handler(req, res) {
|
|||
return res.status(405).json({ message: 'Method not allowed' });
|
||||
}
|
||||
|
||||
const { secret, page = 1, limit = 10 } = req.body;
|
||||
const { secret, targetUserId, page = 1, limit = 10 } = req.body;
|
||||
|
||||
// Validate secret
|
||||
if (!secret || typeof secret !== 'string') {
|
||||
|
|
@ -15,12 +15,26 @@ export default async function handler(req, res) {
|
|||
}
|
||||
|
||||
try {
|
||||
// Verify user exists
|
||||
const user = await User.findOne({ secret });
|
||||
if (!user) {
|
||||
// Verify requesting user exists
|
||||
const requestingUser = await User.findOne({ secret });
|
||||
if (!requestingUser) {
|
||||
return res.status(404).json({ message: 'User not found' });
|
||||
}
|
||||
|
||||
// If targetUserId is provided, verify the requester is staff
|
||||
let user;
|
||||
if (targetUserId) {
|
||||
if (!requestingUser.staff) {
|
||||
return res.status(403).json({ message: 'Unauthorized' });
|
||||
}
|
||||
user = await User.findById(targetUserId);
|
||||
if (!user) {
|
||||
return res.status(404).json({ message: 'Target user not found' });
|
||||
}
|
||||
} else {
|
||||
user = requestingUser;
|
||||
}
|
||||
|
||||
// Calculate pagination
|
||||
const pageNum = Math.max(1, parseInt(page));
|
||||
const limitNum = Math.min(50, Math.max(1, parseInt(limit))); // Max 50 games per page
|
||||
|
|
@ -48,13 +62,13 @@ export default async function handler(req, res) {
|
|||
// Format games for frontend
|
||||
const formattedGames = games.map(game => {
|
||||
// Find the user's player data
|
||||
const userPlayer = game.players.find(player => player.accountId === user._id.toString() || player.accountId === secret);
|
||||
const userPlayer = game.players.find(player => player.accountId === user._id.toString());
|
||||
|
||||
// For ranked duels, find opponent data
|
||||
let opponentPlayer = null;
|
||||
if (game.gameType === 'ranked_duel') {
|
||||
opponentPlayer = game.players.find(player =>
|
||||
player.accountId !== user._id.toString() && player.accountId !== secret
|
||||
opponentPlayer = game.players.find(player =>
|
||||
player.accountId !== user._id.toString()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export default async function handler(req, res) {
|
|||
return res.status(403).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
console.log('requestingUser', requestingUser.username, requestingUser.accountId, username);
|
||||
let targetUser;
|
||||
let searchType = null; // Track how we found the user
|
||||
|
||||
|
|
@ -291,7 +292,6 @@ async function buildUserResponse(targetUser) {
|
|||
const response = {
|
||||
targetUser: {
|
||||
username: targetUser.username,
|
||||
secret: targetUser.secret,
|
||||
_id: targetUser._id,
|
||||
totalXp: targetUser.totalXp,
|
||||
totalGamesPlayed: targetUser.totalGamesPlayed,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import styles from '../styles/gameHistory.module.css';
|
|||
import Link from 'next/link';
|
||||
import CountryFlag from './utils/countryFlag';
|
||||
|
||||
export default function GameHistory({ session, onGameClick, targetUserSecret = null, targetUserData = null, page = null, setPage = null }) {
|
||||
export default function GameHistory({ session, onGameClick, targetUserId = null, targetUserData = null, page = null, setPage = null }) {
|
||||
const { t: text } = useTranslation("common");
|
||||
const [games, setGames] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
|
@ -33,7 +33,8 @@ export default function GameHistory({ session, onGameClick, targetUserSecret = n
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
secret: targetUserSecret || session?.token?.secret,
|
||||
secret: session?.token?.secret,
|
||||
...(targetUserId && { targetUserId }),
|
||||
page,
|
||||
limit: 10
|
||||
}),
|
||||
|
|
@ -59,7 +60,7 @@ export default function GameHistory({ session, onGameClick, targetUserSecret = n
|
|||
if (typeof window !== 'undefined' && session?.token?.secret && window.cConfig?.apiUrl) {
|
||||
fetchGames(currentPage);
|
||||
}
|
||||
}, [session?.token?.secret, targetUserSecret, currentPage]);
|
||||
}, [session?.token?.secret, targetUserId, currentPage]);
|
||||
|
||||
const getGameTypeDisplay = (gameType) => {
|
||||
const types = {
|
||||
|
|
|
|||
|
|
@ -322,6 +322,7 @@ export default function ModDashboard({ session }) {
|
|||
const fetchGameById = async (gameId, targetUserId = null, reportedAccountId = null) => {
|
||||
if (!gameId) return;
|
||||
|
||||
setSavedScrollPosition(window.scrollY);
|
||||
setGameLoading(true);
|
||||
setError(null);
|
||||
setReportedUserId(reportedAccountId);
|
||||
|
|
@ -1808,7 +1809,7 @@ export default function ModDashboard({ session }) {
|
|||
{/* Game History */}
|
||||
<GameHistory
|
||||
session={session}
|
||||
targetUserSecret={targetUser.secret}
|
||||
targetUserId={targetUser._id}
|
||||
targetUserData={targetUser}
|
||||
onGameClick={handleGameClick}
|
||||
page={gameHistoryPage}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue