Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accidentally exported methods from use server #1059

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/redis-lock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use server'
import 'server-only'

import { kv } from '@vercel/kv'
import { v4 as uuidv4 } from 'uuid'

const LOCK_TIMEOUT = 30 * 1000 // 30 seconds

export async function aquireLock(key: string): Promise<string | null> {
async function aquireLock(key: string): Promise<string | null> {
const lockKey = `lock:${key}`
const lockValue = uuidv4()
const acquired = await kv.set(lockKey, lockValue, {
@@ -14,10 +15,7 @@ export async function aquireLock(key: string): Promise<string | null> {
return acquired ? lockValue : null
}

export async function releaseLock(
lockKey: string,
lockValue: string,
): Promise<void> {
async function releaseLock(lockKey: string, lockValue: string): Promise<void> {
const currentLockValue = await kv.get(lockKey)
if (currentLockValue === lockValue) {
await kv.del(lockKey)
3 changes: 2 additions & 1 deletion src/app/[tab]/page.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

import { notFound } from 'next/navigation'
import Harbor from '../harbor/tabs/tabs'
import { createMagicSession, getSession } from '../utils/auth'
import { createMagicSession } from '../utils/create-magic-session'
import { getSession } from '../utils/get-session'
import { Card } from '@/components/ui/card'
import { SoundButton } from '../../components/sound-button.js'
import { useEffect } from 'react'
4 changes: 2 additions & 2 deletions src/app/api/buy/[item]/route.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getSession } from '@/app/utils/auth'
import { redirect } from 'next/navigation'
import { NextResponse } from 'next/server'
import { getSelfPerson } from '@/app/utils/airtable'
import { getSelfPerson } from '@/app/utils/get-self-person'
import { base } from 'airtable'

export async function GET(request, { params }) {
const session = await getSession()
const person = await getSelfPerson(session.slackId)
const person = await getSelfPerson()
if (!person) {
return NextResponse.json(
{ error: "i don't even know who you are" },
3 changes: 1 addition & 2 deletions src/app/api/cron/process-background-jobs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use server'
import 'server-only'

import { sql } from '@vercel/postgres'
import Airtable from 'airtable'

async function processPendingInviteJobs() {
const { rows } =
2 changes: 1 addition & 1 deletion src/app/api/project_ideas/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use server'
import 'server-only'

import { NextRequest, NextResponse } from 'next/server'
import { sample } from '../../../../lib/flavor'
2 changes: 1 addition & 1 deletion src/app/api/referral/[autonum]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use server'
import 'server-only'

import { getPersonByAuto } from '@/app/utils/airtable'
import { redirect } from 'next/navigation'
37 changes: 5 additions & 32 deletions src/app/harbor/battles/battles.tsx
Original file line number Diff line number Diff line change
@@ -7,10 +7,8 @@ import { AnimatePresence, motion } from 'framer-motion'
import ReactMarkdown from 'react-markdown'

import { LoadingSpinner } from '../../../components/ui/loading_spinner.js'
import {
getVotesRemainingForNextPendingShip,
safePerson,
} from '@/app/utils/airtable'
import { getVotesRemainingForNextPendingShip } from '@/app/utils/get-votes-remaining-for-next-pending-ship'
import { getSafePerson } from '@/app/utils/get-safe-person'
import useLocalStorageState from '../../../../lib/useLocalStorageState'
import { useToast } from '@/hooks/use-toast'
import { HsSession } from '@/app/utils/auth'
@@ -33,7 +31,7 @@ interface Matchup {
ts: number
}

export default function Matchups({ session }: { session: HsSession }) {
export default function Battles({ session }: { session: HsSession }) {
const [matchup, setMatchup] = useState<Matchup | null>(null)
const [loading, setLoading] = useState(true)
const [selectedProject, setSelectedProject] = useState<Ships | null>(null)
@@ -81,7 +79,7 @@ export default function Matchups({ session }: { session: HsSession }) {
})

useEffect(() => {
safePerson().then((sp) => {
getSafePerson().then((sp) => {
setCursed(sp.cursed)
setBlessed(sp.blessed)
})
@@ -174,33 +172,8 @@ export default function Matchups({ session }: { session: HsSession }) {
}, interval)
}

// useEffect(() => {
// if (turnstileRef.current) {
// let widgetId;

// const genToken = () => {
// widgetId = window.turnstile!.render(turnstileRef.current, {
// sitekey: "0x4AAAAAAAzOAaBz1TUgJG68", // Site key
// theme: "dark",
// callback: (token: string) => {
// console.log(token);
// setTurnstileToken(token);
// },
// });
// };
// genToken();

// const genTokenInterval = setInterval(genToken, 4 * 60 * 1_000); // Every 4 minutes

// return () => {
// window.turnstile!.reset(widgetId);
// clearInterval(genTokenInterval);
// };
// }
// }, [selectedProject]);

const fetchVoteBalance = async () => {
setVoteBalance(await getVotesRemainingForNextPendingShip(session.slackId))
setVoteBalance(await getVotesRemainingForNextPendingShip())
}

const fetchMatchup = async (
3 changes: 3 additions & 0 deletions src/app/harbor/battles/fraud-utils.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@ export async function sendFraudReport(
reason: string,
) {
const session = await getSession()
if (!session) {
throw new Error('Unauthorized request')
}

const res = await fetch(
'https://middleman.hackclub.com/airtable/v0/appTeNFYcUiYfGcR6/flagged_projects',
77 changes: 0 additions & 77 deletions src/app/harbor/gallery/gallery.tsx

This file was deleted.

55 changes: 0 additions & 55 deletions src/app/harbor/gallery/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/harbor/shipyard/new-ship-form.tsx
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { createShip, Ship } from './ship-utils'
import { Button } from '@/components/ui/button'
import JSConfetti from 'js-confetti'
import { useEffect, useRef, useState } from 'react'
import { getWakaSessions } from '@/app/utils/waka'
import { getWakaSessions } from '@/app/utils/get-waka-sessions'
import { AnimatePresence, motion } from 'framer-motion'
import { useToast } from '@/hooks/use-toast'
import Icon from '@hackclub/icons'
2 changes: 1 addition & 1 deletion src/app/harbor/shipyard/new-update-form.tsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import type { Ship } from '@/app/utils/data'
import { Button } from '@/components/ui/button'
import JSConfetti from 'js-confetti'
import { useCallback, useEffect, useRef, useState } from 'react'
import { getWakaSessions } from '@/app/utils/waka'
import { getWakaSessions } from '@/app/utils/get-waka-sessions'
import Icon from '@hackclub/icons'

export default function NewUpdateForm({
8 changes: 4 additions & 4 deletions src/app/harbor/shipyard/ship-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use server'

import { getSelfPerson } from '@/app/utils/airtable'
import { getSelfPerson } from '@/app/utils/get-self-person'
import { getSession } from '@/app/utils/auth'
import { fetchShips, person } from '@/app/utils/data'
import { getWakaSessions } from '@/app/utils/waka'
import { getWakaSessions } from '@/app/utils/get-waka-sessions'
import { cookies } from 'next/headers'
import type { Ship } from '@/app/utils/data'
import Airtable from 'airtable'
@@ -45,7 +45,7 @@ export async function createShip(formData: FormData, isTutorial: boolean) {

const slackId = session.slackId
return await withLock(`ship:${slackId}`, async () => {
const entrantId = await getSelfPerson(slackId).then((p) => p.id)
const entrantId = await getSelfPerson().then((p) => p.id)

const isShipUpdate = formData.get('isShipUpdate')

@@ -100,7 +100,7 @@ export async function createShipUpdate(
const slackId = session.slackId

return withLock(`update:${slackId}`, async () => {
const entrantId = await getSelfPerson(slackId).then((p) => p.id)
const entrantId = await getSelfPerson().then((p) => p.id)

// This pattern makes sure the ship data is not fraudulent
const ships = await fetchShips(slackId)
3 changes: 2 additions & 1 deletion src/app/harbor/shipyard/ships.tsx
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ import { markdownComponents } from '@/components/markdown'
import { Button, buttonVariants } from '@/components/ui/button'
import NewShipForm from './new-ship-form'
import EditShipForm from './edit-ship-form'
import { getSession, HsSession } from '@/app/utils/auth'
import { type HsSession } from '@/app/utils/auth'
import { getSession } from '@/app/utils/get-session'
import Link from 'next/link'
import TimeAgo from 'javascript-time-ago'
import ShipPillCluster from '@/components/ui/ship-pill-cluster'
4 changes: 2 additions & 2 deletions src/app/harbor/shipyard/shipyard.tsx
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import Ships from './ships'
import useLocalStorageState from '../../../../lib/useLocalStorageState'
import { useEffect } from 'react'
import { getVotesRemainingForNextPendingShip } from '@/app/utils/airtable'
import { getVotesRemainingForNextPendingShip } from '@/app/utils/get-votes-remaining-for-next-pending-ship'
import Pill from '@/components/ui/pill'
import { fetchShips, Ship } from '@/app/utils/data'
import { IdeaGenerator } from './idea-generator/impl'
@@ -44,7 +44,7 @@ export default function Shipyard({ session }: any) {
useEffect(() => {
fetchShips(session.slackId).then((ships) => setShips(ships))

getVotesRemainingForNextPendingShip(session.slackId).then((balance) =>
getVotesRemainingForNextPendingShip().then((balance) =>
setVoteBalance(balance),
)
}, [])
6 changes: 3 additions & 3 deletions src/app/harbor/shop/shop-utils.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import Airtable from 'airtable'
import { getSession } from '@/app/utils/auth'
import { getSelfPerson } from '@/app/utils/airtable'
import { getSelfPerson } from '@/app/utils/get-self-person'
import { NextResponse } from 'next/server'

const base = () => {
@@ -37,7 +37,7 @@ export async function getPerson() {
if (!('slackId' in session)) {
return
}
const person = await getSelfPerson(session.slackId)
const person = await getSelfPerson()
if (!person) {
return NextResponse.json(
{ error: "i don't even know who you are" },
@@ -52,7 +52,7 @@ export async function getShop(): Promise<ShopItem[]> {
if (!('slackId' in session)) {
return
}
const person = await getSelfPerson(session.slackId)
const person = await getSelfPerson()

return new Promise((resolve, reject) => {
base()('shop_items')
Loading