nathan-sain / foundry-world-tools

A Python CLI for managing Foundry VTT assets on the file system
MIT License
10 stars 5 forks source link

Scan journal for references when using pull and renameall #13

Closed EternalDeiwos closed 2 years ago

EternalDeiwos commented 2 years ago

fwt pull work great for the database files but don't pick up media references in journal entries.

For example, we start with an element that looks like this:

<img class="rd__image" src="assets/srd5e/img/adventure/myworld/My Asset Name.jpg" />
fwt pull --from assets/srd5e/img --to worlds/myworld

The assets referenced in the journal are not moved, nor are the links updated. As an aside, I think that other commands like fwt renameall also do not affect journal media references but I'm not sure if that is because its not being scanned or its not meeting some condition to be renamed.

nathan-sain commented 2 years ago

It's been a minute since I've worked with the logic of the pull command. I'll do some testing to see what the issue may be. Off the top of my head I suspect that it may be due to the strings in the biography key being escaped and / or URL encoded.

If you have time can you check the actor.db file that has the problem and see if the src attributes have been URL encoded?

electronicum commented 2 years ago

OP means the journal entries in journal.db. The images are referenced inside html <img and <a tags. These are part of the JSON content attribute.

nathan-sain commented 2 years ago

Ooops. My bad. Although, the URL encoding issue may still apply since the journal.db entries content attribute is also formatted HTML.

Regarding the renaming of assets, I was able to rename images within journal entries on my development server. If you have time please look in your db files to see if there may be additional encoding characters in the paths for the files that are not being renamed.

Regarding the pull command, currently it is only analyzing paths contained within json img keys. I see the need to also find paths contained throughout the db files so I'll start working on a more generic algorithm to detect and copy assets from other projects. No ETA but I expect to have a new version in the next few days.

Thanks for you feedback.

EternalDeiwos commented 2 years ago

The journals.db file looks like this within a JSON string:

<a title=\"A Very Special Asset\" href=\"assets/srd5e/img/adventure/myworld/My Asset.jpg\" target=\"_blank\" rel=\"noopener noreferrer\">

The double quotes are escaped because its in a JSON string but there is no URL encoding going on otherwise. Foundry seems to handle that on the client side and stores the raw HTML.

If you have time can you check the actor.db file that has the problem and see if the src attributes have been URL encoded?

We have already been using this for actors and have had no problems, but I am unsure if the actors in our current world had bios that would be affected by the above. A brief scan of the original actors.db doesn't seem to show any of the same problem.

Also, much appreciated for fwt as always.

nathan-sain commented 2 years ago

I've pushed a new version that should allow pull of assets referenced anywhere in the database. Please test.

@EternalDeiwos, RE the rewrite of assets in the journal.db, is the path assets/srd5e/img/adventure/myworld/My Asset.jpg outside of the project being modified? If so, fwt will ignore remote assets as renaming them could result in breaking changes for those remote projects. Assuming that is the case pull should be able to make those assets local which would allow them to be renamed.

Let me know if all is working.

electronicum commented 2 years ago

Regarding Pull, it worked for the world I was working on. It pulled journal links that it didn't do before, from a source external to the world, and placed it inside the world. Great Stuff.

EternalDeiwos commented 2 years ago

Will test as well but glad to hear confirmation from electronicum.

Also, I had another occasion to try out fwt renameall on journal content and found that it was in fact working as expected so false alarm there. With fwt pull getting the files into the world path everything should work from there.