-
Notifications
You must be signed in to change notification settings - Fork 0
Complete and prepare social service for deployment #2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,42 @@ | ||
| # Dependencies | ||
| node_modules | ||
| .pnp | ||
| .pnp.js | ||
|
|
||
| # Testing | ||
| coverage | ||
| *.log | ||
|
|
||
| # Next.js | ||
| .next/ | ||
| out/ | ||
| build | ||
| dist | ||
|
|
||
| # Production | ||
| .vercel | ||
| .env*.local | ||
|
|
||
| # Environment files | ||
| .env | ||
| .env.production | ||
|
|
||
| # Debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # Misc | ||
| .turbo | ||
| .cache |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** @type {import('next').NextConfig} */ | ||
| const nextConfig = { | ||
| reactStrictMode: true, | ||
| swcMinify: true, | ||
|
|
||
| // Performance optimizations | ||
| compress: true, | ||
| poweredByHeader: false, | ||
|
|
||
| // Image optimization | ||
| images: { | ||
| domains: ['ipfs.io', 'gateway.pinata.cloud', 'cloudflare-ipfs.com'], | ||
| formats: ['image/avif', 'image/webp'], | ||
| }, | ||
|
|
||
| // Security headers | ||
| async headers() { | ||
| return [ | ||
| { | ||
| source: '/:path*', | ||
| headers: [ | ||
| { | ||
| key: 'X-DNS-Prefetch-Control', | ||
| value: 'on' | ||
| }, | ||
| { | ||
| key: 'Strict-Transport-Security', | ||
| value: 'max-age=63072000; includeSubDomains; preload' | ||
| }, | ||
| { | ||
| key: 'X-Content-Type-Options', | ||
| value: 'nosniff' | ||
| }, | ||
| { | ||
| key: 'X-Frame-Options', | ||
| value: 'SAMEORIGIN' | ||
| }, | ||
| { | ||
| key: 'Referrer-Policy', | ||
| value: 'strict-origin-when-cross-origin' | ||
| }, | ||
| { | ||
| key: 'Permissions-Policy', | ||
| value: 'camera=(), microphone=(), geolocation=()' | ||
|
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The For example, if your application needs camera access: value: 'camera=(self), microphone=(), geolocation=()' |
||
| } | ||
| ], | ||
| }, | ||
| ] | ||
| }, | ||
|
|
||
| // Webpack configuration | ||
| webpack: (config, { isServer }) => { | ||
| // Handle node modules that might need special treatment | ||
| if (!isServer) { | ||
| config.resolve.fallback = { | ||
| ...config.resolve.fallback, | ||
| fs: false, | ||
| net: false, | ||
| tls: false, | ||
| } | ||
|
Comment on lines
+55
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The webpack configuration disables certain node modules ( |
||
| } | ||
| return config | ||
| }, | ||
|
|
||
| // Environment variables that should be available client-side | ||
| env: { | ||
| NEXT_PUBLIC_IPFS_GATEWAY: process.env.IPFS_GATEWAY || 'https://ipfs.io/ipfs/', | ||
| }, | ||
| } | ||
|
|
||
| module.exports = nextConfig | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import { getCurrentUser } from '../../../lib/auth'; | ||
| import { IpfsContentModel } from '../../../db/models/ipfs-content'; | ||
| import { createIpfsContentSchema, validateBody } from '../../../lib/validation'; | ||
|
|
||
| export async function GET(req: NextRequest) { | ||
| try { | ||
|
|
@@ -33,20 +34,23 @@ export async function POST(req: NextRequest) { | |
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
| } | ||
|
|
||
| const data = await req.json(); | ||
| const { cid, contentType, filename, size } = data; | ||
| const body = await req.json(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code does not handle potential exceptions that might be thrown if |
||
|
|
||
| if (!cid) { | ||
| // Validate input | ||
| const validation = validateBody(createIpfsContentSchema, body); | ||
| if (!validation.success) { | ||
| return NextResponse.json( | ||
|
Comment on lines
+41
to
42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling for validation failures could be improved by providing more specific error messages. Currently, the error message returned is generic and derived from the validation function. Suggestion: Modify the
Comment on lines
+41
to
42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling in the POST method could be improved by providing more detailed error messages. Currently, it only returns a generic error message from the validation process. Suggestion: Enhance the error response by including specific details about what part of the input validation failed. This can help the client understand what went wrong and how to fix it. Example: if (!validation.success) {
return NextResponse.json(
{ error: `Validation failed: ${validation.error}` },
{ status: 400 }
);
} |
||
| { error: 'CID is required' }, | ||
| { error: validation.error }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| const { cid, content_type, filename, size } = validation.data; | ||
|
|
||
| const content = await IpfsContentModel.create( | ||
| user.id, | ||
| cid, | ||
| contentType, | ||
| content_type, | ||
| filename, | ||
| size | ||
|
Comment on lines
50
to
55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The creation of IPFS content involves multiple database operations which could potentially slow down the response time, especially under high load. Suggestion: Consider optimizing these operations by using batch inserts or transactions if multiple records are being inserted simultaneously. Additionally, ensure that the database operations are properly indexed to speed up the queries. Example: const content = await IpfsContentModel.create(
user.id,
cid,
content_type,
filename,
size
); |
||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import { getCurrentUser, requireAuth } from '../../../lib/auth'; | ||
| import { ProfileModel } from '../../../db/models/profile'; | ||
| import { updateProfileSchema, validateBody } from '../../../lib/validation'; | ||
|
|
||
| export async function GET(req: NextRequest) { | ||
| try { | ||
|
|
@@ -27,9 +28,19 @@ export async function PUT(req: NextRequest) { | |
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
| } | ||
|
|
||
| const data = await req.json(); | ||
| const profile = await ProfileModel.update(user.id, data); | ||
|
|
||
| const body = await req.json(); | ||
|
|
||
| // Validate input | ||
| const validation = validateBody(updateProfileSchema, body); | ||
| if (!validation.success) { | ||
| return NextResponse.json( | ||
| { error: validation.error }, | ||
| { status: 400 } | ||
|
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message returned when the profile update validation fails is generic and may not provide sufficient information for debugging or user understanding. Consider enhancing the error details by including specific validation failures in the response. This can be achieved by modifying the error object to include more context about what exactly failed during validation. Suggested Change: return NextResponse.json({ error: 'Validation failed', details: validation.errors }, { status: 400 }); |
||
| ); | ||
| } | ||
|
|
||
| const profile = await ProfileModel.update(user.id, validation.data); | ||
|
|
||
| if (!profile) { | ||
| return NextResponse.json( | ||
| { error: 'Profile not found' }, | ||
|
Comment on lines
44
to
46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message 'Profile not found' in the response could be misleading in the context of a profile update operation. It suggests that the profile does not exist, whereas the actual issue might be related to the update operation failing (e.g., due to validation issues or database constraints). Recommendation: Consider providing a more specific error message that clarifies the nature of the error, such as 'Failed to update profile' or 'Profile update not successful'. This will improve the clarity of the API responses and help client-side developers handle errors more effectively.
Comment on lines
+42
to
46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The update operation assumes the profile does not exist if no records are affected, which might not always be the case. This could be misleading if the update fails due to other reasons, such as database connectivity issues. It's recommended to check for the existence of the profile before attempting an update and handle different error scenarios more explicitly. Suggested Change: const existingProfile = await ProfileModel.findByUserId(user.id);
if (!existingProfile) {
return NextResponse.json({ error: 'Profile not found' }, { status: 404 });
}
// Proceed with update |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛑 Security Vulnerability: The
domainsconfiguration is deprecated and creates security risks. UseremotePatternsinstead to properly validate image sources and prevent potential SSRF attacks.