1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00
TiddlyWiki5/core/modules
Devin Weaver bf74d13df5 Handle binary files better when saving on Node.JS (#2420)
* Save binary tiddlers with meta file

The filesystemadaptor plugin was a little simplistic in its
understanding of a binary file. It was using the typeInfo dictionary to
choose what tiddler types were binary (and hence needed a meta file when
saving).

I looked as if it was trying to be smart by looking for the hasMetaFile
*OR* had the encoding of base64. Unfortunately the typeInfo only defined
image/jpeg and so any other base64 encoded tiddler was assumed to be of
type text/vnd.tiddlywiki.

The net effect was only JPG images got a meta file and everything else
were saved as .tid files with base64 encoding. It all still worked but
made working with binary data in a Git repo a bit daunting.

There is enough information in the $tw.config.contentTypeInfo to
determine if a tiddler type is encoded with base64 or not. A better list
is available from boot/boot.js who registers all the types thorough the
registerFileType and marks then with base64 were appropriate.

This commit uses the typeInfo dictionary first for any filesystem
specific overrides, then the contentTypeInfo, and finally defaults to
the typeInfo["text/vnd.tiddlywiki"]. It also eliminates the now
unnecessary override for image/jpeg.

I think this might have been the original intent from commit 10b192e7.
From my limited testing all files described in boot/boot.js (lines
1832-1856) with an encoding of base64 now save as the original binary
and a meta file. Meaning that when you start the node server and then
drag-n-drop a binary file (i.e. image/png) it will PUT to the server
and then save it on the filesystem as-is allowing the file to be managed
as a binary file and not a text file. (Binary diffs are better and
GitHub supports them as well).

* Prevent duplicate file extensions

A side effects of using the $tw.config.contentFileInfo in the previous
commit is that it will always append a file extension to the tiddler
title when saving. In most cases this is the correct course of action.
However, sometimes that title is already a proper filename with an
extension (for example importing 'foobar.png' would save a file named
'foobar.png.png') which seemed silly.

This commit simply checks to make sure the title does not already end
with the file extension before appending it to the filename. A little
convenience really.

Since IE apparently doesn't have the String endsWith method I took the
liberty to add a helper method to $tw.utils trying to follow the other
polyfill patterns. I figured this was more generic and readable then
attempting to use a one-off solution inline. I got the polyfill code
from MDN.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#Polyfill

Is strEndsWith the best method name?
2016-07-11 11:18:19 +01:00
..
commands Trap missing tiddlers in savetiddler command 2016-06-23 16:19:00 +01:00
editor Text-editor: fix placeholder colour in Chrome 2016-07-03 14:53:37 +01:00
filters Add localisable strings for error (#2447) 2016-05-17 21:58:47 +01:00
info Obeisance to JSHint for core modules 2014-08-30 20:44:26 +01:00
macros Introduce text editor toolbar (#2315) 2016-04-22 08:36:29 +01:00
parsers Fix sandbox attribute for html parser generated iframes 2016-05-17 15:45:10 -06:00
savers Fix URI in "put" save handler 2016-06-23 16:23:36 +01:00
startup Extend notification handler to accept variables 2016-07-03 14:55:41 +01:00
storyviews Revert getTiddlerData() and add getTiddlerDataCached() 2015-07-10 16:43:50 +01:00
upgraders Revert getTiddlerData() and add getTiddlerDataCached() 2015-07-10 16:43:50 +01:00
utils Handle binary files better when saving on Node.JS (#2420) 2016-07-11 11:18:19 +01:00
widgets Extend view widget with plainwikified format 2016-06-23 16:28:59 +01:00
commander.js Improve error message for missing commands 2014-11-09 14:49:33 +00:00
config.js Move the wikilink regexps into global config 2014-11-26 11:12:25 +00:00
deserializers.js Fix JSON deserialiser to allow all fields 2014-11-13 16:04:30 +00:00
filters.js Add localisable strings for error (#2447) 2016-05-17 21:58:47 +01:00
keyboard.js Introduce text editor toolbar (#2315) 2016-04-22 08:36:29 +01:00
language.js Make lazy loading message be translateable 2015-09-08 10:41:27 +01:00
pluginswitcher.js disable enqueueTiddlerEvent during plugin switching 2014-11-01 16:32:52 +03:00
saver-handler.js Add localisable strings for error (#2447) 2016-05-17 21:58:47 +01:00
story.js Fix issues with creation and modification dates 2015-09-11 13:34:01 +01:00
syncer.js Don't use syncadaptors until they are ready 2016-07-05 11:29:59 +01:00
tiddler.js More resilience to Tiddler.isEqual() 2014-11-09 21:47:00 +00:00
wiki-bulkops.js Add renaming to text-slicer tiddler toolbar 2015-08-04 17:44:07 +01:00
wiki.js Fix problem with editing missing tiddlers 2016-05-02 10:12:08 +01:00