Skip to content

Commit

Permalink
Bump a lot of deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasamato committed Dec 4, 2024
1 parent 8f09b2d commit ce0b08b
Show file tree
Hide file tree
Showing 94 changed files with 2,381 additions and 1,761 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NEXT_PUBLIC_SITE_NAME="The Anime Index"
# remove trailing slash !!!
NEXT_PUBLIC_DOMAIN="https://piracy.moe"
NEXTAUTH_URL="https://piracy.moe"
AUTH_TRUST_HOST="true"

# secret for session hash validations
NEXTAUTH_SECRET="generate_a_real_long_and_secure_random_string"
Expand Down
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:22.3
FROM node:23.3
WORKDIR /app

# We use the image browserless/chrome instead of having our own chrome instance here
Expand All @@ -12,6 +12,7 @@ ENV NEXT_PUBLIC_SITE_NAME="The Anime Index"
# connection urls
ENV NEXTAUTH_URL="https://theindex.moe"
ENV NEXT_PUBLIC_DOMAIN="https://theindex.moe"
ENV AUTH_TRUST_HOST="true"
ENV DATABASE_URL="mongodb://mongo:27017/index"
ENV CACHE_URL="redis://redis:6379"
ENV AUDIT_WEBHOOK=""
Expand Down Expand Up @@ -40,6 +41,13 @@ COPY package.json package-lock.json ./
RUN npm ci
ENV PATH /app/node_modules/.bin:$PATH

# manully add .js to import as something is messed up...
RUN sed -i 's/next\/server/next\/server.js/' /app/node_modules/next-auth/lib/env.js \
&& sed -i 's/next\/server/next\/server.js/' /app/node_modules/next-auth/lib/index.js \
&& sed -i 's/next\/headers/next\/headers.js/' /app/node_modules/next-auth/lib/index.js \
&& sed -i 's/next\/headers/next\/headers.js/' /app/node_modules/next-auth/lib/actions.js \
&& sed -i 's/next\/navigation/next\/navigation.js/' /app/node_modules/next-auth/lib/actions.js

# build the web app
COPY . .

Expand Down
3 changes: 3 additions & 0 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { handlers } from '../../../../auth'

export const { GET, POST } = handlers
62 changes: 38 additions & 24 deletions pages/api/auth/[...nextauth].ts → auth.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import NextAuth from 'next-auth'
import DiscordProvider from 'next-auth/providers/discord'
import { addUser } from '../../../lib/db/users'
import { AccountType, type User } from '../../../types/User'
import { MongoDBAdapter } from '@next-auth/mongodb-adapter'
import { dbClient } from '../../../lib/db/db'
import { addUser } from './lib/db/users'
import { AccountType, type User } from './types/User'
import { MongoDBAdapter } from '@auth/mongodb-adapter'
import { dbClient } from './lib/db/db'
import { ObjectId } from 'mongodb'
import type { AuthOptions } from 'next-auth'
import { findOneTyped } from '../../../lib/db/dbTyped'
import { Types } from '../../../types/Components'
import type { NextAuthConfig } from 'next-auth'
import { findOneTyped } from './lib/db/dbTyped'
import { Types } from './types/Components'

