--- a/src/server/safs/service.c Fri May 30 14:11:56 2025 +0200 +++ b/src/server/safs/service.c Fri May 30 14:48:42 2025 +0200 @@ -823,6 +823,31 @@ char *path = pblock_findkeyval(pb_key_path, rq->vars); char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); + + // params + char *useemojis = pblock_findval("use-emojis", pb); + char *diricon = pblock_findval("dir-icon", pb); + char *fileicon = pblock_findval("file-icon", pb); + char *hidden = pblock_findval("show-hidden", pb); + + WSBool show_hidden = TRUE; + char *dir_str = "<dir>"; + char *file_str = "<file>"; + + if(hidden) { + show_hidden = util_getboolean(hidden, FALSE); + } + if(useemojis && util_getboolean(useemojis, FALSE)) { + dir_str = "📁"; + file_str = "📄"; + } else { + if(diricon) { + dir_str = cx_asprintf_a(a, "<img src=\"%s\" alt=\"directory\" border=\"0\"/>", diricon).ptr; + } + if(fileicon) { + file_str = cx_asprintf_a(a, "<img src=\"%s\" alt=\"directory\" border=\"0\"/>", fileicon).ptr; + } + } // open the file VFSContext *vfs = vfs_request_context(sn, rq); @@ -830,6 +855,13 @@ if(!dir) { return REQ_ABORTED; } + + CxList *files = cxLinkedListCreate(a, (cx_compare_func)cmp_file_type_name, sizeof(IndexEntry)); + if(!files) { + vfs_closedir(dir); + return REQ_ABORTED; + } + sbuf_t *out = sbuf_new(1024); // output buffer @@ -839,21 +871,21 @@ sbuf_puts(out, "</title>\n"); sbuf_puts(out, "<style>\n"); sbuf_puts(out, "th { text-align: left; }\n"); - sbuf_puts(out, "td { padding-right: 1em; }\n"); + sbuf_puts(out, "td { padding-right: 2em; }\n"); + sbuf_puts(out, ".type { padding-right: 0em; }\n"); sbuf_puts(out, "</style>\n"); sbuf_puts(out, "</head><body>\n<h1>Index of "); sbuf_puts(out, uri); sbuf_puts(out, "</h1><hr>\n\n"); - - CxList *files = cxLinkedListCreate(a, (cx_compare_func)cmp_file_type_name, sizeof(IndexEntry)); - if(!files) { - return REQ_ABORTED; - } // read directory at store entries in the files list int ret = REQ_PROCEED; VFS_ENTRY f; while(vfs_readdir_stat(dir, &f)) { + if(!show_hidden && f.name[0] == '.') { + continue; + } + IndexEntry entry; entry.name = pool_strdup(sn->pool, f.name); if(!entry.name) { @@ -879,14 +911,14 @@ } // generate html output - sbuf_puts(out, "<table>\n<tr><th>Type</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>\n"); + sbuf_puts(out, "<table>\n<tr><th colspan=\"2\">Name</th><th>Size</th><th>Last Modified</th></tr>\n"); cxListSort(files); CxIterator i = cxListIterator(files); cx_foreach(IndexEntry *, entry, i) { sbuf_puts(out, "<tr>\n"); - sbuf_puts(out, "<td>"); - sbuf_puts(out, entry->isdir ? "[DIR]" : "[FILE]"); + sbuf_puts(out, "<td class=\"type\">"); + sbuf_puts(out, entry->isdir ? dir_str : file_str); sbuf_puts(out, "</td>"); sbuf_puts(out, "<td>");