aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bzpage.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bzpage.js')
-rw-r--r--lib/bzpage.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 635ec7d..cbaae12 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -774,6 +774,43 @@ BZPage.prototype.getDefaultBugzillaMaintainer = function getDefaultBugzillaMaint
};
/**
+ * Parse the row with the attachment
+ *
+ * @param DOM element to be parsed
+ * @return array with string name of the attachment, integer its id number,
+ * string of MIME type, integer of size in kilobytes, and the whole
+ * element itself
+ */
+BZPage.prototype.parseAttachmentLine = function(inElem) {
+ var MIMEtype = "";
+ var size = 0;
+
+ // Skip over obsolete attachments
+ if (inElem.getElementsByClassName("bz_obsolete").length > 0) {
+ return ( []);
+ }
+
+ // getting name of the attachment
+ // TODO probably could use url.URL object
+ var attName = inElem.getElementsByTagName("b")[0].textContent.trim();
+
+ var aHrefsArr = inElem.getElementsByTagName("a");
+ var aHref = Array.filter(aHrefsArr, function(x) {
+ return x.textContent.trim() === "Details";
+ })[0];
+ var id = parseInt(aHref.getAttribute("href").replace(
+ /^.*attachment.cgi\?id=/, ""), 10);
+
+ // getting MIME type and size
+ var stringArray = inElem.getElementsByClassName("bz_attach_extra_info")[0].textContent
+ .replace(/[\n ()]+/g, " ").trim().split(", ");
+ size = parseInt(stringArray[0], 10);
+ MIMEtype = stringArray[1].split(" ")[0];
+
+ return [ attName, id, MIMEtype, size, inElem ];
+};
+
+/**
* collect the list of attachments in a structured format
*
* @return Array of arrays, one for each attachments;