upload: reduce attachment identifiers to 9 characters.
authorArt Cancro <ajc@citadel.org>
Wed, 11 Oct 2023 02:37:48 +0000 (22:37 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 11 Oct 2023 02:37:48 +0000 (22:37 -0400)
Also switched from a unicode X to a fontawesome rounded-X for the
'remove attachment' button.  The unicode one was too big.

webcit-ng/server/upload.c
webcit-ng/server/webcit.h
webcit-ng/static/js/upload.js

index 110241c3c5c23268699b3fc5e8d6dfe5af6bfd6b..101d7894882493363773602817a3ce1dcc5e8a91 100644 (file)
@@ -28,7 +28,13 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        syslog(LOG_DEBUG, "          id: %s", cbid);
 
        struct uploaded_file u;
-       generate_uuid(u.id);
+
+       // create a random ID for the attachment
+       for (int i=0; i<sizeof(u.id); ++i) {
+               u.id[i] = (rand() % 26) + 'a';
+       }
+       u.id[sizeof(u.id)-1] = 0;
+
        safestrncpy(u.filename, filename, sizeof(u.filename));
        safestrncpy(u.content_type, cbtype, sizeof(u.content_type));
        u.length = length;
@@ -123,6 +129,29 @@ void dav_delete_upload(struct http_transaction *h, struct ctdlsession *c, struct
 }
 
 
+// Remove an uploaded item from the upload_list.  Caller now owns the file handle and is responsible for closing it.
+struct uploaded_file pop_upload(char *id) {
+       int i;
+       struct uploaded_file *u;
+       struct uploaded_file ret;
+
+       memset(&ret, 0, sizeof(struct uploaded_file));
+
+       pthread_mutex_lock(&upload_list_mutex);
+       for (i=0; i<array_len(upload_list); ++i) {
+               u = (struct uploaded_file *) array_get_element_at(upload_list, i), sizeof(struct uploaded_file);
+               if (!strcmp(u->id, id)) {
+                       ret = *u;
+                       array_delete_element_at(upload_list, i);
+                       i = array_len(upload_list) + 1;         // Go out of scope; we're done here
+               }
+       }
+       pthread_mutex_unlock(&upload_list_mutex);
+
+       return(ret);                                            // ret will be all-zeroes if we didn't find it
+}
+
+
 // Handle operations on a specific upload
 void specific_upload(struct http_transaction *h, struct ctdlsession *c, char *name) {
        int i;
index 64368b0e5c6169bb206a77d0f8b2e53c6c26522b..0b415ade0885c52b259908b503fb725c9affc5b7 100644 (file)
@@ -96,7 +96,7 @@ struct ctdlsession {
 };
 
 struct uploaded_file {                         // things that have been uploaded to the server (such as email attachments)
-       char id[64];
+       char id[10];
        char filename[256];
        char content_type[256];
        long length;
index 28c374edb114302bb8c3217ae21d3b96cbe44e57..96e02b972e7a53b90b556155c293723140ac91cf 100644 (file)
@@ -85,7 +85,8 @@ function upload_file(file) {
                        j_response.forEach((item) => {
                                let new_upl = document.createElement("li");
                                // item["ref"] is what we need
-                               new_upl.innerHTML = `<a href="xxx">❌</a>`
+                               new_upl.innerHTML = `<i class="fa-solid fa-circle-xmark" style="color:red" onClick="alert('` + item["ref"] + `')"></i>`
+                               + `&nbsp;`
                                + item["uploadfilename"] + " (" + item["contenttype"] + ", " + item["contentlength"] + " " + _("bytes") + ")";
                                document.getElementById("ctdl-upload_list").appendChild(new_upl);
                        });