Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWS: fix editing attachment tiddlers #8455

Merged

Conversation

webplusai
Copy link
Contributor

@webplusai webplusai commented Jul 30, 2024

Issue: #8446
Each time the image was broken on the webpage while following the reproduction steps. It was as a result of the attachment_blob value being set to null when the tiddler was saved.

Copy link

Confirmed: webplusai has already signed the Contributor License Agreement (see contributing.md)

@webplusai webplusai closed this Jul 30, 2024
@webplusai webplusai reopened this Jul 30, 2024
Copy link

Confirmed: webplusai has already signed the Contributor License Agreement (see contributing.md)

@Jermolene Jermolene changed the title fix breaking bug in image tiddler attachment MWS: fix editing attachment tiddlers Jul 30, 2024
Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @webplusai for the speedy response. It's great to see that you've been able to identify a fix so swiftly with unfamiliar code.

I have only conducted a brief review so far as I am away from my desk. I will try it out properly when I am back.

Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @webplusai much appreciated

Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @webplusai thank you, this is looking good. My concerns now are around the edge cases.

Have you seen the test framework in $:/plugins/tiddlywiki/multiwikiserver/commands/mws-test-server.js? I think we need to look at introducing some tests for the attachment handling logic. I would hope it could be done relatively easily if we could figure out a convenient way to bring down the attachment size limit so that the tests can work with attachments of 10s of bytes.

Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @webplusai this is looking very good. The new tests are very clear and much appreciated.

There are a couple of minor points but otherwise I think this is ready to merge

.gitignore Outdated
@@ -10,3 +10,6 @@ store/
/playwright-report/
/playwright/.cache/
$__StoryList.tid
/editions/test/test-store/*
/coverage
/.nyc_output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the last two entries are no longer required.

Tests attachments.

\*/
var fs = require('fs');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologise in advance, but an aspect of our coding style that is unorthodox is that we prefer strings to use double quotes

/*\
title: test-attachment.js
type: application/javascript
tags: [[$:/tags/test-spec]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should reside within the multiwikiserver plugin, and the tiddlywiki.info for the editions/test edition should be modified to include the multiwikiserver plugin. (This is the approach that the geospatial plugin uses for its tests).

created: $tw.utils.stringifyDate(new Date()),
modified: $tw.utils.stringifyDate(new Date()),
contentHash: contentHash,
filename: dataFilename,
type: options.type
type: options.type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extraneous comma at the end of this line

},null,4));
return contentHash;
};

/*
Adopts an attachment file into the store
*/
AttachmentStore.prototype.adoptAttachment = function(incomingFilepath,type,hash) {
AttachmentStore.prototype.adoptAttachment = function(incomingFilepath,type,hash,canonicalUri) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consistently use _canonical_uri as the variable name


let shouldProcessAttachment = tiddlerFields.text && tiddlerFields.text.length <= attachmentSizeLimit;

if (existing_attachment_blob) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another coding style weirdness is that we don't include whitespace between if and the parenthesis.

@pmario may be able to advise on linter settings that can help with TW coding styles

Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you again for you patience @webplusai. This is excellent quality of work.

There's a couple of minor points below, but otherwise this is ready to merge.

"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz",
"integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==",
"version": "7.24.7",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these changes to package-lock.json are needed anymore.

package.json Outdated
"test": "node ./tiddlywiki.js ./editions/test --verbose --version --build index && node ./tiddlywiki ./editions/multiwikiserver/ --build load-mws-demo-data --mws-listen --mws-test-server http://127.0.0.1:8080/ --quit",
"start": "node ./tiddlywiki.js ./editions/multiwikiserver --mws-load-plugin-bags --build load-mws-demo-data --mws-listen",
"build:test-edition": "node ./tiddlywiki.js ./editions/test --verbose --version --build index",
"build:multiwikiserver-edition": "node ./tiddlywiki.js ./editions/multiwikiserver/ --build load-mws-demo-data --mws-listen --mws-test-server http://127.0.0.1:8080/ --quit",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this should perhaps be test:multiwikiserver-edition?

@@ -170,7 +170,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
* Default number of milliseconds Jasmine will wait for an asynchronous spec to complete.
* @name jasmine.DEFAULT_TIMEOUT_INTERVAL
*/
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
j$.DEFAULT_TIMEOUT_INTERVAL = 30000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files within the plugins/tiddlywiki/jasmine/files directory are taken directly from the Jasmine release. Any changes here will be overwritten the next time Jasmine is upgraded. If the increased timeout is necessary we should explore whether it can be configured in the TiddlyWIki JS wrappers

@Jermolene
Copy link
Member

Thank you @webplusai for your patience, and congratulations on landing a significant PR.

@Jermolene Jermolene merged commit 3287dce into TiddlyWiki:multi-wiki-support Aug 28, 2024
2 of 3 checks passed
@Jermolene
Copy link
Member

Hi @webplusai it turns out that there is a small problem with the tests – they fail if the directory ./editions/test/test-store does not exist. That means that the tests are failing in CI at the moment so it would be great to sort this out as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants