From 01ec422bcf158954ca7417330e96c86f3dd3451c Mon Sep 17 00:00:00 2001 From: arlen22 Date: Fri, 10 Jan 2025 12:17:34 -0500 Subject: [PATCH] simple typescript errors --- .../modules/routes/handlers/get-users.js | 2 +- .../modules/routes/handlers/manage-user.js | 2 +- .../modules/routes/handlers/update-role.js | 2 +- .../modules/store/sql-tiddler-database.js | 16 ++++++++++++++-- .../modules/store/sql-tiddler-store.js | 2 +- .../modules/store/tests-sql-tiddler-store.js | 5 +++-- .../modules/tests/test-attachment.js | 4 ++-- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-users.js b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-users.js index 6beeda2fc02..2e0f7d59dfa 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-users.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-users.js @@ -29,7 +29,7 @@ exports.handler = async function(request,response,state) { console.error("userList is not an array"); } - if(!state.authenticatedUser.isAdmin && !state.firstGuestUser) { + if(!state.authenticatedUser?.isAdmin && !state.firstGuestUser) { response.writeHead(403, "Forbidden", { "Content-Type": "text/plain" }); response.end("Forbidden"); return; diff --git a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js index 8ec85aef97b..17e9b512ee5 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js @@ -46,7 +46,7 @@ exports.handler = async function(request,response,state) { } // Check if the user is trying to access their own profile or is an admin - var hasPermission = ($tw.utils.parseInt(user_id) === state.authenticatedUser.user_id) || state.authenticatedUser.isAdmin; + var hasPermission = ($tw.utils.parseInt(user_id) === state.authenticatedUser?.user_id) || state.authenticatedUser?.isAdmin; if(!hasPermission) { response.writeHead(403, "Forbidden", { "Content-Type": "text/plain" }); response.end("Forbidden"); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/update-role.js b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/update-role.js index bd6bdb594cf..401211051f0 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/update-role.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/update-role.js @@ -26,7 +26,7 @@ exports.handler = async function(request, response, state) { var role_name = state.data.role_name; var role_description = state.data.role_description; - if(!state.authenticatedUser.isAdmin) { + if(!state.authenticatedUser?.isAdmin) { response.writeHead(403, "Forbidden"); response.end(); return; diff --git a/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-database.js b/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-database.js index b2af90f07a1..921da98a438 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-database.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-database.js @@ -536,7 +536,19 @@ Checks if a user has permission to access a bag SqlTiddlerDatabase.prototype.hasBagPermission = async function(userId, bagName, permissionName) { return await this.checkACLPermission(userId, "bag", bagName, permissionName) }; - +/** + * @overload + * @param {string} entityType + * @param {string} entityName + * @param {false} [fetchAll] + * @returns {Promise>} + * + * @overload + * @param {string} entityType + * @param {string} entityName + * @param {true} fetchAll + * @returns {Promise[]>} + */ SqlTiddlerDatabase.prototype.getACLByName = async function(entityType, entityName, fetchAll) { const entityInfo = this.entityTypeToTableMap[entityType]; if (!entityInfo) { @@ -1078,7 +1090,7 @@ SqlTiddlerDatabase.prototype.findUserBySessionId = async function(sessionId) { $sessionId: sessionId, $timestamp: currentTimestamp }); - + /** @type {any} */ const userResult = await this.engine.runStatementGet(` SELECT * FROM users diff --git a/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-store.js b/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-store.js index 5d94fc3dfa1..4a5d4885aa3 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-store.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/store/sql-tiddler-store.js @@ -171,7 +171,7 @@ SqlTiddlerStore.prototype.processIncomingTiddler = function(tiddlerFields, exist if(existing_attachment_blob) { const fileSize = this.attachmentStore.getAttachmentFileSize(existing_attachment_blob); - if(fileSize <= attachmentSizeLimit) { + if(fileSize && (fileSize <= attachmentSizeLimit)) { const existingAttachmentMeta = this.attachmentStore.getAttachmentMetadata(existing_attachment_blob); const hasCanonicalField = !!tiddlerFields._canonical_uri; const skipAttachment = hasCanonicalField && (tiddlerFields._canonical_uri === (existingAttachmentMeta ? existingAttachmentMeta._canonical_uri : existing_canonical_uri)); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/store/tests-sql-tiddler-store.js b/plugins/tiddlywiki/multiwikiserver/modules/store/tests-sql-tiddler-store.js index a914fca9987..5fe904079ef 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/store/tests-sql-tiddler-store.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/store/tests-sql-tiddler-store.js @@ -29,9 +29,10 @@ function runSqlStoreTests(engine) { beforeEach(async function() { store = new SqlTiddlerStore({ databasePath: ":memory:", - engine: engine + engine: engine, + attachmentStore: {} }); - await store.initCheck(); + await store.init(); }); afterEach(async function() { diff --git a/plugins/tiddlywiki/multiwikiserver/modules/tests/test-attachment.js b/plugins/tiddlywiki/multiwikiserver/modules/tests/test-attachment.js index 39d09c12195..1fa84f7eee9 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/tests/test-attachment.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/tests/test-attachment.js @@ -104,7 +104,7 @@ if(typeof window === "undefined" && typeof process !== "undefined" && process.ve var contentHash = attachmentStore.saveAttachment(options); var stream = attachmentStore.getAttachmentStream(contentHash); expect(stream).not.toBeNull(); - expect(stream.type).toBe("text/plain"); + expect(stream?.type).toBe("text/plain"); }); it("getAttachmentFileSize", function() { @@ -173,7 +173,7 @@ if(typeof window === "undefined" && typeof process !== "undefined" && process.ve var contentHash = attachmentStore.saveAttachment(options); var stream = attachmentStore.getAttachmentStream(contentHash); assert.notStrictEqual(stream, null); - assert.strictEqual(stream.type, "application/octet-stream"); + assert.strictEqual(stream?.type, "application/octet-stream"); } }); });