Revert filesystem as it makes more sense to do over socket
This commit is contained in:
@@ -6,11 +6,8 @@
|
|||||||
import { modals } from 'svelte-modals'
|
import { modals } from 'svelte-modals'
|
||||||
import NewFolderDialog from './NewFolderDialog.svelte'
|
import NewFolderDialog from './NewFolderDialog.svelte'
|
||||||
import NewFileDialog from './NewFileDialog.svelte'
|
import NewFileDialog from './NewFileDialog.svelte'
|
||||||
import { api } from '$lib/api'
|
|
||||||
import type { Response, FileEntry } from '$lib/platform_shared/api'
|
|
||||||
|
|
||||||
let currentPath = $state('/')
|
let currentPath = $state('/')
|
||||||
let fileTree = $state<FileEntry | null>(null)
|
|
||||||
let files = $state<Array<{ name: string; size: number }>>([])
|
let files = $state<Array<{ name: string; size: number }>>([])
|
||||||
let directories = $state<Array<{ name: string }>>([])
|
let directories = $state<Array<{ name: string }>>([])
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
@@ -25,47 +22,17 @@
|
|||||||
let downloadProgress = $state<TransferProgress | null>(null)
|
let downloadProgress = $state<TransferProgress | null>(null)
|
||||||
let uploadInputRef: HTMLInputElement
|
let uploadInputRef: HTMLInputElement
|
||||||
|
|
||||||
function getNodeAtPath(root: FileEntry, path: string): FileEntry | null {
|
async function loadDirectory(path: string = currentPath) {
|
||||||
if (path === '/') return root
|
|
||||||
const parts = path.split('/').filter(Boolean)
|
|
||||||
let current = root
|
|
||||||
for (const part of parts) {
|
|
||||||
const child = current.children?.find((c) => c.name === part)
|
|
||||||
if (!child) return null
|
|
||||||
current = child
|
|
||||||
}
|
|
||||||
return current
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateFilesAndDirectories(node: FileEntry | null) {
|
|
||||||
if (!node || !node.children) {
|
|
||||||
files = []
|
|
||||||
directories = []
|
|
||||||
return
|
|
||||||
}
|
|
||||||
files = node.children
|
|
||||||
.filter((c) => !c.isDirectory)
|
|
||||||
.map((c) => ({ name: c.name, size: c.size }))
|
|
||||||
directories = node.children
|
|
||||||
.filter((c) => c.isDirectory)
|
|
||||||
.map((c) => ({ name: c.name }))
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadFileTree() {
|
|
||||||
loading = true
|
loading = true
|
||||||
error = ''
|
error = ''
|
||||||
try {
|
try {
|
||||||
const result = await api.get<Response>('/api/files')
|
const result = await fileSystemClient.listDirectory(path)
|
||||||
if (result.isOk()) {
|
if (result.success) {
|
||||||
const response = result.inner
|
files = result.files
|
||||||
if (response.fileList && response.fileList.entries.length > 0) {
|
directories = result.directories
|
||||||
fileTree = response.fileList.entries[0]
|
currentPath = path
|
||||||
updateFilesAndDirectories(getNodeAtPath(fileTree, currentPath))
|
|
||||||
} else {
|
|
||||||
error = response.errorMessage || 'Failed to load file tree'
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
error = 'Failed to fetch file list'
|
error = result.error || 'Failed to load directory'
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e instanceof Error ? e.message : 'Unknown error'
|
error = e instanceof Error ? e.message : 'Unknown error'
|
||||||
@@ -74,15 +41,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadDirectory(path: string = currentPath) {
|
|
||||||
currentPath = path
|
|
||||||
if (fileTree) {
|
|
||||||
updateFilesAndDirectories(getNodeAtPath(fileTree, path))
|
|
||||||
} else {
|
|
||||||
await loadFileTree()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function navigateTo(dirName: string) {
|
async function navigateTo(dirName: string) {
|
||||||
const newPath = currentPath === '/' ? `/${dirName}` : `${currentPath}/${dirName}`
|
const newPath = currentPath === '/' ? `/${dirName}` : `${currentPath}/${dirName}`
|
||||||
await loadDirectory(newPath)
|
await loadDirectory(newPath)
|
||||||
@@ -136,7 +94,7 @@
|
|||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
isEditing = false
|
isEditing = false
|
||||||
await loadFileTree() // Refresh to update file sizes
|
await loadDirectory() // Refresh to update file sizes
|
||||||
} else {
|
} else {
|
||||||
error = result.error || 'Failed to save file'
|
error = result.error || 'Failed to save file'
|
||||||
}
|
}
|
||||||
@@ -167,7 +125,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
await loadFileTree()
|
await loadDirectory()
|
||||||
} else {
|
} else {
|
||||||
error = result.error || 'Upload failed'
|
error = result.error || 'Upload failed'
|
||||||
}
|
}
|
||||||
@@ -215,7 +173,7 @@
|
|||||||
selectedFile = ''
|
selectedFile = ''
|
||||||
fileContent = ''
|
fileContent = ''
|
||||||
}
|
}
|
||||||
await loadFileTree()
|
await loadDirectory()
|
||||||
} else {
|
} else {
|
||||||
error = result.error || 'Delete failed'
|
error = result.error || 'Delete failed'
|
||||||
}
|
}
|
||||||
@@ -233,7 +191,7 @@
|
|||||||
try {
|
try {
|
||||||
const result = await fileSystemClient.createDirectory(path)
|
const result = await fileSystemClient.createDirectory(path)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
await loadFileTree()
|
await loadDirectory()
|
||||||
} else {
|
} else {
|
||||||
error = result.error || 'Failed to create directory'
|
error = result.error || 'Failed to create directory'
|
||||||
}
|
}
|
||||||
@@ -254,7 +212,7 @@
|
|||||||
|
|
||||||
const result = await fileSystemClient.uploadFile(path, data)
|
const result = await fileSystemClient.uploadFile(path, data)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
await loadFileTree()
|
await loadDirectory()
|
||||||
await loadFileContent(fileName)
|
await loadFileContent(fileName)
|
||||||
} else {
|
} else {
|
||||||
error = result.error || 'Failed to create file'
|
error = result.error || 'Failed to create file'
|
||||||
@@ -284,9 +242,9 @@
|
|||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load initial file tree
|
// Load initial directory
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
loadFileTree()
|
loadDirectory('/')
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user