summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-08-11 16:59:12 +0100
committerdiogo464 <[email protected]>2025-08-11 16:59:12 +0100
commit6b71b7f2365001bf0d474cca1625c82e310abf63 (patch)
tree1a867a85ead3cdbf9c6cd4f49b5a6f3e8540cce8
parentfebcfc499657c8d17092611c647598eeee2b9653 (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]>
-rw-r--r--frontend/app/api/log/route.ts13
-rw-r--r--frontend/lib/drive_server.ts34
-rw-r--r--frontend/lib/drive_types.ts10
3 files changed, 56 insertions, 1 deletions
diff --git a/frontend/app/api/log/route.ts b/frontend/app/api/log/route.ts
new file mode 100644
index 0000000..a316ce7
--- /dev/null
+++ b/frontend/app/api/log/route.ts
@@ -0,0 +1,13 @@
1import { NextResponse } from 'next/server'
2import { Drive_log } from '@/lib/drive_server'
3
4export async function GET() {
5 try {
6 const logEntries = await Drive_log()
7
8 return NextResponse.json(logEntries)
9 } catch (error) {
10 console.error('Error getting log entries:', error)
11 throw error
12 }
13} \ No newline at end of file
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 @@
1import { spawnSync } from 'child_process' 1import { spawnSync } from 'child_process'
2import { DriveLsEntry, DriveTreeNode, DriveTreeResponse } from './drive_types' 2import { DriveLsEntry, DriveTreeNode, DriveTreeResponse, DriveLogEntry } from './drive_types'
3import { Drive_split_path, Drive_basename } from './drive_shared' 3import { 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
178export 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 {
21export interface DriveTreeResponse { 21export interface DriveTreeResponse {
22 root: DriveTreeNode[] 22 root: DriveTreeNode[]
23} 23}
24
25export 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}