@@ -6,21 +6,22 @@ var url_base = window.location;
6
6
var current_path ;
7
7
var editable = undefined ;
8
8
9
+ function compareValues ( a , b ) {
10
+ if ( a . directory == b . directory && a . name . toLowerCase ( ) === b . name . toLowerCase ( ) ) {
11
+ return 0 ;
12
+ } else if ( a . directory != b . directory ) {
13
+ return a . directory < b . directory ? 1 : - 1 ;
14
+ } else {
15
+ return a . name . toLowerCase ( ) < b . name . toLowerCase ( ) ? - 1 : 1 ;
16
+ }
17
+ }
18
+
9
19
function set_upload_enabled ( enabled ) {
10
20
files . disabled = ! enabled ;
11
21
dirs . disabled = ! enabled ;
12
22
}
13
23
14
24
async function refresh_list ( ) {
15
-
16
- function compareValues ( a , b ) {
17
- if ( a . directory == b . directory && a . name . toLowerCase ( ) === b . name . toLowerCase ( ) ) {
18
- return 0 ;
19
- } else {
20
- return a . directory . toString ( ) . substring ( 3 , 4 ) + a . name . toLowerCase ( ) < b . directory . toString ( ) . substring ( 3 , 4 ) + b . name . toLowerCase ( ) ? - 1 : 1 ;
21
- }
22
- }
23
-
24
25
current_path = window . location . hash . substr ( 1 ) ;
25
26
if ( current_path == "" ) {
26
27
current_path = "/" ;
@@ -58,7 +59,7 @@ async function refresh_list() {
58
59
}
59
60
}
60
61
61
- if ( window . location . path != "/fs /" ) {
62
+ if ( current_path != "/" ) {
62
63
var clone = template . content . cloneNode ( true ) ;
63
64
var td = clone . querySelectorAll ( "td" ) ;
64
65
td [ 0 ] . textContent = "📁" ;
@@ -68,6 +69,8 @@ async function refresh_list() {
68
69
path . textContent = ".." ;
69
70
// Remove the delete button
70
71
td [ 4 ] . replaceChildren ( ) ;
72
+ td [ 5 ] . replaceChildren ( ) ;
73
+ td [ 6 ] . replaceChildren ( ) ;
71
74
new_children . push ( clone ) ;
72
75
}
73
76
@@ -88,31 +91,46 @@ async function refresh_list() {
88
91
file_path = api_url ;
89
92
}
90
93
94
+ var text_file = false ;
91
95
if ( f . directory ) {
92
96
icon = "📁" ;
93
97
} else if ( f . name . endsWith ( ".txt" ) ||
98
+ f . name . endsWith ( ".env" ) ||
94
99
f . name . endsWith ( ".py" ) ||
95
100
f . name . endsWith ( ".js" ) ||
96
101
f . name . endsWith ( ".json" ) ) {
97
102
icon = "📄" ;
103
+ text_file = true ;
98
104
} else if ( f . name . endsWith ( ".html" ) ) {
99
105
icon = "🌐" ;
106
+ text_file = true ;
100
107
}
101
108
td [ 0 ] . textContent = icon ;
102
109
td [ 1 ] . textContent = f . file_size ;
103
- var path = clone . querySelector ( "a" ) ;
110
+ var path = clone . querySelector ( "a.path " ) ;
104
111
path . href = file_path ;
105
112
path . textContent = f . name ;
106
- td [ 3 ] . textContent = ( new Date ( f . modified_ns / 1000000 ) ) . toLocaleString ( ) ;
113
+ let modtime = clone . querySelector ( "td.modtime" ) ;
114
+ modtime . textContent = ( new Date ( f . modified_ns / 1000000 ) ) . toLocaleString ( ) ;
107
115
var delete_button = clone . querySelector ( "button.delete" ) ;
108
116
delete_button . value = api_url ;
109
117
delete_button . disabled = ! editable ;
110
118
delete_button . onclick = del ;
111
119
112
- if ( editable && ! f . directory ) {
120
+
121
+ var rename_button = clone . querySelector ( "button.rename" ) ;
122
+ rename_button . value = api_url ;
123
+ rename_button . disabled = ! editable ;
124
+ rename_button . onclick = rename ;
125
+
126
+ let edit_link = clone . querySelector ( ".edit_link" ) ;
127
+ if ( text_file && editable && ! f . directory ) {
113
128
edit_url = new URL ( edit_url , url_base ) ;
114
- let edit_link = clone . querySelector ( ".edit_link" ) ;
115
129
edit_link . href = edit_url
130
+ } else if ( f . directory ) {
131
+ edit_link . style = "display: none;" ;
132
+ } else {
133
+ edit_link . querySelector ( "button" ) . disabled = true ;
116
134
}
117
135
118
136
new_children . push ( clone ) ;
@@ -214,6 +232,26 @@ async function del(e) {
214
232
}
215
233
}
216
234
235
+ async function rename ( e ) {
236
+ let fn = new URL ( e . target . value ) ;
237
+ var new_fn = prompt ( "Rename to " , fn . pathname . substr ( 3 ) ) ;
238
+ if ( new_fn === null ) {
239
+ return ;
240
+ }
241
+ let new_uri = new URL ( "/fs" + new_fn , fn ) ;
242
+ const response = await fetch ( e . target . value ,
243
+ {
244
+ method : "MOVE" ,
245
+ headers : {
246
+ 'X-Destination' : new_uri . pathname ,
247
+ } ,
248
+ }
249
+ )
250
+ if ( response . ok ) {
251
+ refresh_list ( ) ;
252
+ }
253
+ }
254
+
217
255
find_devices ( ) ;
218
256
219
257
let mkdir_button = document . getElementById ( "mkdir" ) ;
0 commit comments