export const authOptions: AuthOptions = {
export const authOptions: NextAuthConfig = {
providers: [
DiscordProvider({
clientId: process.env.DISCORD_CLIENT_ID,
Expand Down Expand Up @@ -57,26 +57,39 @@ export const authOptions: AuthOptions = {
if (isNewUser) {
console.log('Creating new user', user.name)
const accountType =
account !== null &&
typeof process.env.SETUP_WHITELIST_DISCORD_ID !== 'undefined' &&
process.env.SETUP_WHITELIST_DISCORD_ID !== '' &&
account.providerAccountId === process.env.SETUP_WHITELIST_DISCORD_ID
? AccountType.admin
: AccountType.user
await addUser({
uid: user.id.toString(),
accountType,
})
} else if (user.image !== profile.image) {
// update new discord image on login
const db = (await dbClient).db('index')
await db.collection('nextauth_users').updateOne(
{ _id: new ObjectId(user.id) },
{
$set: {
image: profile.image,
},
}
)
if (typeof user.id !== 'undefined') {
await addUser({
uid: user.id.toString(),
accountType,
})
} else {
console.log('Unable to create new user', user, 'due to missing id')
}
} else if (profile && user.image !== profile.image) {
if (typeof user.id !== 'undefined') {
// update new discord image on login
const db = (await dbClient).db('index')
await db.collection('nextauth_users').updateOne(
{ _id: new ObjectId(user.id) },
{
$set: {
image: profile.image,
},
}
)
} else {
console.log(
'Unable to update user profile picutre',
user,
'due to missing id'
)
}
}
},
},
Expand All @@ -91,4 +104,5 @@ export const authOptions: AuthOptions = {
}),
secret: process.env.NEXTAUTH_SECRET,
}
export default NextAuth(authOptions)

export const { auth, handlers, signIn, signOut } = NextAuth(authOptions)
Binary file removed bun.lockb
Binary file not shown.
48 changes: 32 additions & 16 deletions components/CardRowView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,38 @@ import UserCard from './cards/UserCard'
import UserRow from './rows/UserRow'
import ListCard from './cards/ListCard'
import ListRow from './rows/ListRow'
import { Column } from '../types/Column'
import { User } from '../types/User'
import { Item } from '../types/Item'
import { Collection } from '../types/Collection'
import { Library } from '../types/Library'
import { List } from '../types/List'
import { Types } from '../types/Components'

type Props = {
cardView: boolean,
type: Types,
content: User | Item | List | Collection | Column | Library
columns: Column[]
move?: (order: number) => void
add?: () => void
remove?: () => void
}

const CardRowView = ({
cardView = true,
type,
content,
add = null,
move = null,
remove = null,
add,
move,
remove,
columns = [],
}) => {
}: Props) => {
if (type === Types.item) {
if (cardView) {
return (
<ItemCard
item={content}
item={content as Item}
columns={columns}
add={add}
move={move}
Expand All @@ -36,7 +52,7 @@ const CardRowView = ({
}
return (
<ItemRow
item={content}
item={content as Item}
columns={columns}
add={add}
move={move}
Expand All @@ -46,15 +62,15 @@ const CardRowView = ({
} else if (type === Types.column) {
if (cardView) {
return (
<ColumnCard column={content} add={add} move={move} remove={remove} />
<ColumnCard column={content as Column} add={add} move={move} remove={remove} />
)
}
return <ColumnRow column={content} add={add} move={move} remove={remove} />
return <ColumnRow column={content as Column} add={add} move={move} remove={remove} />
} else if (type === Types.collection) {
if (cardView) {
return (
<CollectionCard
collection={content}
collection={content as Collection}
add={add}
move={move}
remove={remove}
Expand All @@ -63,7 +79,7 @@ const CardRowView = ({
}
return (
<CollectionRow
collection={content}
collection={content as Collection}
add={add}
move={move}
remove={remove}
Expand All @@ -72,22 +88,22 @@ const CardRowView = ({
} else if (type === Types.library) {
if (cardView) {
return (
<LibraryCard library={content} add={add} move={move} remove={remove} />
<LibraryCard library={content as Library} add={add} move={move} remove={remove} />
)
}
return (
<LibraryRow library={content} add={add} move={move} remove={remove} />
<LibraryRow library={content as Library} add={add} move={move} remove={remove} />
)
} else if (type === Types.user) {
if (cardView) {
return <UserCard user={content} add={add} move={move} remove={remove} />
return <UserCard user={content as User} add={add} move={move} remove={remove} />
}
return <UserRow user={content} add={add} move={move} remove={remove} />
return <UserRow user={content as User} add={add} move={move} remove={remove} />
} else if (type === Types.list) {
if (cardView) {
return <ListCard list={content} add={add} move={move} remove={remove} />
return <ListCard list={content as List} add={add} move={move} remove={remove} />
}
return <ListRow list={content} add={add} move={move} remove={remove} />
return <ListRow list={content as List} add={add} move={move} remove={remove} />
} else {
console.error('Unknown type of content:', type)
}
Expand Down
12 changes: 7 additions & 5 deletions components/boards/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const Board: FC<Props> = ({
)
updateContent(newContent, newUnselectedContent)
}
: null
: undefined
}
move={
moveAllowed
Expand All @@ -231,7 +231,7 @@ const Board: FC<Props> = ({
updateContent(copy, unselectedContent)
}
}
: null
: undefined
}
remove={
removeAllowed
Expand Down Expand Up @@ -263,7 +263,7 @@ const Board: FC<Props> = ({
updateContent(newContent, newUnselectedContent)
}
}
: null
: undefined
}
columns={compactView ? [] : columns}
/>
Expand Down Expand Up @@ -365,8 +365,10 @@ const Board: FC<Props> = ({
(option) => option.name === event.target.value
)
console.log('Changed sorting to', newSortOption)
setSortOption(newSortOption)
setContent(content.sort(newSortOption.sort))
if (typeof newSortOption !== 'undefined') {
setSortOption(newSortOption)
setContent(content.sort(newSortOption.sort))
}
}}
/>
)}
Expand Down
6 changes: 3 additions & 3 deletions components/cards/CollectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type Props = {

const CollectionCard: FC<Props> = ({
collection,
add = null,
remove = null,
move = null,
add,
remove,
move,
}) => {
return (
<Card
Expand Down
6 changes: 3 additions & 3 deletions components/cards/ColumnCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type Props = {

const ColumnCard: FC<Props> = ({
column,
add = null,
remove = null,
move = null,
add,
remove,
move,
}) => {
return (
<Card
Expand Down
4 changes: 2 additions & 2 deletions components/cards/DataCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Props = {
onChange?: (value: any) => void
}

const DataCard: FC<Props> = ({ data, column, onChange = null }) => {
const DataCard: FC<Props> = ({ data, column, onChange }) => {
const { data: session } = useSession()

return (
Expand All @@ -37,7 +37,7 @@ const DataCard: FC<Props> = ({ data, column, onChange = null }) => {
)}
</h5>

{onChange === null && (
{typeof onChange === 'undefined' && (
<p className={styles.description + ' card-text'}>
{column.description}
</p>
Expand Down
9 changes: 1 addition & 8 deletions components/cards/ItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ type Props = {
remove?: () => void
}

const ItemCard: FC<Props> = ({
item,
columns = [],
add = null,
remove = null,
move = null,
}) => {
const ItemCard: FC<Props> = ({ item, columns = [], add, remove, move }) => {
const column = splitColumnsIntoTypes(columns, item.data)

return (
Expand Down Expand Up @@ -55,7 +49,6 @@ const ItemCard: FC<Props> = ({
column={c}
sponsor={item.sponsor}
key={c._id}
data={null}
/>
))}
</div>
Expand Down
7 changes: 1 addition & 6 deletions components/cards/LibraryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ type Props = {
remove?: () => void
}

const LibraryCard: FC<Props> = ({
library,
add = null,
remove = null,
move = null,
}) => {
const LibraryCard: FC<Props> = ({ library, add, remove, move }) => {
return (
<Card
type={Types.library}
Expand Down
7 changes: 1 addition & 6 deletions components/cards/ListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ type Props = {
remove?: () => void
}

const ListCard: FC<Props> = ({
list,
add = null,
remove = null,
move = null,
}) => {
const ListCard: FC<Props> = ({ list, add, remove, move }) => {
return (
<Card
type={Types.list}
Expand Down
7 changes: 1 addition & 6 deletions components/cards/UserCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ type Props = {
remove?: () => void
}

const UserCard: FC<Props> = ({
user,
add = null,
remove = null,
move = null,
}) => {
const UserCard: FC<Props> = ({ user, add, remove, move }) => {
const joined = new Date(user.createdAt).toISOString().slice(0, 10)
return (
<Card
Expand Down
Loading

0 comments on commit ce0b08b

Please sign in to comment.