Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Add basic image uploaded to webhoookthing (#295)

Sean Boulta85b0506fe07
diff --git a/.env.example b/.env.example
index 520b2649..66655dd1 100644
--- a/.env.example
+++ b/.env.example
@@ -1,6 +1,9 @@
DATABASE_URL="mysql://dev:dev@localhost/typehero"
GITHUB_ID=
GITHUB_SECRET=
+
+UPLOADTHING_SECRET=
+UPLOADTHING_APP_ID=
# Next Auth
# You can generate a new secret on the command line with:
# openssl rand -base64 32
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5f30b280..18413337 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -9,6 +9,8 @@ env:
GITHUB_SECRET: 'lmao'
NEXTAUTH_SECRET: 'ligma'
NEXTAUTH_URL: 'http://localhost:3000'
+ UPLOADTHING_SECRET: 'ligma'
+ UPLOADTHING_APP_ID: 'ligma'
jobs:
build:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a155e66a..0d44227d 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -54,7 +54,11 @@ GITHUB_ID=<client_id>
GITHUB_SECRET=<client_secret>
```
-### 4. Install dependencies
+### 4. Setup uploadthing for file uploads
+
+Go to [uploadthing.com](https://uploadthing.com/dashboard) and create a project, then copy in the secrets into your `.env`.
+
+### 5. Install dependencies
Use `pnpm` to install dependencies.
@@ -62,7 +66,7 @@ Use `pnpm` to install dependencies.
pnpm install
```
-### 5. Push Schema Changes
+### 6. Push Schema Changes
Run the prisma push command to sync db schemas:
@@ -70,7 +74,7 @@ Run the prisma push command to sync db schemas:
pnpx prisma db push
```
-### 6. Seed the database
+### 7. Seed the database
Run the prisma seed command to add mock data
diff --git a/next.config.mjs b/next.config.mjs
index 78b04dc8..597734c5 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -30,6 +30,10 @@ const config = {
protocol: 'https',
hostname: 'avatars.githubusercontent.com',
},
+ {
+ protocol: 'https',
+ hostname: 'uploadthing.com',
+ },
],
},
swcMinify: true,
diff --git a/package.json b/package.json
index 81fc942a..f493df2c 100644
--- a/package.json
+++ b/package.json
@@ -44,6 +44,7 @@
"@tanstack/react-table": "^8.9.3",
"@types/lodash": "^4.14.195",
"@uiw/react-md-editor": "^3.23.3",
+ "@uploadthing/react": "^5.2.0",
"class-variance-authority": "^0.6.1",
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
@@ -61,6 +62,7 @@
"react": "18.2.0",
"react-day-picker": "^8.8.0",
"react-dom": "18.2.0",
+ "react-dropzone": "^14.2.3",
"react-hook-form": "^7.45.1",
"react-intersection-observer": "^9.5.2",
"react-markdown": "^8.0.7",
@@ -73,6 +75,7 @@
"tailwindcss-animate": "^1.0.6",
"unified": "^10.1.2",
"unist-util-visit": "^5.0.0",
+ "uploadthing": "^5.2.1",
"uuid-by-string": "^4.0.0",
"zod": "^3.21.4",
"zustand": "^4.3.9"
@@ -121,5 +124,6 @@
},
"lint-staged": {
"src/**/*.{ts,tsx,css}": "prettier --write"
- }
+ },
+ "packageManager": "[email protected]"
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 38ec78cb..71d971dc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -91,6 +91,9 @@ dependencies:
'@uiw/react-md-editor':
specifier: ^3.23.3
+ '@uploadthing/react':
+ specifier: ^5.2.0
class-variance-authority:
specifier: ^0.6.1
version: 0.6.1
@@ -142,6 +145,9 @@ dependencies:
react-dom:
specifier: 18.2.0
version: 18.2.0([email protected])
+ react-dropzone:
+ specifier: ^14.2.3
+ version: 14.2.3([email protected])
react-hook-form:
specifier: ^7.45.1
version: 7.45.1([email protected])
@@ -178,6 +184,9 @@ dependencies:
unist-util-visit:
specifier: ^5.0.0
version: 5.0.0
+ uploadthing:
+ specifier: ^5.2.1
+ version: 5.2.1([email protected])
uuid-by-string:
specifier: ^4.0.0
version: 4.0.0
@@ -2577,6 +2586,39 @@ packages:
- supports-color
dev: false
+ /@uploadthing/[email protected]:
+ resolution: {integrity: sha512-nRcdyM622+GYT9SdaJIVLknqoc8i7krItinfuBPtvmPc+UNGDJ+pMkr4AatYp88cEc4iYtPlN8flJvZ3dNtgrg==}
+ dev: false
+
+ resolution: {integrity: sha512-kVM/3JZJhMgk2QGvyhyqPA5Zycq9TaqgCg/MNWvWDSgzw5MKeMyiXsEAJEQ7jO1BBjAfZ0O0NCM0VXCXuMLkPQ==}
+ peerDependencies:
+ react: ^17.0.2 || ^18.0.0
+ react-dropzone: ^14.2.3
+ uploadthing: ^5.0.0
+ dependencies:
+ '@uploadthing/shared': 5.1.0(@uploadthing/[email protected])([email protected])
+ react: 18.2.0
+ react-dropzone: 14.2.3([email protected])
+ uploadthing: 5.2.1([email protected])
+ transitivePeerDependencies:
+ - '@uploadthing/mime-types'
+ - zod
+ dev: false
+
+ resolution: {integrity: sha512-3pt9PFN0QuAvCv2LZyC66Bcn+zDUbh8Ws3noYHIlr2BFIvsH0zs2oVG+WXhb+9Nunu8+DER6iol7frza5rldIA==}
+ peerDependencies:
+ '@uploadthing/mime-types': ^0.2.0
+ zod: ^3.21.4
+ peerDependenciesMeta:
+ '@uploadthing/mime-types':
+ optional: true
+ dependencies:
+ '@uploadthing/mime-types': 0.2.0
+ zod: 3.21.4
+ dev: false
+
/@webassemblyjs/[email protected]:
resolution: {integrity: sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==}
dependencies:
@@ -2870,6 +2912,11 @@ packages:
engines: {node: '>=8'}
dev: true
+ resolution: {integrity: sha512-7prDjvt9HmqiZ0cl5CRjtS84sEyhsHP2coDkaZKRKVfCDo9s7iw7ChVmar78Gu9pC4SoR/28wFu/G5JJhTnqEg==}
+ engines: {node: '>=4'}
+ dev: false
+
resolution: {integrity: sha512-FQzyfOsTlwVzjHxKEqRIAdJx9niO6VCBCoEwax/VLSoQF29ggECcPuBqUMZ+u8jCZOPSy8b8/8KnuFbp0SaFZQ==}
engines: {node: ^10 || ^12 || >=14}
@@ -3921,6 +3968,13 @@ packages:
flat-cache: 3.0.4
dev: true
+ resolution: {integrity: sha512-QlZ5yJC0VxHxQQsQhXvBaC7VRJ2uaxTf+Tfpu4Z/OcVQJVpZO+DGU0rkoVW5ce2SccxugvpBJoMvUs59iILYdw==}
+ engines: {node: '>= 12'}
+ dependencies:
+ tslib: 2.6.0
+ dev: false
+
resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==}
engines: {node: '>=8'}
@@ -5958,6 +6012,18 @@ packages:
scheduler: 0.23.0
dev: false
+ resolution: {integrity: sha512-O3om8I+PkFKbxCukfIR3QAGftYXDZfOE2N1mr/7qebQJHs7U+/RSL/9xomJNpRg9kM5h9soQSdf0Gc7OHF5Fug==}
+ engines: {node: '>= 10.13'}
+ peerDependencies:
+ react: '>= 16.8 || 18.0.0'
+ dependencies:
+ attr-accept: 2.2.2
+ file-selector: 0.6.0
+ prop-types: 15.8.1
+ react: 18.2.0
+ dev: false
+
resolution: {integrity: sha512-6dWoFJwycbuFfw/iKMcl+RdAOAOHDiF11KWYhNDRN/OkUt+Di5qsZHwA0OwsVnu9y135gkHpTw9DJA+WzCeR9w==}
engines: {node: '>=12.22.0'}
@@ -7018,6 +7084,15 @@ packages:
picocolors: 1.0.0
dev: true
+ resolution: {integrity: sha512-vav6UwvEOzBSoPYHGsM6PksyAmyUoPPylkcveTgAUWVS5kKWaaxcOlgStShveTUo3JnoKD2E9Z2+z1BWXALv8A==}
+ dependencies:
+ '@uploadthing/mime-types': 0.2.0
+ '@uploadthing/shared': 5.1.0(@uploadthing/[email protected])([email protected])
+ transitivePeerDependencies:
+ - zod
+ dev: false
+
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
dependencies:
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 51648c48..b5f69a9f 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -122,6 +122,8 @@ model User {
reports Report[] @relation("reporter")
reportsAbout Report[] @relation("reported_user")
moderated Report[] @relation("report_moderator")
+
+ imageUpload ImageUpload[]
}
model VerificationToken {
@@ -297,9 +299,9 @@ enum CommentRoot {
}
model Comment {
- id Int @id @default(autoincrement())
- text String @db.MediumText
- visible Boolean @default(true)
+ id Int @id @default(autoincrement())
+ text String @db.MediumText
+ visible Boolean @default(true)
parentId Int?
userId String
@@ -334,3 +336,23 @@ model Waitlist {
email String
intention WaitlistIntention
}
+
+model ImageUpload {
+ /// the id of the db row
+ id String @id @default(uuid())
+
+ /// the user id fk
+ userId String
+
+ /// The user that this is related to
+ user User @relation(fields: [userId], references: [id])
+
+ /// the url to the s3 uploaded assets
+ url String @db.VarChar(256)
+
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@index([userId])
+}
+
diff --git a/public/contributors.json b/public/contributors.json
index 3d7d70a7..1d68cf93 100644
--- a/public/contributors.json
+++ b/public/contributors.json
@@ -1 +1,317 @@
-[{"login":"bautistaaa","id":3660667,"node_id":"MDQ6VXNlcjM2NjA2Njc=","avatar_url":"https://avatars.githubusercontent.com/u/3660667?v=4","gravatar_id":"","url":"https://api.github.com/users/bautistaaa","html_url":"https://github.com/bautistaaa","followers_url":"https://api.github.com/users/bautistaaa/followers","following_url":"https://api.github.com/users/bautistaaa/following{/other_user}","gists_url":"https://api.github.com/users/bautistaaa/gists{/gist_id}","starred_url":"https://api.github.com/users/bautistaaa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bautistaaa/subscriptions","organizations_url":"https://api.github.com/users/bautistaaa/orgs","repos_url":"https://api.github.com/users/bautistaaa/repos","events_url":"https://api.github.com/users/bautistaaa/events{/privacy}","received_events_url":"https://api.github.com/users/bautistaaa/received_events","type":"User","site_admin":false,"contributions":58},{"login":"PickleNik","id":31113245,"node_id":"MDQ6VXNlcjMxMTEzMjQ1","avatar_url":"https://avatars.githubusercontent.com/u/31113245?v=4","gravatar_id":"","url":"https://api.github.com/users/PickleNik","html_url":"https://github.com/PickleNik","followers_url":"https://api.github.com/users/PickleNik/followers","following_url":"https://api.github.com/users/PickleNik/following{/other_user}","gists_url":"https://api.github.com/users/PickleNik/gists{/gist_id}","starred_url":"https://api.github.com/users/PickleNik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PickleNik/subscriptions","organizations_url":"https://api.github.com/users/PickleNik/orgs","repos_url":"https://api.github.com/users/PickleNik/repos","events_url":"https://api.github.com/users/PickleNik/events{/privacy}","received_events_url":"https://api.github.com/users/PickleNik/received_events","type":"User","site_admin":false,"contributions":56},{"login":"Hacksore","id":996134,"node_id":"MDQ6VXNlcjk5NjEzNA==","avatar_url":"https://avatars.githubusercontent.com/u/996134?v=4","gravatar_id":"","url":"https://api.github.com/users/Hacksore","html_url":"https://github.com/Hacksore","followers_url":"https://api.github.com/users/Hacksore/followers","following_url":"https://api.github.com/users/Hacksore/following{/other_user}","gists_url":"https://api.github.com/users/Hacksore/gists{/gist_id}","starred_url":"https://api.github.com/users/Hacksore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hacksore/subscriptions","organizations_url":"https://api.github.com/users/Hacksore/orgs","repos_url":"https://api.github.com/users/Hacksore/repos","events_url":"https://api.github.com/users/Hacksore/events{/privacy}","received_events_url":"https://api.github.com/users/Hacksore/received_events","type":"User","site_admin":false,"contributions":50},{"login":"jhechtf","id":8152471,"node_id":"MDQ6VXNlcjgxNTI0NzE=","avatar_url":"https://avatars.githubusercontent.com/u/8152471?v=4","gravatar_id":"","url":"https://api.github.com/users/jhechtf","html_url":"https://github.com/jhechtf","followers_url":"https://api.github.com/users/jhechtf/followers","following_url":"https://api.github.com/users/jhechtf/following{/other_user}","gists_url":"https://api.github.com/users/jhechtf/gists{/gist_id}","starred_url":"https://api.github.com/users/jhechtf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhechtf/subscriptions","organizations_url":"https://api.github.com/users/jhechtf/orgs","repos_url":"https://api.github.com/users/jhechtf/repos","events_url":"https://api.github.com/users/jhechtf/events{/privacy}","received_events_url":"https://api.github.com/users/jhechtf/received_events","type":"User","site_admin":false,"contributions":16},{"login":"ggrandi","id":49359646,"node_id":"MDQ6VXNlcjQ5MzU5NjQ2","avatar_url":"https://avatars.githubusercontent.com/u/49359646?v=4","gravatar_id":"","url":"https://api.github.com/users/ggrandi","html_url":"https://github.com/ggrandi","followers_url":"https://api.github.com/users/ggrandi/followers","following_url":"https://api.github.com/users/ggrandi/following{/other_user}","gists_url":"https://api.github.com/users/ggrandi/gists{/gist_id}","starred_url":"https://api.github.com/users/ggrandi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ggrandi/subscriptions","organizations_url":"https://api.github.com/users/ggrandi/orgs","repos_url":"https://api.github.com/users/ggrandi/repos","events_url":"https://api.github.com/users/ggrandi/events{/privacy}","received_events_url":"https://api.github.com/users/ggrandi/received_events","type":"User","site_admin":false,"contributions":15},{"login":"creativenull","id":3767728,"node_id":"MDQ6VXNlcjM3Njc3Mjg=","avatar_url":"https://avatars.githubusercontent.com/u/3767728?v=4","gravatar_id":"","url":"https://api.github.com/users/creativenull","html_url":"https://github.com/creativenull","followers_url":"https://api.github.com/users/creativenull/followers","following_url":"https://api.github.com/users/creativenull/following{/other_user}","gists_url":"https://api.github.com/users/creativenull/gists{/gist_id}","starred_url":"https://api.github.com/users/creativenull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/creativenull/subscriptions","organizations_url":"https://api.github.com/users/creativenull/orgs","repos_url":"https://api.github.com/users/creativenull/repos","events_url":"https://api.github.com/users/creativenull/events{/privacy}","received_events_url":"https://api.github.com/users/creativenull/received_events","type":"User","site_admin":false,"contributions":14},{"login":"ernestoresende","id":55156145,"node_id":"MDQ6VXNlcjU1MTU2MTQ1","avatar_url":"https://avatars.githubusercontent.com/u/55156145?v=4","gravatar_id":"","url":"https://api.github.com/users/ernestoresende","html_url":"https://github.com/ernestoresende","followers_url":"https://api.github.com/users/ernestoresende/followers","following_url":"https://api.github.com/users/ernestoresende/following{/other_user}","gists_url":"https://api.github.com/users/ernestoresende/gists{/gist_id}","starred_url":"https://api.github.com/users/ernestoresende/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ernestoresende/subscriptions","organizations_url":"https://api.github.com/users/ernestoresende/orgs","repos_url":"https://api.github.com/users/ernestoresende/repos","events_url":"https://api.github.com/users/ernestoresende/events{/privacy}","received_events_url":"https://api.github.com/users/ernestoresende/received_events","type":"User","site_admin":false,"contributions":9},{"login":"is-it-ayush","id":36449128,"node_id":"MDQ6VXNlcjM2NDQ5MTI4","avatar_url":"https://avatars.githubusercontent.com/u/36449128?v=4","gravatar_id":"","url":"https://api.github.com/users/is-it-ayush","html_url":"https://github.com/is-it-ayush","followers_url":"https://api.github.com/users/is-it-ayush/followers","following_url":"https://api.github.com/users/is-it-ayush/following{/other_user}","gists_url":"https://api.github.com/users/is-it-ayush/gists{/gist_id}","starred_url":"https://api.github.com/users/is-it-ayush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/is-it-ayush/subscriptions","organizations_url":"https://api.github.com/users/is-it-ayush/orgs","repos_url":"https://api.github.com/users/is-it-ayush/repos","events_url":"https://api.github.com/users/is-it-ayush/events{/privacy}","received_events_url":"https://api.github.com/users/is-it-ayush/received_events","type":"User","site_admin":false,"contributions":8},{"login":"basokant","id":70033855,"node_id":"MDQ6VXNlcjcwMDMzODU1","avatar_url":"https://avatars.githubusercontent.com/u/70033855?v=4","gravatar_id":"","url":"https://api.github.com/users/basokant","html_url":"https://github.com/basokant","followers_url":"https://api.github.com/users/basokant/followers","following_url":"https://api.github.com/users/basokant/following{/other_user}","gists_url":"https://api.github.com/users/basokant/gists{/gist_id}","starred_url":"https://api.github.com/users/basokant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basokant/subscriptions","organizations_url":"https://api.github.com/users/basokant/orgs","repos_url":"https://api.github.com/users/basokant/repos","events_url":"https://api.github.com/users/basokant/events{/privacy}","received_events_url":"https://api.github.com/users/basokant/received_events","type":"User","site_admin":false,"contributions":5},{"login":"emalineg","id":93755103,"node_id":"U_kgDOBZaW3w","avatar_url":"https://avatars.githubusercontent.com/u/93755103?v=4","gravatar_id":"","url":"https://api.github.com/users/emalineg","html_url":"https://github.com/emalineg","followers_url":"https://api.github.com/users/emalineg/followers","following_url":"https://api.github.com/users/emalineg/following{/other_user}","gists_url":"https://api.github.com/users/emalineg/gists{/gist_id}","starred_url":"https://api.github.com/users/emalineg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emalineg/subscriptions","organizations_url":"https://api.github.com/users/emalineg/orgs","repos_url":"https://api.github.com/users/emalineg/repos","events_url":"https://api.github.com/users/emalineg/events{/privacy}","received_events_url":"https://api.github.com/users/emalineg/received_events","type":"User","site_admin":false,"contributions":4},{"login":"FullStackCorm","id":101738478,"node_id":"U_kgDOBhBn7g","avatar_url":"https://avatars.githubusercontent.com/u/101738478?v=4","gravatar_id":"","url":"https://api.github.com/users/FullStackCorm","html_url":"https://github.com/FullStackCorm","followers_url":"https://api.github.com/users/FullStackCorm/followers","following_url":"https://api.github.com/users/FullStackCorm/following{/other_user}","gists_url":"https://api.github.com/users/FullStackCorm/gists{/gist_id}","starred_url":"https://api.github.com/users/FullStackCorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FullStackCorm/subscriptions","organizations_url":"https://api.github.com/users/FullStackCorm/orgs","repos_url":"https://api.github.com/users/FullStackCorm/repos","events_url":"https://api.github.com/users/FullStackCorm/events{/privacy}","received_events_url":"https://api.github.com/users/FullStackCorm/received_events","type":"User","site_admin":false,"contributions":4},{"login":"F-PTS","id":80021800,"node_id":"MDQ6VXNlcjgwMDIxODAw","avatar_url":"https://avatars.githubusercontent.com/u/80021800?v=4","gravatar_id":"","url":"https://api.github.com/users/F-PTS","html_url":"https://github.com/F-PTS","followers_url":"https://api.github.com/users/F-PTS/followers","following_url":"https://api.github.com/users/F-PTS/following{/other_user}","gists_url":"https://api.github.com/users/F-PTS/gists{/gist_id}","starred_url":"https://api.github.com/users/F-PTS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/F-PTS/subscriptions","organizations_url":"https://api.github.com/users/F-PTS/orgs","repos_url":"https://api.github.com/users/F-PTS/repos","events_url":"https://api.github.com/users/F-PTS/events{/privacy}","received_events_url":"https://api.github.com/users/F-PTS/received_events","type":"User","site_admin":false,"contributions":3},{"login":"metal-face","id":101987676,"node_id":"U_kgDOBhQ1XA","avatar_url":"https://avatars.githubusercontent.com/u/101987676?v=4","gravatar_id":"","url":"https://api.github.com/users/metal-face","html_url":"https://github.com/metal-face","followers_url":"https://api.github.com/users/metal-face/followers","following_url":"https://api.github.com/users/metal-face/following{/other_user}","gists_url":"https://api.github.com/users/metal-face/gists{/gist_id}","starred_url":"https://api.github.com/users/metal-face/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metal-face/subscriptions","organizations_url":"https://api.github.com/users/metal-face/orgs","repos_url":"https://api.github.com/users/metal-face/repos","events_url":"https://api.github.com/users/metal-face/events{/privacy}","received_events_url":"https://api.github.com/users/metal-face/received_events","type":"User","site_admin":false,"contributions":3},{"login":"thecornisians","id":84820874,"node_id":"MDQ6VXNlcjg0ODIwODc0","avatar_url":"https://avatars.githubusercontent.com/u/84820874?v=4","gravatar_id":"","url":"https://api.github.com/users/thecornisians","html_url":"https://github.com/thecornisians","followers_url":"https://api.github.com/users/thecornisians/followers","following_url":"https://api.github.com/users/thecornisians/following{/other_user}","gists_url":"https://api.github.com/users/thecornisians/gists{/gist_id}","starred_url":"https://api.github.com/users/thecornisians/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thecornisians/subscriptions","organizations_url":"https://api.github.com/users/thecornisians/orgs","repos_url":"https://api.github.com/users/thecornisians/repos","events_url":"https://api.github.com/users/thecornisians/events{/privacy}","received_events_url":"https://api.github.com/users/thecornisians/received_events","type":"User","site_admin":false,"contributions":1},{"login":"QuiiBz","id":43268759,"node_id":"MDQ6VXNlcjQzMjY4NzU5","avatar_url":"https://avatars.githubusercontent.com/u/43268759?v=4","gravatar_id":"","url":"https://api.github.com/users/QuiiBz","html_url":"https://github.com/QuiiBz","followers_url":"https://api.github.com/users/QuiiBz/followers","following_url":"https://api.github.com/users/QuiiBz/following{/other_user}","gists_url":"https://api.github.com/users/QuiiBz/gists{/gist_id}","starred_url":"https://api.github.com/users/QuiiBz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuiiBz/subscriptions","organizations_url":"https://api.github.com/users/QuiiBz/orgs","repos_url":"https://api.github.com/users/QuiiBz/repos","events_url":"https://api.github.com/users/QuiiBz/events{/privacy}","received_events_url":"https://api.github.com/users/QuiiBz/received_events","type":"User","site_admin":false,"contributions":1}]
\ No newline at end of file
+[
+ {
+ "login": "bautistaaa",
+ "id": 3660667,
+ "node_id": "MDQ6VXNlcjM2NjA2Njc=",
+ "avatar_url": "https://avatars.githubusercontent.com/u/3660667?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/bautistaaa",
+ "html_url": "https://github.com/bautistaaa",
+ "followers_url": "https://api.github.com/users/bautistaaa/followers",
+ "following_url": "https://api.github.com/users/bautistaaa/following{/other_user}",
+ "gists_url": "https://api.github.com/users/bautistaaa/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/bautistaaa/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/bautistaaa/subscriptions",
+ "organizations_url": "https://api.github.com/users/bautistaaa/orgs",
+ "repos_url": "https://api.github.com/users/bautistaaa/repos",
+ "events_url": "https://api.github.com/users/bautistaaa/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/bautistaaa/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 58
+ },
+ {
+ "login": "PickleNik",
+ "id": 31113245,
+ "node_id": "MDQ6VXNlcjMxMTEzMjQ1",
+ "avatar_url": "https://avatars.githubusercontent.com/u/31113245?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/PickleNik",
+ "html_url": "https://github.com/PickleNik",
+ "followers_url": "https://api.github.com/users/PickleNik/followers",
+ "following_url": "https://api.github.com/users/PickleNik/following{/other_user}",
+ "gists_url": "https://api.github.com/users/PickleNik/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/PickleNik/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/PickleNik/subscriptions",
+ "organizations_url": "https://api.github.com/users/PickleNik/orgs",
+ "repos_url": "https://api.github.com/users/PickleNik/repos",
+ "events_url": "https://api.github.com/users/PickleNik/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/PickleNik/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 56
+ },
+ {
+ "login": "Hacksore",
+ "id": 996134,
+ "node_id": "MDQ6VXNlcjk5NjEzNA==",
+ "avatar_url": "https://avatars.githubusercontent.com/u/996134?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/Hacksore",
+ "html_url": "https://github.com/Hacksore",
+ "followers_url": "https://api.github.com/users/Hacksore/followers",
+ "following_url": "https://api.github.com/users/Hacksore/following{/other_user}",
+ "gists_url": "https://api.github.com/users/Hacksore/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/Hacksore/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/Hacksore/subscriptions",
+ "organizations_url": "https://api.github.com/users/Hacksore/orgs",
+ "repos_url": "https://api.github.com/users/Hacksore/repos",
+ "events_url": "https://api.github.com/users/Hacksore/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/Hacksore/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 50
+ },
+ {
+ "login": "jhechtf",
+ "id": 8152471,
+ "node_id": "MDQ6VXNlcjgxNTI0NzE=",
+ "avatar_url": "https://avatars.githubusercontent.com/u/8152471?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/jhechtf",
+ "html_url": "https://github.com/jhechtf",
+ "followers_url": "https://api.github.com/users/jhechtf/followers",
+ "following_url": "https://api.github.com/users/jhechtf/following{/other_user}",
+ "gists_url": "https://api.github.com/users/jhechtf/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/jhechtf/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/jhechtf/subscriptions",
+ "organizations_url": "https://api.github.com/users/jhechtf/orgs",
+ "repos_url": "https://api.github.com/users/jhechtf/repos",
+ "events_url": "https://api.github.com/users/jhechtf/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/jhechtf/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 16
+ },
+ {
+ "login": "ggrandi",
+ "id": 49359646,
+ "node_id": "MDQ6VXNlcjQ5MzU5NjQ2",
+ "avatar_url": "https://avatars.githubusercontent.com/u/49359646?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/ggrandi",
+ "html_url": "https://github.com/ggrandi",
+ "followers_url": "https://api.github.com/users/ggrandi/followers",
+ "following_url": "https://api.github.com/users/ggrandi/following{/other_user}",
+ "gists_url": "https://api.github.com/users/ggrandi/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/ggrandi/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/ggrandi/subscriptions",
+ "organizations_url": "https://api.github.com/users/ggrandi/orgs",
+ "repos_url": "https://api.github.com/users/ggrandi/repos",
+ "events_url": "https://api.github.com/users/ggrandi/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/ggrandi/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 15
+ },
+ {
+ "login": "creativenull",
+ "id": 3767728,
+ "node_id": "MDQ6VXNlcjM3Njc3Mjg=",
+ "avatar_url": "https://avatars.githubusercontent.com/u/3767728?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/creativenull",
+ "html_url": "https://github.com/creativenull",
+ "followers_url": "https://api.github.com/users/creativenull/followers",
+ "following_url": "https://api.github.com/users/creativenull/following{/other_user}",
+ "gists_url": "https://api.github.com/users/creativenull/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/creativenull/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/creativenull/subscriptions",
+ "organizations_url": "https://api.github.com/users/creativenull/orgs",
+ "repos_url": "https://api.github.com/users/creativenull/repos",
+ "events_url": "https://api.github.com/users/creativenull/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/creativenull/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 14
+ },
+ {
+ "login": "ernestoresende",
+ "id": 55156145,
+ "node_id": "MDQ6VXNlcjU1MTU2MTQ1",
+ "avatar_url": "https://avatars.githubusercontent.com/u/55156145?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/ernestoresende",
+ "html_url": "https://github.com/ernestoresende",
+ "followers_url": "https://api.github.com/users/ernestoresende/followers",
+ "following_url": "https://api.github.com/users/ernestoresende/following{/other_user}",
+ "gists_url": "https://api.github.com/users/ernestoresende/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/ernestoresende/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/ernestoresende/subscriptions",
+ "organizations_url": "https://api.github.com/users/ernestoresende/orgs",
+ "repos_url": "https://api.github.com/users/ernestoresende/repos",
+ "events_url": "https://api.github.com/users/ernestoresende/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/ernestoresende/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 9
+ },
+ {
+ "login": "is-it-ayush",
+ "id": 36449128,
+ "node_id": "MDQ6VXNlcjM2NDQ5MTI4",
+ "avatar_url": "https://avatars.githubusercontent.com/u/36449128?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/is-it-ayush",
+ "html_url": "https://github.com/is-it-ayush",
+ "followers_url": "https://api.github.com/users/is-it-ayush/followers",
+ "following_url": "https://api.github.com/users/is-it-ayush/following{/other_user}",
+ "gists_url": "https://api.github.com/users/is-it-ayush/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/is-it-ayush/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/is-it-ayush/subscriptions",
+ "organizations_url": "https://api.github.com/users/is-it-ayush/orgs",
+ "repos_url": "https://api.github.com/users/is-it-ayush/repos",
+ "events_url": "https://api.github.com/users/is-it-ayush/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/is-it-ayush/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 8
+ },
+ {
+ "login": "basokant",
+ "id": 70033855,
+ "node_id": "MDQ6VXNlcjcwMDMzODU1",
+ "avatar_url": "https://avatars.githubusercontent.com/u/70033855?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/basokant",
+ "html_url": "https://github.com/basokant",
+ "followers_url": "https://api.github.com/users/basokant/followers",
+ "following_url": "https://api.github.com/users/basokant/following{/other_user}",
+ "gists_url": "https://api.github.com/users/basokant/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/basokant/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/basokant/subscriptions",
+ "organizations_url": "https://api.github.com/users/basokant/orgs",
+ "repos_url": "https://api.github.com/users/basokant/repos",
+ "events_url": "https://api.github.com/users/basokant/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/basokant/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 5
+ },
+ {
+ "login": "emalineg",
+ "id": 93755103,
+ "node_id": "U_kgDOBZaW3w",
+ "avatar_url": "https://avatars.githubusercontent.com/u/93755103?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/emalineg",
+ "html_url": "https://github.com/emalineg",
+ "followers_url": "https://api.github.com/users/emalineg/followers",
+ "following_url": "https://api.github.com/users/emalineg/following{/other_user}",
+ "gists_url": "https://api.github.com/users/emalineg/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/emalineg/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/emalineg/subscriptions",
+ "organizations_url": "https://api.github.com/users/emalineg/orgs",
+ "repos_url": "https://api.github.com/users/emalineg/repos",
+ "events_url": "https://api.github.com/users/emalineg/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/emalineg/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 4
+ },
+ {
+ "login": "FullStackCorm",
+ "id": 101738478,
+ "node_id": "U_kgDOBhBn7g",
+ "avatar_url": "https://avatars.githubusercontent.com/u/101738478?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/FullStackCorm",
+ "html_url": "https://github.com/FullStackCorm",
+ "followers_url": "https://api.github.com/users/FullStackCorm/followers",
+ "following_url": "https://api.github.com/users/FullStackCorm/following{/other_user}",
+ "gists_url": "https://api.github.com/users/FullStackCorm/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/FullStackCorm/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/FullStackCorm/subscriptions",
+ "organizations_url": "https://api.github.com/users/FullStackCorm/orgs",
+ "repos_url": "https://api.github.com/users/FullStackCorm/repos",
+ "events_url": "https://api.github.com/users/FullStackCorm/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/FullStackCorm/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 4
+ },
+ {
+ "login": "F-PTS",
+ "id": 80021800,
+ "node_id": "MDQ6VXNlcjgwMDIxODAw",
+ "avatar_url": "https://avatars.githubusercontent.com/u/80021800?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/F-PTS",
+ "html_url": "https://github.com/F-PTS",
+ "followers_url": "https://api.github.com/users/F-PTS/followers",
+ "following_url": "https://api.github.com/users/F-PTS/following{/other_user}",
+ "gists_url": "https://api.github.com/users/F-PTS/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/F-PTS/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/F-PTS/subscriptions",
+ "organizations_url": "https://api.github.com/users/F-PTS/orgs",
+ "repos_url": "https://api.github.com/users/F-PTS/repos",
+ "events_url": "https://api.github.com/users/F-PTS/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/F-PTS/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 3
+ },
+ {
+ "login": "metal-face",
+ "id": 101987676,
+ "node_id": "U_kgDOBhQ1XA",
+ "avatar_url": "https://avatars.githubusercontent.com/u/101987676?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/metal-face",
+ "html_url": "https://github.com/metal-face",
+ "followers_url": "https://api.github.com/users/metal-face/followers",
+ "following_url": "https://api.github.com/users/metal-face/following{/other_user}",
+ "gists_url": "https://api.github.com/users/metal-face/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/metal-face/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/metal-face/subscriptions",
+ "organizations_url": "https://api.github.com/users/metal-face/orgs",
+ "repos_url": "https://api.github.com/users/metal-face/repos",
+ "events_url": "https://api.github.com/users/metal-face/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/metal-face/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 3
+ },
+ {
+ "login": "thecornisians",
+ "id": 84820874,
+ "node_id": "MDQ6VXNlcjg0ODIwODc0",
+ "avatar_url": "https://avatars.githubusercontent.com/u/84820874?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/thecornisians",
+ "html_url": "https://github.com/thecornisians",
+ "followers_url": "https://api.github.com/users/thecornisians/followers",
+ "following_url": "https://api.github.com/users/thecornisians/following{/other_user}",
+ "gists_url": "https://api.github.com/users/thecornisians/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/thecornisians/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/thecornisians/subscriptions",
+ "organizations_url": "https://api.github.com/users/thecornisians/orgs",
+ "repos_url": "https://api.github.com/users/thecornisians/repos",
+ "events_url": "https://api.github.com/users/thecornisians/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/thecornisians/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 1
+ },
+ {
+ "login": "QuiiBz",
+ "id": 43268759,
+ "node_id": "MDQ6VXNlcjQzMjY4NzU5",
+ "avatar_url": "https://avatars.githubusercontent.com/u/43268759?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/QuiiBz",
+ "html_url": "https://github.com/QuiiBz",
+ "followers_url": "https://api.github.com/users/QuiiBz/followers",
+ "following_url": "https://api.github.com/users/QuiiBz/following{/other_user}",
+ "gists_url": "https://api.github.com/users/QuiiBz/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/QuiiBz/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/QuiiBz/subscriptions",
+ "organizations_url": "https://api.github.com/users/QuiiBz/orgs",
+ "repos_url": "https://api.github.com/users/QuiiBz/repos",
+ "events_url": "https://api.github.com/users/QuiiBz/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/QuiiBz/received_events",
+ "type": "User",
+ "site_admin": false,
+ "contributions": 1
+ }
+]
diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx
index 1f440997..5c0a6d9f 100644
--- a/src/app/admin/page.tsx
+++ b/src/app/admin/page.tsx
@@ -2,9 +2,10 @@
import { RoleTypes } from '@prisma/client';
import { Lock } from 'lucide-react';
import React from 'react';
-import { getBannedUsers } from '~/components/admin/admin.actions';
import { ChallengeReviews } from '~/components/admin/challenge-reviews';
-import { Reports } from '~/components/admin/reports';
+import { getBannedUsers, getUploadedImages } from '~/components/admin/admin.actions';
+import { ImageUploadReport } from '~/components/admin/images';
+// import Reports2 from '~/components/admin/reports';
import { BannedUsers } from '~/components/admin/users';
import { getInfiniteReports } from '~/components/report/report.action';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '~/components/ui/tabs';
@@ -36,18 +37,21 @@ async function Admin() {
);
}
+// TODO: i think we need nested routing here so we can only load the data when the tab is active
+// 💀 this has to be a job for trash
const View = async () => {
const allBannedUsers = await getBannedUsers();
// This needs done because server functions are dumb and this throws A LOT of errors otherwise.
const firstPage = await getInfiniteReports();
+ const uploadedimages = await getUploadedImages();
return (
<div className="container m-8 flex flex-col space-y-4">
<div className="space-y-2">
<div className="mx-2 flex flex-col">
<p className="text-2xl font-semibold text-black dark:text-white">Moderation</p>
- <p className="max-w-[40ch] text-start text-sm text-neutral-400 dark:text-neutral-600">
- A view of all the reports & users.
+ <p className="text-start text-sm text-neutral-400 dark:text-neutral-600">
+ A view of all the reports & users and all uploaded user images
</p>
</div>
<div className="flex flex-col space-y-2">
@@ -71,10 +75,16 @@ const View = async () => {
>
Users
</TabsTrigger>
+ <TabsTrigger
+ className="rounded-l-2xl rounded-r-lg duration-300 data-[state=active]:bg-border"
+ value="images"
+ >
+ Images
+ </TabsTrigger>
</TabsList>
<TabsContent value="reports">
<React.Suspense fallback={<>Loading...</>}>
- <Reports initialReports={firstPage} />
+ {/* <Reports2 initialReports={firstPage} /> */}
</React.Suspense>
</TabsContent>
<TabsContent value="users">
@@ -83,6 +93,9 @@ const View = async () => {
<TabsContent value="challengeReviews">
<ChallengeReviews />
</TabsContent>
+ <TabsContent value="images">
+ <ImageUploadReport data={uploadedimages} />
+ </TabsContent>
</Tabs>
</div>
</div>
diff --git a/src/app/api/uploadthing/core.ts b/src/app/api/uploadthing/core.ts
new file mode 100644
index 00000000..e23404c9
--- /dev/null
+++ b/src/app/api/uploadthing/core.ts
@@ -0,0 +1,50 @@
+import { createUploadthing, type FileRouter } from 'uploadthing/next';
+import { prisma } from '~/server/db';
+import { getServerSession } from 'next-auth';
+import { authOptions } from '~/server/auth';
+
+const f = createUploadthing();
+
+type ValidFileTypes = 'image' | 'video' | 'audio' | 'blob';
+type FileRouterInput =
+ | ValidFileTypes[]
+ | {
+ // @ts-ignore fixed by typehero god
+ [key: ValidFileTypes]: {
+ maxFileSize?: string;
+ maxFileCount?: number;
+ };
+ };
+
+// control the file sizes for all image types
+const DEFAULT_IMAGE_UPLOAD_PARAMS: FileRouterInput = { maxFileSize: '4MB', maxFiles: 1 };
+
+// FileRouter for your app, can contain multiple FileRoutes
+export const ourFileRouter = {
+ // Define as many FileRoutes as you like, each with a unique routeSlug
+ imageUploader: f({
+ 'image/png': DEFAULT_IMAGE_UPLOAD_PARAMS,
+ 'image/jpeg': DEFAULT_IMAGE_UPLOAD_PARAMS,
+ })
+ // Set permissions and file types for this FileRoute
+ .middleware(async () => {
+ const session = await getServerSession(authOptions);
+
+ // If you throw, the user will not be able to upload
+ if (!session?.user.id) throw new Error('Unauthorized');
+
+ // Whatever is returned here is accessible in onUploadComplete as `metadata`
+ return { userId: session.user.id };
+ })
+ .onUploadComplete(async ({ metadata, file }) => {
+ // save to db
+ await prisma.imageUpload.create({
+ data: {
+ url: file.url,
+ user: { connect: { id: metadata.userId } },
+ },
+ });
+ }),
+} satisfies FileRouter;
+
+export type OurFileRouter = typeof ourFileRouter;
diff --git a/src/app/api/uploadthing/route.ts b/src/app/api/uploadthing/route.ts
new file mode 100644
index 00000000..56cb5164
--- /dev/null
+++ b/src/app/api/uploadthing/route.ts
@@ -0,0 +1,8 @@
+import { createNextRouteHandler } from 'uploadthing/next';
+
+import { ourFileRouter } from './core';
+
+// Export routes for Next App Router
+export const { GET, POST } = createNextRouteHandler({
+ router: ourFileRouter,
+});
diff --git a/src/components/admin/admin.actions.tsx b/src/components/admin/admin.actions.tsx
index 42130881..722c59be 100644
--- a/src/components/admin/admin.actions.tsx
+++ b/src/components/admin/admin.actions.tsx
@@ -238,3 +238,16 @@ export async function getChallenge(id: number) {
},
});
}
+
+
+/**
+ * The function fetches the last 100 uploaded images.
+ */
+export async function getUploadedImages() {
+ return prisma.imageUpload.findMany({
+ take: 100,
+ orderBy: {
+ createdAt: 'asc',
+ }
+ });
+}
diff --git a/src/components/admin/images.tsx b/src/components/admin/images.tsx
new file mode 100644
index 00000000..ee095231
--- /dev/null
+++ b/src/components/admin/images.tsx
@@ -0,0 +1,28 @@
+'use client';
+import Image from 'next/image';
+import type { getUploadedImages } from './admin.actions';
+
+export type ImageUpload = Awaited<ReturnType<typeof getUploadedImages>>;
+
+interface ImageUploadProps {
+ data: ImageUpload;
+}
+
+export const ImageUploadReport = ({ data }: ImageUploadProps) => {
+ return (
+ <div className="flex flex-col gap-2">
+ <div>
+ {data.map((image) => (
+ <Image
+ key={image.id}
+ src={image.url}
+ width="300"
+ height="300"
+ alt={`${image.id}`}
+ className="rounded-lg"
+ />
+ ))}
+ </div>
+ </div>
+ );
+};
diff --git a/src/components/challenge/solutions/post-solution.action.ts b/src/components/challenge/solutions/post-solution.action.ts
index 66c5934c..5280d30d 100644
--- a/src/components/challenge/solutions/post-solution.action.ts
+++ b/src/components/challenge/solutions/post-solution.action.ts
@@ -7,6 +7,7 @@ interface Args {
title: string;
userId: string;
}
+
export async function postSolution({ challengeId, description, title, userId }: Args) {
await prisma.sharedSolution.create({
data: {
diff --git a/src/components/challenge/solutions/solution-editor.tsx b/src/components/challenge/solutions/solution-editor.tsx
index 11846d67..0f8649bc 100644
--- a/src/components/challenge/solutions/solution-editor.tsx
+++ b/src/components/challenge/solutions/solution-editor.tsx
@@ -125,6 +125,7 @@ export function SolutionEditor({ dismiss, challenge }: Props) {
value={field.value}
// non-split-screen by default
onChange={field.onChange}
+ allowImageUpload
/>
)}
/>
diff --git a/src/components/landing/community.tsx b/src/components/landing/community.tsx
index d2bdceda..71641fab 100644
--- a/src/components/landing/community.tsx
+++ b/src/components/landing/community.tsx
@@ -1,7 +1,39 @@
+// eslint-disable-next-line no-restricted-imports
+// import { Octokit } from 'octokit';
+
// eslint-disable-next-line no-restricted-imports
import { contributors } from '../../../public/contributors';
const Community = async function () {
+ // async function getOcto() {
+ // if (!process.env.PROD) {
+ // console.log('You are not in production mode. Mocking data.');
+ // return Array(13).fill({
+ // login: 'PickleNik',
+ // avatar_url: 'https://avatars.githubusercontent.com/u/31113245?v=4',
+ // html_url: 'https://github.com/PickleNik',
+ // });
+ // }
+ // if (!process.env.GITHUB_TOKEN) {
+ // console.error('No GitHub token provided. Please set GITHUB_TOKEN env var.');
+ // return [];
+ // }
+ //
+ // // TODO: hacksore already thinking about making the Graphql api work here
+ // const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
+ // const response = await octokit.request('GET /repos/{owner}/{repo}/contributors', {
+ // owner: 'bautistaa',
+ // repo: 'typehero',
+ // headers: {
+ // 'X-GitHub-Api-Version': '2022-11-28',
+ // },
+ // });
+ // // put all avatar urls in a list
+ // return response.data.map((contributor) => contributor);
+ // }
+ // const avatars = await getOcto();
+ //
+
return (
<section className="container mt-[172px] flex flex-col justify-center md:mb-[172px] lg:flex-row lg:items-center">
<div className="flex flex-1 flex-col items-center pb-36 lg:items-start lg:pb-0">
diff --git a/src/components/ui/rich-markdown-editor.tsx b/src/components/ui/rich-markdown-editor.tsx
index 65e24577..3b7aa6ff 100644
--- a/src/components/ui/rich-markdown-editor.tsx
+++ b/src/components/ui/rich-markdown-editor.tsx
@@ -1,10 +1,12 @@
import { useTheme } from 'next-themes';
-import { useContext, useEffect } from 'react';
+import { useContext, useEffect, useRef, useState } from 'react';
import MDEditor, { commands, type ICommand, EditorContext } from '@uiw/react-md-editor';
+import { useUploadThing } from '~/utils/useUploadthing';
+import { insertText } from '~/utils/domUtils';
+import { toast } from './use-toast';
const PreviewToggle = () => {
- console.warn(commands);
const { preview, dispatch } = useContext(EditorContext);
const click = () => {
dispatch?.({
@@ -56,9 +58,24 @@ interface Props {
value: string;
onChange: (v: string) => void;
dismissPreview?: boolean;
+ /**
+ * This will allow images to be uploaded to CDN
+ *
+ * @default false
+ */
+ allowImageUpload?: boolean;
}
-export function RichMarkdownEditor({ dismissPreview, value, onChange }: Props) {
+export function RichMarkdownEditor({
+ dismissPreview,
+ value,
+ onChange,
+ allowImageUpload = false,
+}: Props) {
+ // @ts-ignore someone fix the types, #GFI
+ const editorRef = useRef<MDEditor>(null);
+ const [isImageUploading, setIsImageUploading] = useState(false);
+
const { theme } = useTheme();
useEffect(() => {
theme == 'dark'
@@ -68,9 +85,63 @@ export function RichMarkdownEditor({ dismissPreview, value, onChange }: Props) {
const extraCommands = [...(dismissPreview ? [] : [codePreview, commands.fullscreen])];
+ const { startUpload } = useUploadThing('imageUploader', {
+ onClientUploadComplete: (res) => {
+ console.log('client upload complete');
+ if (!res) return;
+ // fist file in the array
+ const uploadedFile = res[0];
+
+ // insert string at cursor position by calling on change
+ insertText(
+ `![${uploadedFile?.fileKey}](${uploadedFile?.fileUrl})`,
+ editorRef.current.textarea,
+ );
+
+ setIsImageUploading(false);
+
+ toast({
+ title: 'Image was uploaded successfully',
+ variant: 'success',
+ });
+ },
+ onUploadError: (err) => {
+ console.log(err);
+
+ setIsImageUploading(false);
+
+ toast({
+ title: 'Image failed to upload',
+ variant: 'destructive',
+ });
+ },
+ });
+
+ const handlePasta = async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
+ // only allow image if it's enabled
+ if (!allowImageUpload) return;
+
+ const items = event.clipboardData?.items;
+ if (!items) return;
+ // upload the image to and endpoint
+ for (const item of items) {
+ if (item.kind === 'file') {
+ const blob = item.getAsFile();
+ if (!blob) return;
+
+ // update state for the loading spinner
+ setIsImageUploading(true);
+
+ // upload to the endpoint
+ await startUpload([blob]);
+ }
+ }
+ };
+
return (
<div className="h-full flex-1">
<MDEditor
+ ref={editorRef}
height="100%"
value={value}
// non-split-screen by default
@@ -79,6 +150,8 @@ export function RichMarkdownEditor({ dismissPreview, value, onChange }: Props) {
extraCommands={extraCommands}
// @ts-ignore
onChange={onChange}
+ // @ts-ignore
+ onPaste={(event) => handlePasta(event)}
components={{
toolbar: (command) => {
// toolbar: (command, disabled, executeCommand) => {
@@ -100,6 +173,30 @@ export function RichMarkdownEditor({ dismissPreview, value, onChange }: Props) {
},
}}
/>
+ {isImageUploading && (
+ <div className="absolute bottom-0 flex w-full items-center bg-neutral-100 p-2 pl-3 dark:bg-zinc-700 dark:text-white">
+ <div role="status">
+ <svg
+ aria-hidden="true"
+ className="mr-3 h-5 w-5 animate-spin fill-black text-gray-300 dark:fill-white dark:text-neutral-500"
+ viewBox="0 0 100 101"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
+ fill="currentColor"
+ />
+ <path
+ d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
+ fill="currentFill"
+ />
+ </svg>
+ <span className="sr-only">Loading...</span>
+ </div>
+ <div>Uploading image...</div>
+ </div>
+ )}
</div>
);
}
diff --git a/src/env.mjs b/src/env.mjs
index c981546e..0a9faf23 100644
--- a/src/env.mjs
+++ b/src/env.mjs
@@ -20,6 +20,10 @@ export const env = createEnv({
// VERCEL_URL doesn't include `https` so it cant be validated as a URL
process.env.VERCEL ? z.string().min(1) : z.string().url(),
),
+
+ // upload thing
+ UPLOADTHING_SECRET: z.string(),
+ UPLOADTHING_APP_ID: z.string()
},
/**
@@ -42,6 +46,8 @@ export const env = createEnv({
GITHUB_ID: process.env.GITHUB_ID,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
+ UPLOADTHING_SECRET: process.env.UPLOADTHING_SECRET,
+ UPLOADTHING_APP_ID: process.env.UPLOADTHING_APP_ID,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
diff --git a/src/utils/domUtils.ts b/src/utils/domUtils.ts
new file mode 100644
index 00000000..7d16d0d4
--- /dev/null
+++ b/src/utils/domUtils.ts
@@ -0,0 +1,23 @@
+/**
+ * This will paste the given text into the textarea element
+ */
+export function insertText(newText: string, textarea: HTMLTextAreaElement) {
+ // make sure it's selected when we go to pasta
+ textarea.focus();
+
+ let pasted = true;
+ try {
+ if (!document.execCommand('insertText', false, newText)) {
+ pasted = false;
+ }
+ } catch (e) {
+ console.error('error caught:', e);
+ pasted = false;
+ }
+
+ if (!pasted) {
+ console.error('paste unsuccessful, execCommand not supported');
+ }
+
+ return pasted;
+}
diff --git a/src/utils/useUploadthing.ts b/src/utils/useUploadthing.ts
new file mode 100644
index 00000000..1d671719
--- /dev/null
+++ b/src/utils/useUploadthing.ts
@@ -0,0 +1,5 @@
+import { generateReactHelpers } from '@uploadthing/react/hooks';
+
+import type { OurFileRouter } from '~/app/api/uploadthing/core';
+
+export const { useUploadThing, uploadFiles } = generateReactHelpers < OurFileRouter > ();