-
Notifications
You must be signed in to change notification settings - Fork 0
Pr request #527
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
Pr request #527
Changes from all commits
ad0554c
00435f4
5e16ec1
8c0f749
0f17baa
73f8c44
835d4dc
6bab880
65ee31e
39a7dd4
5207dd2
c11782d
2ff04fb
717af8d
560ab30
c312a69
ed53803
e3f5c08
30de397
ded46f5
8698896
1013f38
b2c0c96
1885f4e
53068f6
04bc9e4
b8eb414
d9731ba
1014ede
205a73a
71cb433
a84a628
8566bf1
7dc48fc
c5326eb
d65d968
b374c3c
f2c2390
010a61f
1860956
8db4b75
614d412
fe0b1c8
4afb097
fa45fac
869a128
93975eb
b86b315
f7c2ffd
e7d4e6b
2d43529
69d4c6f
a568e6c
b0a53d3
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,12 +22,14 @@ export const UserSchema = z.object({ | |||||
|
|
||||||
| profile: z.strictObject({ // strict object | ||||||
| bio: z.string().optional(), | ||||||
| joined: z.date(), | ||||||
| joined: z.datesdsd(), | ||||||
| }), | ||||||
| address: z.urlsdsd({ message: "Invalid address URL" }).optional(), | ||||||
|
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. Fix the typo in Zod method name.
Apply this diff to fix the typo: - address: z.urlsdsd({ message: "Invalid address URL" }).optional(),
+ address: z.url({ message: "Invalid address URL" }).optional(),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| format: z.strinsdsg() | ||||||
|
Comment on lines
+25
to
+28
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. Restore valid Zod primitives.
- joined: z.datesdsd(),
+ joined: z.date(),
}),
- address: z.urlsdsd({ message: "Invalid address URL" }).optional(),
- format: z.strinsdsg()
+ address: z.url({ message: "Invalid address URL" }).optional(),
+ format: z.string()🤖 Prompt for AI AgentsThere 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. Fix the typo in Zod method name.
Apply this diff to fix the typo: - format: z.strinsdsg()
+ format: z.string()📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| }) | ||||||
|
|
||||||
| // ✅ TypeScript inference | ||||||
| export type User = z.infer<typeof UserSchema> | ||||||
| export type User = z.infer<typeof UserSchemassss>ssssss | ||||||
|
|
||||||
| // ✅ Safe parsing with v4 error helpers | ||||||
| export function parseUser(input: unknown): User { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||
| import 'dotenv/config'; | ||||||||||||||||||||||||||||
| import express from 'express'; | ||||||||||||||||||||||||||||
| import cors from 'cors'; | ||||||||||||||||||||||||||||
| import multer from 'multer'; | ||||||||||||||||||||||||||||
| import fs from 'fs/promises'; | ||||||||||||||||||||||||||||
| import path from 'path'; | ||||||||||||||||||||||||||||
| import { fileURLToPath } from 'url'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import { analyzeTrack } from './realtime.js'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const app = express(); | ||||||||||||||||||||||||||||
| const upload = multer({ dest: 'uploads/', limits: { fileSize: 10 * 1024 * 1024 } }); | ||||||||||||||||||||||||||||
|
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. Add file type validation for uploads. The multer configuration lacks file type validation, allowing any file to be uploaded. This poses a security risk if malicious files are uploaded and processed. Consider adding a -const upload = multer({ dest: 'uploads/', limits: { fileSize: 10 * 1024 * 1024 } });
+const upload = multer({
+ dest: 'uploads/',
+ limits: { fileSize: 10 * 1024 * 1024 },
+ fileFilter: (_req, file, cb) => {
+ const allowedMimeTypes = ['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/mp4'];
+ if (allowedMimeTypes.includes(file.mimetype)) {
+ cb(null, true);
+ } else {
+ cb(new Error('Invalid file type. Only audio files are allowed.'));
+ }
+ }
+});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const __filename = fileURLToPath(import.meta.url); | ||||||||||||||||||||||||||||
| const __dirname = path.dirname(__filename); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const PORT = process.env.PORT || 3001; | ||||||||||||||||||||||||||||
| const CLIENT_ORIGIN = process.env.CLIENT_ORIGIN || 'http://localhost:5173'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| await fs.mkdir('uploads', { recursive: true }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| app.use(cors({ origin: CLIENT_ORIGIN })); | ||||||||||||||||||||||||||||
| app.use(express.json()); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| app.get('/health', (_req, res) => { | ||||||||||||||||||||||||||||
| res.json({ status: 'ok' }); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| app.post('/api/analyze', upload.single('track'), async (req, res) => { | ||||||||||||||||||||||||||||
| if (!req.file) { | ||||||||||||||||||||||||||||
| return res.status(400).json({ error: 'Missing track upload' }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const task = req.body.task || 'analysis'; | ||||||||||||||||||||||||||||
| const lyricContext = req.body.lyricContext || ''; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const filePath = path.join(__dirname, '..', req.file.path); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||
| const audioBuffer = await fs.readFile(filePath); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const result = await analyzeTrack({ | ||||||||||||||||||||||||||||
| task, | ||||||||||||||||||||||||||||
| audioBuffer, | ||||||||||||||||||||||||||||
| lyricContext, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| res.json(result); | ||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||
| console.error('Realtime analysis failed', error); | ||||||||||||||||||||||||||||
| res.status(500).json({ | ||||||||||||||||||||||||||||
| error: 'Failed to process track with OpenAI Realtime API', | ||||||||||||||||||||||||||||
| details: error?.message ?? 'Unknown error', | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||
| await fs.unlink(filePath).catch(() => {}); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| app.listen(PORT, () => { | ||||||||||||||||||||||||||||
| console.log(`Server listening on http://localhost:${PORT}`); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| Hi | ||
|
|
||
|
|
||
| asd |
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.
Fix the typo in Zod method name.
z.datesdsd()is not a valid Zod method and will cause a runtime error. This should bez.date().Apply this diff to fix the typo:
📝 Committable suggestion
🤖 Prompt for AI Agents