From f67e477cc78d75b4f58a10072590e721ca22c594 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Tue, 1 Feb 2022 19:13:48 -0800
Subject: [PATCH] add() method will now parse added, last_downloaded, and
 times_downloaded

These 3 'stats' properties were read-only (never used when adding a file). To support moving files between FileBases while retaining these stats, support the parse/use of these file-meta-object property values.

Should fix issue #333 reported by Nightfox.
---
 src/sbbs3/js_filebase.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/sbbs3/js_filebase.c b/src/sbbs3/js_filebase.c
index 1f2d779d03..5e9a4f294d 100644
--- a/src/sbbs3/js_filebase.c
+++ b/src/sbbs3/js_filebase.c
@@ -572,7 +572,7 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
 		uint32_t cost = 0;
 		if(!JS_ValueToECMAUint32(cx, val, &cost)) {
 			free(cp);
-			JS_ReportError(cx, "Error converting adding '%s' property to Uint32", prop_name);
+			JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
 			return SMB_FAILURE;
 		}
 		if((file->cost != 0 || cost != 0) && (result = smb_new_hfield(file, SMB_COST, sizeof(cost), &cost)) != SMB_SUCCESS) {
@@ -581,6 +581,36 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
 			return result;
 		}
 	}
+	prop_name = "added";
+	if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
+		uint32_t t = 0;
+		if(!JS_ValueToECMAUint32(cx, val, &t)) {
+			free(cp);
+			JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
+			return SMB_FAILURE;
+		}
+		file->hdr.when_imported.time = t;
+	}
+	prop_name = "last_downloaded";
+	if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
+		uint32_t t = 0;
+		if(!JS_ValueToECMAUint32(cx, val, &t)) {
+			free(cp);
+			JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
+			return SMB_FAILURE;
+		}
+		file->hdr.last_downloaded = t;
+	}
+	prop_name = "times_downloaded";
+	if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
+		uint32_t t = 0;
+		if(!JS_ValueToECMAUint32(cx, val, &t)) {
+			free(cp);
+			JS_ReportError(cx, "Error converting '%s' property to Uint32", prop_name);
+			return SMB_FAILURE;
+		}
+		file->hdr.times_downloaded = t;
+	}
 
 	if(JS_GetProperty(cx, obj, "anon", &val) && val == JSVAL_TRUE)
 		file->hdr.attr |= FILE_ANONYMOUS;
-- 
GitLab