Skip to content

Commit

Permalink
simple typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arlen22 committed Jan 10, 2025
1 parent dd94354 commit 01ec422
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, any>>}
*
* @overload
* @param {string} entityType
* @param {string} entityName
* @param {true} fetchAll
* @returns {Promise<Record<string, any>[]>}
*/
SqlTiddlerDatabase.prototype.getACLByName = async function(entityType, entityName, fetchAll) {
const entityInfo = this.entityTypeToTableMap[entityType];
if (!entityInfo) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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");
}
});
});
Expand Down

0 comments on commit 01ec422

Please sign in to comment.