Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(observability): extend audit log, PostHog, and storage metering coverage#5269
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
77fc13122b5851a48954bb40d531821950b7b3e5dc0f0b3f04e2fdaed4efef7c0861cbbfc300cc97c3b0c2f3e778701102a90d3d07c94ed961b976197f5039c35a8e21eea82528b50dfa7e89696fe71df82718eb6e440d93e43e8a59f1f4440dba9126f0995f8c01ce409676e59f1d11e4cc7da914e2eeFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import { AuditAction, AuditResourceType, recordAudit } from '@sim/audit' | ||
| import { createLogger } from '@sim/logger' | ||
| import { type NextRequest, NextResponse } from 'next/server' | ||
| import { fileDownloadContract } from '@/lib/api/contracts/storage-transfer' | ||
| import { getValidationErrorMessage, parseRequest } from '@/lib/api/server' | ||
| import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid' | ||
| import { withRouteHandler } from '@/lib/core/utils/with-route-handler' | ||
| import { captureServerEvent } from '@/lib/posthog/server' | ||
| import { hasCloudStorage } from '@/lib/uploads/core/storage-service' | ||
| import { inferContextFromKey } from '@/lib/uploads/utils/file-utils' | ||
| import { verifyFileAccess } from '@/app/api/files/authorization' | ||
| @@ -80,10 +82,26 @@ export const POST = withRouteHandler(async (request: NextRequest) => { | ||
| logger.info(`Generated download URL for ${storageContext} file: ${key}`) | ||
| const downloadName = name || key.split('/').pop() || 'download' | ||
| recordAudit({ | ||
| workspaceId: null, | ||
| actorId: userId, | ||
| action: AuditAction.FILE_DOWNLOADED, | ||
| resourceType: AuditResourceType.FILE, | ||
| resourceName: downloadName, | ||
| description: `Downloaded file "${downloadName}"`, | ||
| metadata: { key, fileName: downloadName, context: storageContext }, | ||
| request, | ||
| }) | ||
| captureServerEvent(userId, 'file_downloaded', { | ||
| is_bulk: false, | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| file_count: 1, | ||
| }) | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return NextResponse.json({ | ||
| downloadUrl, | ||
| expiresIn: null, | ||
| fileName: name || key.split('/').pop() || 'download', | ||
| fileName: downloadName, | ||
| }) | ||
| } catch (error) { | ||
| logger.error('Error in file download endpoint:', error) | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.