dsh-explorer 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,121 @@
1
+ export interface CompactSegment {
2
+ name: string
3
+ path: string
4
+ }
5
+
6
+ export interface FsEntry {
7
+ name: string
8
+ path: string
9
+ isDir: boolean
10
+ hidden: boolean
11
+ isSymlink: boolean
12
+ broken: boolean
13
+ compact?: boolean
14
+ compactName?: string
15
+ compactPath?: string
16
+ compactChain?: CompactSegment[]
17
+ }
18
+
19
+ export interface FsListing {
20
+ path: string
21
+ entries: FsEntry[]
22
+ truncated: boolean
23
+ }
24
+
25
+ export interface GitStatusEntry {
26
+ path: string
27
+ xy: string
28
+ }
29
+
30
+ export interface GitStatusResult {
31
+ isRepo: boolean
32
+ branch?: string
33
+ entries: GitStatusEntry[]
34
+ }
35
+
36
+ export async function fetchTree(sessionId?: string, dir?: string): Promise<FsListing> {
37
+ const params = new URLSearchParams()
38
+ if (sessionId) params.set('sessionId', sessionId)
39
+ if (dir) params.set('dir', dir)
40
+ const res = await fetch(`/dsh-explorer/api/tree?${params.toString()}`)
41
+ if (!res.ok) {
42
+ const text = await res.text().catch(() => '')
43
+ throw new Error(`HTTP ${res.status}: ${text || res.statusText}`)
44
+ }
45
+ const json = await res.json()
46
+ if (!json.ok) throw new Error(json.message || 'Failed to fetch directory')
47
+ return json.listing
48
+ }
49
+
50
+ export async function fetchBatchTree(paths: string[]): Promise<Record<string, FsListing>> {
51
+ const res = await fetch('/dsh-explorer/api/batch-tree', {
52
+ method: 'POST',
53
+ headers: { 'Content-Type': 'application/json' },
54
+ body: JSON.stringify({ paths }),
55
+ })
56
+ const json = await res.json()
57
+ if (!json.ok) throw new Error(json.message || 'Failed to fetch batch trees')
58
+ return json.results
59
+ }
60
+
61
+ export async function fetchGitStatus(sessionId?: string, dir?: string): Promise<GitStatusResult> {
62
+ const params = new URLSearchParams()
63
+ if (sessionId) params.set('sessionId', sessionId)
64
+ if (dir) params.set('dir', dir)
65
+ const res = await fetch(`/dsh-explorer/api/git-status?${params.toString()}`)
66
+ const json = await res.json()
67
+ if (!json.ok) return { isRepo: false, entries: [] }
68
+ return json.git
69
+ }
70
+
71
+ export async function fetchFileContent(path: string): Promise<string> {
72
+ const params = new URLSearchParams({ path })
73
+ const res = await fetch(`/dsh-explorer/api/read-file?${params.toString()}`)
74
+ const json = await res.json()
75
+ if (!json.ok) throw new Error(json.message || 'Failed to read file')
76
+ return json.text
77
+ }
78
+
79
+ export async function apiCreateNewFile(dir: string, name: string): Promise<{ path: string }> {
80
+ const res = await fetch('/dsh-explorer/api/new-file', {
81
+ method: 'POST',
82
+ headers: { 'Content-Type': 'application/json' },
83
+ body: JSON.stringify({ dir, name }),
84
+ })
85
+ const json = await res.json()
86
+ if (!json.ok) throw new Error(json.message || 'Failed to create file')
87
+ return json
88
+ }
89
+
90
+ export async function apiCreateDirectory(dir: string, name: string): Promise<{ path: string }> {
91
+ const res = await fetch('/dsh-explorer/api/mkdir', {
92
+ method: 'POST',
93
+ headers: { 'Content-Type': 'application/json' },
94
+ body: JSON.stringify({ dir, name }),
95
+ })
96
+ const json = await res.json()
97
+ if (!json.ok) throw new Error(json.message || 'Failed to create folder')
98
+ return json
99
+ }
100
+
101
+ export async function apiRename(path: string, newName: string): Promise<{ oldPath: string; newPath: string }> {
102
+ const res = await fetch('/dsh-explorer/api/rename', {
103
+ method: 'POST',
104
+ headers: { 'Content-Type': 'application/json' },
105
+ body: JSON.stringify({ path, newName }),
106
+ })
107
+ const json = await res.json()
108
+ if (!json.ok) throw new Error(json.message || 'Failed to rename')
109
+ return json
110
+ }
111
+
112
+ export async function apiDelete(path: string): Promise<void> {
113
+ const res = await fetch('/dsh-explorer/api/delete', {
114
+ method: 'POST',
115
+ headers: { 'Content-Type': 'application/json' },
116
+ body: JSON.stringify({ path }),
117
+ })
118
+ const json = await res.json()
119
+ if (!json.ok) throw new Error(json.message || 'Failed to delete')
120
+ }
121
+