diff options
| author | diogo464 <[email protected]> | 2025-08-11 16:59:12 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-11 16:59:12 +0100 |
| commit | 6b71b7f2365001bf0d474cca1625c82e310abf63 (patch) | |
| tree | 1a867a85ead3cdbf9c6cd4f49b5a6f3e8540cce8 /frontend/lib | |
| parent | febcfc499657c8d17092611c647598eeee2b9653 (diff) | |
Add Drive_log function and /api/log endpoint
- Added DriveLogEntry type for log entries with timestamp, log_id, email, action, path, blob_id, size
- Implemented Drive_log function that executes fctdrive log and parses tab-separated output
- Created /api/log GET endpoint that returns JSON array of all log entries
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'frontend/lib')
| -rw-r--r-- | frontend/lib/drive_server.ts | 34 | ||||
| -rw-r--r-- | frontend/lib/drive_types.ts | 10 |
2 files changed, 43 insertions, 1 deletions
diff --git a/frontend/lib/drive_server.ts b/frontend/lib/drive_server.ts index 6531641..81e9321 100644 --- a/frontend/lib/drive_server.ts +++ b/frontend/lib/drive_server.ts | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | import { spawnSync } from 'child_process' | 1 | import { spawnSync } from 'child_process' |
| 2 | import { DriveLsEntry, DriveTreeNode, DriveTreeResponse } from './drive_types' | 2 | import { DriveLsEntry, DriveTreeNode, DriveTreeResponse, DriveLogEntry } from './drive_types' |
| 3 | import { Drive_split_path, Drive_basename } from './drive_shared' | 3 | import { Drive_split_path, Drive_basename } from './drive_shared' |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| @@ -172,4 +172,36 @@ export async function Drive_tree(): Promise<DriveTreeResponse> { | |||
| 172 | }; | 172 | }; |
| 173 | 173 | ||
| 174 | return { root: calculateSizesAndSort(rootNodes) }; | 174 | return { root: calculateSizesAndSort(rootNodes) }; |
| 175 | } | ||
| 176 | |||
| 177 | /// returns the log entries from the drive | ||
| 178 | export async function Drive_log(): Promise<DriveLogEntry[]> { | ||
| 179 | const result = spawnSync('fctdrive', ['log'], { encoding: 'utf-8', maxBuffer: 50 * 1024 * 1024 }) | ||
| 180 | if (result.error) { | ||
| 181 | throw new Error(`Failed to execute fctdrive: ${result.error.message}`) | ||
| 182 | } | ||
| 183 | if (result.status !== 0) { | ||
| 184 | throw new Error(`fctdrive exited with code ${result.status}: ${result.stderr}`) | ||
| 185 | } | ||
| 186 | |||
| 187 | const stdout = result.stdout | ||
| 188 | const entries = [] | ||
| 189 | for (const line of stdout.split('\n')) { | ||
| 190 | if (line.trim() === "") | ||
| 191 | continue; | ||
| 192 | |||
| 193 | const parts = line.split('\t'); | ||
| 194 | const timestamp = parseInt(parts[0]); | ||
| 195 | const log_id = parseInt(parts[1]); | ||
| 196 | const email = parts[2]; | ||
| 197 | const action = parts[3]; | ||
| 198 | const path = parts[4]; | ||
| 199 | const blob_id = parts[5]; | ||
| 200 | const size = parseInt(parts[6]); | ||
| 201 | |||
| 202 | entries.push({ | ||
| 203 | timestamp, log_id, email, action, path, blob_id, size | ||
| 204 | } as DriveLogEntry); | ||
| 205 | } | ||
| 206 | return entries; | ||
| 175 | } \ No newline at end of file | 207 | } \ No newline at end of file |
diff --git a/frontend/lib/drive_types.ts b/frontend/lib/drive_types.ts index ced8271..9220d82 100644 --- a/frontend/lib/drive_types.ts +++ b/frontend/lib/drive_types.ts | |||
| @@ -21,3 +21,13 @@ export interface DriveTreeNode { | |||
| 21 | export interface DriveTreeResponse { | 21 | export interface DriveTreeResponse { |
| 22 | root: DriveTreeNode[] | 22 | root: DriveTreeNode[] |
| 23 | } | 23 | } |
| 24 | |||
| 25 | export interface DriveLogEntry { | ||
| 26 | timestamp: number | ||
| 27 | log_id: number | ||
| 28 | email: string | ||
| 29 | action: string | ||
| 30 | path: string | ||
| 31 | blob_id: string | ||
| 32 | size: number | ||
| 33 | } | ||
