-
Notifications
You must be signed in to change notification settings - Fork 0
feat: UI polish batch 2 — log search, teamless SSO block, multi-select mappings, backup fixes #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
56644b1
feat: add client-side search to pipeline and node log viewers
TerrifiedBug f33737d
feat: show full-page block for SSO users not assigned to a team
TerrifiedBug 708e518
feat: multi-select team mapping and team count pills in settings
TerrifiedBug 5d1d7de
fix: validate backup files, add error banner, and download button
TerrifiedBug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { auth } from "@/auth"; | ||
| import { prisma } from "@/lib/prisma"; | ||
| import fs from "fs/promises"; | ||
| import path from "path"; | ||
| import { createReadStream } from "fs"; | ||
| import { Readable } from "stream"; | ||
|
|
||
| const BACKUP_DIR = process.env.VF_BACKUP_DIR ?? "/backups"; | ||
|
|
||
| function sanitizeFilename(filename: string): string { | ||
| const base = path.basename(filename); | ||
| if (!/^[\w.\-]+$/.test(base)) { | ||
| throw new Error("Invalid filename"); | ||
| } | ||
| return base; | ||
| } | ||
|
|
||
| export async function GET( | ||
| _request: Request, | ||
| { params }: { params: Promise<{ filename: string }> } | ||
| ) { | ||
| const session = await auth(); | ||
| if (!session?.user?.id) { | ||
| return new Response("Unauthorized", { status: 401 }); | ||
| } | ||
|
|
||
| const user = await prisma.user.findUnique({ | ||
| where: { id: session.user.id }, | ||
| select: { isSuperAdmin: true }, | ||
| }); | ||
|
|
||
| if (!user?.isSuperAdmin) { | ||
| return new Response("Forbidden", { status: 403 }); | ||
| } | ||
|
|
||
| const { filename } = await params; | ||
| let safe: string; | ||
| try { | ||
| safe = sanitizeFilename(filename); | ||
| } catch { | ||
| return new Response("Invalid filename", { status: 400 }); | ||
| } | ||
|
|
||
| if (!safe.endsWith(".dump")) { | ||
| return new Response("Invalid backup filename", { status: 400 }); | ||
| } | ||
|
|
||
| const filePath = path.join(BACKUP_DIR, safe); | ||
|
|
||
| try { | ||
| await fs.access(filePath); | ||
| } catch { | ||
| return new Response("Backup not found", { status: 404 }); | ||
| } | ||
|
|
||
| const stat = await fs.stat(filePath); | ||
| const stream = createReadStream(filePath); | ||
| const webStream = Readable.toWeb(stream) as ReadableStream; | ||
|
|
||
| return new Response(webStream, { | ||
| headers: { | ||
| "Content-Type": "application/octet-stream", | ||
| "Content-Disposition": `attachment; filename="${safe}"`, | ||
| "Content-Length": stat.size.toString(), | ||
| }, | ||
| }); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
fs.statandcreateReadStreamunprotected afterfs.accesscheckThe
fs.accesscheck at line 51 is wrapped in a try/catch that returns a clean 404, butfs.statandcreateReadStream(lines 56–58) are outside any error handler. If the.dumpfile is removed between thefs.accesscheck and the subsequent calls (e.g., during a concurrent backup cleanup),fs.statwill throw an unhandled exception and Next.js will return a 500 error instead of a graceful 404.The simpler fix is to drop the redundant
fs.accesscheck and usefs.statdirectly inside the try/catch:Prompt To Fix With AI