Skip to content

Commit 4d1d0d7

Browse files
committed
Fix createFile endpoint being improperly called
1 parent 186a93f commit 4d1d0d7

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/main/frontend/app/components/file-structure/use-file-tree-context-menu.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ export function getParentItemId(itemId: TreeItemIndex): TreeItemIndex {
4949
return lastSlash > 0 ? str.slice(0, Math.max(0, lastSlash)) : 'root'
5050
}
5151

52-
function ensureXmlExtension(name: string): string {
53-
if (name.includes('.')) return name
54-
return `${name}.xml`
52+
function ensureHasExtension(name: string): string {
53+
const dotIndex = name.lastIndexOf('.')
54+
if (dotIndex < name.length - 1) return name
55+
if (dotIndex === -1) return `${name}.txt`
56+
return `${name.slice(0, Math.max(0, dotIndex))}.txt`
5557
}
5658

5759
function buildNewPath(oldPath: string, newName: string): string {
@@ -114,7 +116,7 @@ export function useFileTreeContextMenu({
114116
title: 'New File',
115117
onSubmit: async (name: string) => {
116118
try {
117-
await createFile(projectName, `${parentPath}/${ensureXmlExtension(name)}`)
119+
await createFile(projectName, `${parentPath}/${ensureHasExtension(name)}`)
118120
await dataProvider.reloadDirectory(parentItemId)
119121
} catch (error) {
120122
showErrorToastFrom('Failed to create file', error)

src/main/frontend/app/services/file-service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface FileDTO {
77
}
88

99
export async function createFile(projectName: string, filePath: string): Promise<void> {
10-
await updateFile(projectName, filePath, '')
10+
await updateFile(projectName, filePath, '\n')
1111
}
1212

1313
export function fetchFile(projectName: string, path: string, signal?: AbortSignal): Promise<FileDTO> {
@@ -17,6 +17,9 @@ export function fetchFile(projectName: string, path: string, signal?: AbortSigna
1717
export function updateFile(projectName: string, path: string, content: string): Promise<FileTreeNode> {
1818
return apiFetch<FileTreeNode>(`${getBaseUrl(projectName)}?path=${encodeURIComponent(path)}`, {
1919
method: 'PUT',
20+
headers: {
21+
'Content-Type': 'text/plain', // override default json content type
22+
},
2023
body: content,
2124
})
2225
}

0 commit comments

Comments
 (0)