1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-28 15:08:46 +00:00
TiddlyWiki5/plugins/tiddlywiki
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
..
async Add plugin wrappers for async and jszip 2015-12-19 18:47:42 +00:00
blog Added mobile-web-app-capable meta tag for Android Chrome (#2456) 2016-07-11 11:16:58 +01:00
browser-sniff Left off last commit 2015-03-19 10:53:51 +00:00
cecily Improve plugin readmes 2015-03-19 10:53:45 +00:00
classictools Improve plugin readmes 2015-03-19 10:53:45 +00:00
codemirror Remove final vestiges of undo/redo buttons 2016-05-01 13:54:16 +01:00
d3 Improve plugin readmes 2015-03-19 10:53:45 +00:00
evernote Minor tweaks to #2275 2016-02-16 16:35:28 +00:00
filesystem Handle binary files better when saving on Node.JS (#2420) 2016-07-11 11:18:19 +01:00
github-fork-ribbon Left off last commit 2015-03-19 10:53:51 +00:00
googleanalytics Improve plugin readmes 2015-03-19 10:53:45 +00:00
help Tweak size of help panel 2015-03-22 15:52:17 +00:00
highlight Highlight plugin: add static demo 2015-09-11 22:36:30 +01:00
internals Introduce text editor toolbar (#2315) 2016-04-22 08:36:29 +01:00
jasmine Improve plugin readmes 2015-03-19 10:53:45 +00:00
jszip Fix readme path of jszip (#2430) 2016-05-20 07:46:29 -06:00
katex Update KaTeX plugin to v0.6.0 2016-04-22 15:50:23 +01:00
markdown Update codemirror and markdown plugins from #2315 2016-04-22 08:41:31 +01:00
nodewebkitsaver Improve plugin readmes 2015-03-19 10:53:45 +00:00
pluginlibrary Improve plugin readmes 2015-03-19 10:53:45 +00:00
powered-by-tiddlywiki Add rel="noopener noreferrer" to external links 2016-05-05 11:49:40 +01:00
railroad Add rel="noopener noreferrer" to external links 2016-05-05 11:49:40 +01:00
stacked-view Make the stacked view play well with the new fluid-fixed mode 2015-05-05 07:24:14 +01:00
tahoelafs Improve plugin readmes 2015-03-19 10:53:45 +00:00
text-slicer Text-slicer: Fix issue with missing destination title 2016-05-11 11:13:15 -06:00
tiddlyweb Don't use syncadaptors until they are ready 2016-07-05 11:29:59 +01:00
translators Split exporters from miscellaneous language tiddler (#2460) 2016-05-23 12:30:57 -06:00
tw2parser Fix referred name of localisable string for recursive transclusion error (#2458) 2016-05-22 15:33:02 -06:00
tw5.com-docs Create a plugin and edition for tw5.com docs 2015-09-15 13:37:01 +01:00
upgrade Make upgrade wizard download link be relative 2015-03-31 19:14:49 +01:00
xmldom Add xmldom parser 2016-02-01 21:28:52 +00:00