Skip to content

Commit

Permalink
fix: Enable large file saving and no content files
Browse files Browse the repository at this point in the history
  • Loading branch information
Carson-Shaar committed Nov 25, 2024
1 parent fe0f54e commit 932b405
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions zt_backend/models/api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class DeleteItemRequest(BaseModel):
class FileWrite(BaseModel):
path: str
content: str
chunk_index: int
total_chunks: int

class DownloadRequest(BaseModel):
path: str
Expand Down
4 changes: 3 additions & 1 deletion zt_backend/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,9 @@ def write_file(file_data: request.FileWrite):

# Write the file
try:
file_path.write_text(file_data.content, encoding='utf-8')
mode = "a" if file_data.chunk_index > 0 else "w"
with open(file_path, mode, encoding="utf-8") as f:
f.write(file_data.content)
except IOError as e:
raise HTTPException(status_code=500, detail=f"Failed to write file: {str(e)}")

Expand Down
21 changes: 15 additions & 6 deletions zt_frontend/src/components/FileEditorDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</v-card-actions>
</template>
<!-- Editor State -->
<template v-else-if="fileContent">
<template v-else>
<v-card-title class="d-flex justify-space-between align-center pa-4 bg-dark">
<div class="d-flex align-center">
<v-icon size="small" class="mr-2" color="grey-lighten-2">mdi-file-document-outline</v-icon>
Expand All @@ -83,7 +83,7 @@
<v-divider vertical class="mx-2" color="grey-darken-3" />
<span class="text-caption text-grey-lighten-2">{{ getFileSize }}</span>
</v-card-subtitle>
<v-card-text class="pa-0 bg-dark">
<v-card-text class="pa-0 bg-dark" style="overflow-y: auto;">
<div class="editor-container">
<codemirror
v-model="fileContent"
Expand Down Expand Up @@ -243,11 +243,19 @@ setup(props, { emit }) {
const saveChanges = async () => {
saving.value = true
const chunkSize = 1024 * 512;
const totalChunks = Math.ceil(fileContent.value.length / chunkSize);
try {
await axios.post(`${import.meta.env.VITE_BACKEND_URL}api/write_file`, {
path: props.filePath,
content: fileContent.value
})
for (let i = 0; i < totalChunks; i++) {
const chunk = fileContent.value.slice(i * chunkSize, (i + 1) * chunkSize);
await axios.post(`${import.meta.env.VITE_BACKEND_URL}api/write_file`, {
path: props.filePath,
content: chunk,
chunk_index: i,
total_chunks: totalChunks,
});
}
emit('file-saved')
closeDialog()
}catch (err: any) {
Expand Down Expand Up @@ -326,6 +334,7 @@ height: 100%;
:deep(.cm-scroller) {
font-family: 'Fira Code', monospace;
overflow: auto;
}
/* Dark theme overrides */
Expand Down

0 comments on commit 932b405

Please sign in to comment.