From bb3eb18942caf55e2d4e6f10429413a9dcf2cb6f Mon Sep 17 00:00:00 2001 From: Val Packett Date: Fri, 19 Aug 2022 18:22:35 +0300 Subject: [PATCH] Plugin: support uploading to arbitrary sync servers Not just the ones we're syncing with --- plugins/tiddlypwa/main.js | 8 +++++--- plugins/tiddlypwa/save-dialog.tid | 5 +++++ plugins/tiddlypwa/upload-app-form.tid | 10 ++++++++++ tiddlers/TiddlyPWA.tid | 7 +++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 plugins/tiddlypwa/upload-app-form.tid diff --git a/plugins/tiddlypwa/main.js b/plugins/tiddlypwa/main.js index 5e6ffa0..d8e93a0 100644 --- a/plugins/tiddlypwa/main.js +++ b/plugins/tiddlypwa/main.js @@ -532,9 +532,11 @@ Formatted with `deno fmt`. ); const swjs = $tw.wiki.renderTiddler('text/plain', '$:/plugins/valpackett/tiddlypwa-offline/sw.js', {}); try { - const servers = await adb( - this.db.transaction('syncservers').objectStore('syncservers').getAll(), - ); + const servers = (variables.uploadUrl && variables.uploadToken) + ? [{ url: variables.uploadUrl, token: variables.uploadToken }] + : await adb( + this.db.transaction('syncservers').objectStore('syncservers').getAll(), + ); const resps = await Promise.all(servers.map(({ url, token }) => fetch(url, { method: 'POST', diff --git a/plugins/tiddlypwa/save-dialog.tid b/plugins/tiddlypwa/save-dialog.tid index b7aae8d..2d34954 100644 --- a/plugins/tiddlypwa/save-dialog.tid +++ b/plugins/tiddlypwa/save-dialog.tid @@ -64,6 +64,11 @@ upload it to sync servers ! +
+Or even upload to a sync server you are not currently syncing with… +{{$:/plugins/valpackett/tiddlypwa/upload-app-form}} +
+ {{$:/status/TiddlyPWAUploadResult}} Note that some basic configuration like the title, subtitle, favicon, theme and palette will be saved unencrypted. diff --git a/plugins/tiddlypwa/upload-app-form.tid b/plugins/tiddlypwa/upload-app-form.tid new file mode 100644 index 0000000..d209819 --- /dev/null +++ b/plugins/tiddlypwa/upload-app-form.tid @@ -0,0 +1,10 @@ +title: $:/plugins/valpackett/tiddlypwa/upload-app-form + + + +<$button> +<$action-sendmessage $message="tiddlypwa-upload-app-wiki" + publishFilter={{$:/plugins/valpackett/tiddlypwa/app-filter}} + uploadUrl={{$:/temp/TiddlyPWAServerURL}} uploadToken={{$:/temp/TiddlyPWAServerToken}} /> +Upload + diff --git a/tiddlers/TiddlyPWA.tid b/tiddlers/TiddlyPWA.tid index e5eb5fb..2344994 100644 --- a/tiddlers/TiddlyPWA.tid +++ b/tiddlers/TiddlyPWA.tid @@ -11,6 +11,13 @@ This will reload the page, and you will be asked for a password. If you do not yet have one, make one up! Note that you must to use the same password on all TiddlyPWA instances you'd want to sync between. +
+Upload this version to any sync server… +{{$:/plugins/valpackett/tiddlypwa/upload-app-form}} +
+ +{{$:/status/TiddlyPWAUploadResult}} + !! Hosting a custom instance First, either start with this page or add the following plugins to a fresh TiddlyWiki file: