@@ -126,6 +126,10 @@ class FileManager extends HTMLElement {
126126 ${ iconsSvg }
127127 <div class="file-manager">
128128 <div class="toolbar">
129+ <button class="btn-create-collection" title="Create collection">
130+ <svg width="16" height="16" fill="currentColor"><use href="#icon-folder-plus"></use></svg>
131+ New Collection
132+ </button>
129133 <button class="btn-upload" title="Upload files">
130134 <svg width="16" height="16" fill="currentColor"><use href="#icon-upload"></use></svg>
131135 Upload
@@ -168,6 +172,10 @@ class FileManager extends HTMLElement {
168172 </div>
169173 ` ;
170174
175+ // Setup create collection button
176+ const createCollectionBtn = this . shadowRoot . querySelector ( '.btn-create-collection' ) ;
177+ createCollectionBtn . addEventListener ( 'click' , ( ) => this . performCreateCollection ( ) ) ;
178+
171179 // Setup upload button
172180 const uploadBtn = this . shadowRoot . querySelector ( '.btn-upload' ) ;
173181 const fileInput = this . shadowRoot . querySelector ( '.file-input' ) ;
@@ -284,6 +292,38 @@ class FileManager extends HTMLElement {
284292 }
285293 }
286294
295+ async createCollection ( collectionPath , name ) {
296+ // API: POST /api/collections/{collection}?name={name}
297+ const url = `${ this . apiBase } /api/collections/${ encodeURIComponent ( collectionPath ) } ?name=${ encodeURIComponent ( name ) } ` ;
298+
299+ try {
300+ const response = await fetch ( url , {
301+ method : 'POST'
302+ } ) ;
303+
304+ if ( ! response . ok ) {
305+ const errorText = await response . text ( ) ;
306+ console . error ( 'Create collection HTTP error:' , response . status , errorText ) ;
307+ throw new Error ( `HTTP error! status: ${ response . status } - ${ errorText . substring ( 0 , 100 ) } ` ) ;
308+ }
309+
310+ // API returns JSON
311+ const result = await response . json ( ) ;
312+
313+ // Check for failure response
314+ if ( result . status === 'fail' && result . message ) {
315+ console . error ( 'Create collection failed, response:' , result ) ;
316+ throw new Error ( result . message ) ;
317+ }
318+
319+ return result ;
320+ } catch ( error ) {
321+ console . error ( 'Error creating collection:' , error ) ;
322+ this . showError ( `Failed to create collection: ${ error . message } ` ) ;
323+ throw error ;
324+ }
325+ }
326+
287327 async deleteItem ( path ) {
288328 // This method is kept for single item deletion
289329 // For multiple items, use deleteItems() instead
@@ -1463,6 +1503,36 @@ class FileManager extends HTMLElement {
14631503 }
14641504 }
14651505
1506+ async performCreateCollection ( ) {
1507+ const collectionName = await this . showPrompt ( 'Enter collection name:' , '' , 'info' ) ;
1508+
1509+ if ( ! collectionName || ! collectionName . trim ( ) ) return ;
1510+
1511+ const name = collectionName . trim ( ) ;
1512+
1513+ // Validate collection name (basic validation - no slashes, not empty)
1514+ if ( name . includes ( '/' ) || name . includes ( '\\' ) ) {
1515+ this . showError ( 'Collection name cannot contain slashes' ) ;
1516+ return ;
1517+ }
1518+
1519+ try {
1520+ await this . createCollection ( this . currentPath , name ) ;
1521+
1522+ // Clear cache and loaded ranges to force fresh load
1523+ this . cache . delete ( this . currentPath ) ;
1524+ this . loadedRanges = [ ] ;
1525+ this . items = [ ] ;
1526+
1527+ // Refresh collection
1528+ await this . loadCollection ( this . currentPath , false ) ;
1529+ this . showMessage ( `Collection "${ name } " created successfully` ) ;
1530+ } catch ( error ) {
1531+ console . error ( 'Create collection error:' , error ) ;
1532+ // Error already shown in createCollection method
1533+ }
1534+ }
1535+
14661536 async performRename ( path ) {
14671537 const item = this . items . find ( i => ( i . path || i . name ) === path ) ;
14681538 if ( ! item ) return ;
0 commit comments