Skip to content

Commit

Permalink
Languages completed
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Oct 13, 2024
1 parent 9383f88 commit 5bd0c63
Show file tree
Hide file tree
Showing 39 changed files with 2,361 additions and 1,989 deletions.
4 changes: 2 additions & 2 deletions api/clues/getClue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Clue from '@/models/Clue';
import User from '@/models/User';
import Clue from '../../models/Clue.js';
import User from '../../models/User.js';

async function handler(req, res) {
if (req.method === 'GET') {
Expand Down
2 changes: 1 addition & 1 deletion api/clues/getCluesCount.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Clue from '@/models/Clue';
import Clue from '../../models/Clue.js';

let clueCountCache = {
count: 0,
Expand Down
5 changes: 2 additions & 3 deletions api/clues/makeClue.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NextApiRequest, NextApiResponse } from 'next';
import formidable from 'formidable';
// import { OpenAI } from 'openai';
import fs from 'fs';
import User from '@/models/User';
import Clue from '@/models/Clue';
import User from '../../models/User.js';
import Clue from '../../models/Clue.js';

// const openai = new OpenAI({
// apiKey: process.env.OPENAI_API_KEY,
Expand Down
7 changes: 3 additions & 4 deletions api/clues/rateClue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next';
import Clue from '@/models/Clue';
import User from '@/models/User';
import Clue from '../../models/Clue.js';
import User from '../../models/User.js';

async function handler(req, res) {
if (req.method === 'POST') {
Expand All @@ -11,7 +10,7 @@ async function handler(req, res) {
if (typeof secret !== 'string') {
return res.status(400).json({ message: 'Invalid input' });
}

if (!clueId || !rating || !secret) {
return res.status(400).json({ message: 'Missing clueId, rating, or secret' });
}
Expand Down
4 changes: 2 additions & 2 deletions api/map/approveRejectMap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Map from "@/models/Map";
import User from "@/models/User";
import Map from "../../models/Map.js";
import User from "../../models/User.js";

export default async function handler(req, res) {
// only allow POST
Expand Down
4 changes: 2 additions & 2 deletions api/map/delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Map from "@/models/Map";
import User from "@/models/User";
import Map from "../../models/Map.js";
import User from "../../models/User.js";

export default async function handler(req, res) {
// only allow DELETE
Expand Down
6 changes: 3 additions & 3 deletions api/map/heartMap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Map from '@/models/Map';
import User from '@/models/User';
import Map from '../../models/Map.js';
import User from '../../models/User.js';

const HEART_COOLDOWN = 500;
let recentHearts = {}
Expand All @@ -16,7 +16,7 @@ async function handler(req, res) {
if (typeof secret !== 'string') {
return res.status(400).json({ message: 'Invalid input' });
}


if (!mapId || !secret) {
return res.status(400).json({ message: 'Missing values' });
Expand Down
11 changes: 4 additions & 7 deletions api/map/mapHome.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import mapConst from "@/components/maps/mapConst";
import parseMapData from "@/components/utils/parseMapData";
import sendableMap from "@/components/utils/sendableMap";
import generateSlug from "@/components/utils/slugGenerator";
import Map from "@/models/Map";
import User from "@/models/User";
import officialCountryMaps from '@/public/officialCountryMaps.json';
import sendableMap from "../../components/utils/sendableMap.js";
import Map from "../../models/Map.js";
import User from "../../models/User.js";
import officialCountryMaps from '../../public/officialCountryMaps.json' with { type: "json" };

let mapCache = {
popular: {
Expand Down
53 changes: 53 additions & 0 deletions api/map/publicData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { getServerSession } from "../../components/auth/serverAuth.js";
import officialCountryMaps from "../../public/officialCountryMaps.json" with { type: "json" };
import Map from "../../models/Map.js";
import User from "../../models/User.js";
import msToTime from "../../components/msToTime.js";

export default async function handler(req, res) {
const slug = req.query.slug;
console.log("Getting map data for", slug);
const session = await getServerSession(req);

// Check if map is an official country map
const cntryMap = Object.values(officialCountryMaps).find(map => map.slug === slug);
if (cntryMap) {
return res.json({
mapData: {
...cntryMap,
description_short: cntryMap.shortDescription,
description_long: cntryMap.longDescription,
created_by: "WorldGuessr",
in_review: false,
rejected: false
}
});
}

// If map is not official, check user-created maps
const map = await Map.findOne({ slug })
.select({ 'data': { $slice: 10 } }) // Slice the data to limit to 10 items
.lean();

if (!map) {
return res.status(404).json({ message: 'Map not found' });
}

const authorId = map.created_by;
const authorUser = await User.findById(authorId).lean();
const authorSecret = authorUser?.secret;
const staff = session?.token?.staff;

const isCreatorOrStaff = session && (authorSecret === session?.token?.secret || staff);

if (!map.accepted && !isCreatorOrStaff) {
return res.status(404).json({ message: 'Map not accepted or no permission to view' });
}

map.created_by = authorUser?.username;
map.created_at = msToTime(Date.now() - map.created_at);

return res.json({
mapData: map
});
}
11 changes: 4 additions & 7 deletions api/map/searchMap.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import mapConst from "@/components/maps/mapConst";
import parseMapData from "@/components/utils/parseMapData";
import sendableMap from "@/components/utils/sendableMap";
import generateSlug from "@/components/utils/slugGenerator";
import Map from "@/models/Map";
import User from "@/models/User";
import officialCountryMaps from '@/public/officialCountryMaps.json';

import sendableMap from "../../components/utils/sendableMap.js";
import Map from "../../models/Map.js";
import User from "../../models/User.js";

export default async function searchMaps(req, res) {
// only allow POST
Expand Down
4 changes: 4 additions & 0 deletions components/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ function MapPlugin({ pinPoint, setPinPoint, answerShown, dest, gameOptions, ws,
}
// play sound
playSound();
// if point is outside bounds, pan back
const bounds = L.latLngBounds([-90, -180], [90, 180]);

if(!bounds.contains(e.latlng)) {
const center = e.target.panInsideBounds(bounds, { animate: true });
}
}
},
});
Expand Down
2 changes: 1 addition & 1 deletion components/accountModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function AccountModal({ session, shown, setAccountModalOpen, inCr
useEffect(() => {
if(shown) {
const fetchData = async () => {
const response = await fetch('/api/publicAccount', {
const response = await fetch(window.cConfig.apiUrl+'/api/publicAccount', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
6 changes: 0 additions & 6 deletions components/auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,4 @@ export function useSession() {
return {
data: session
}
}

export function getServerSession(req, res, authOptions) {
console.log("Getting server session", req, res, authOptions);

return null;
}
5 changes: 5 additions & 0 deletions components/auth/serverAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function getServerSession(req, res, authOptions) {
console.log("Getting server session");

return null;
}
2 changes: 1 addition & 1 deletion components/clueBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ halfFillMode='svg'
...ratedIndexes,
[`rate${index}`]: value
});
fetch('/api/clues/rateClue', {
fetch(window.cConfig.apiUrl+'/api/clues/rateClue', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion components/explanationModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ExplanationModal({ lat, long, session, shown, onClose })
setSending(true);


const response = await fetch('/api/clues/makeClue', {
const response = await fetch(window.cConfig.apiUrl+'/api/clues/makeClue', {
method: 'POST',
headers: {
// 'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion components/findCountry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default async function findCountry({lat, lon}) {
let data = null;
try {
const resp = await fetch(`/api/country?lat=${lat}&lon=${lon}`); // fetch data from OSM
const resp = await fetch(window.cConfig.apiUrl+`/api/country?lat=${lat}&lon=${lon}`); // fetch data from OSM
data = await resp.json();
} catch (e) {
data = { address: { country: "Unknown" }}; // default to unknown
Expand Down
4 changes: 2 additions & 2 deletions components/gameUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default function GameUI({ singlePlayerRound, setSinglePlayerRound, showDi
if(window.location.search.includes("learn=true")) {

console.log("fetching clue")
fetch('/api/clues/getClue'+(latLong ? `?lat=${latLong.lat}&lng=${latLong.long}` : '')).then(res => res.json()).then(data => {
fetch(window.cConfig.apiUrl+'/api/clues/getClue'+(latLong ? `?lat=${latLong.lat}&lng=${latLong.long}` : '')).then(res => res.json()).then(data => {

if(data.error) {
console.error(data.error);
Expand Down Expand Up @@ -336,7 +336,7 @@ export default function GameUI({ singlePlayerRound, setSinglePlayerRound, showDi
if(multiplayerState?.inGame) return;

if(xpEarned > 0 && session?.token?.secret && gameOptions.official) {
fetch('/api/storeGame', {
fetch(window.cConfig.apiUrl+'/api/storeGame', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down
Loading

0 comments on commit 5bd0c63

Please sign in to comment.