summaryrefslogtreecommitdiff
path: root/frontend/lib/drive_server.ts
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-08-14 15:34:42 +0100
committerdiogo464 <[email protected]>2025-08-14 15:34:42 +0100
commit6c70d6a60b286f7cfbbde4e428d41c8de2c7e77a (patch)
treec5047911c102f885af3671418477231a4a2351f4 /frontend/lib/drive_server.ts
parenta9f1dbeed109b175fbf78e18a1ede3eba44924f8 (diff)
feat: improve DriveLogEntry types with discriminated unions
- Replace generic DriveLogEntry with action-specific discriminated unions - Add DriveLogEntryCreateFile, CreateDir, Remove, Rename types - Update Drive_log parsing to create correct union types based on action - Add type guards (isCreateFileEntry, isRenameEntry, etc.) for safe access - Enhance History UI to properly display rename operations (old → new) - Change log_id to revision to match Rust OperationHeader structure - Improve type safety and maintainability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'frontend/lib/drive_server.ts')
-rw-r--r--frontend/lib/drive_server.ts66
1 files changed, 58 insertions, 8 deletions
diff --git a/frontend/lib/drive_server.ts b/frontend/lib/drive_server.ts
index 8af0356..e7c88e8 100644
--- a/frontend/lib/drive_server.ts
+++ b/frontend/lib/drive_server.ts
@@ -139,23 +139,73 @@ export async function Drive_log(): Promise<DriveLogEntry[]> {
139 } 139 }
140 140
141 const stdout = result.stdout 141 const stdout = result.stdout
142 const entries = [] 142 const entries: DriveLogEntry[] = []
143 for (const line of stdout.split('\n')) { 143 for (const line of stdout.split('\n')) {
144 if (line.trim() === "") 144 if (line.trim() === "")
145 continue; 145 continue;
146 146
147 const parts = line.split('\t'); 147 const parts = line.split('\t');
148 const timestamp = parseInt(parts[0]); 148 const timestamp = parseInt(parts[0]);
149 const log_id = parseInt(parts[1]); 149 const revision = parseInt(parts[1]);
150 const email = parts[2]; 150 const email = parts[2];
151 const action = parts[3]; 151 const action = parts[3];
152 const path = parts[4];
153 const blob_id = parts[5];
154 const size = parseInt(parts[6]);
155 152
156 entries.push({ 153 // Parse based on action type to create the correct discriminated union
157 timestamp, log_id, email, action, path, blob_id, size 154 switch (action) {
158 } as DriveLogEntry); 155 case "create_file": {
156 const path = parts[4];
157 const blob_id = parts[5];
158 const size = parseInt(parts[6]);
159 entries.push({
160 timestamp,
161 revision,
162 email,
163 action: "create_file",
164 path,
165 blob_id,
166 size
167 });
168 break;
169 }
170 case "create_dir": {
171 const path = parts[4];
172 entries.push({
173 timestamp,
174 revision,
175 email,
176 action: "create_dir",
177 path
178 });
179 break;
180 }
181 case "remove": {
182 const path = parts[4];
183 entries.push({
184 timestamp,
185 revision,
186 email,
187 action: "remove",
188 path
189 });
190 break;
191 }
192 case "rename": {
193 const old_path = parts[4];
194 const new_path = parts[5];
195 entries.push({
196 timestamp,
197 revision,
198 email,
199 action: "rename",
200 old_path,
201 new_path
202 });
203 break;
204 }
205 default:
206 console.warn(`Unknown log action: ${action}`, parts);
207 continue;
208 }
159 } 209 }
160 return entries; 210 return entries;
161} \ No newline at end of file 211} \ No newline at end of file