diff --git a/package.json b/package.json index b3122e471ff..be199f4ef71 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "scripts": { "start": "node ./tiddlywiki.js ./editions/multiwikiserver --listen", - "test": "node ./tiddlywiki.js ./editions/test --verbose --version --build index && node ./tiddlywiki ./editions/multiwikiserver/ --listen debug-level=full --mws-test-server http://127.0.0.1:8080/ --quit", + "test": "node ./tiddlywiki.js ./editions/test --verbose --version --build index && node ./tiddlywiki ./editions/multiwikiserver/ --mws-listen debug-level=full --mws-test-server http://127.0.0.1:8080/ --quit", "lint:fix": "eslint . --fix", "lint": "eslint ." }, diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/AdminLayout.tid b/plugins/tiddlywiki/multiwikiserver/admin-ui/AdminLayout.tid deleted file mode 100644 index 94f5bff4398..00000000000 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/AdminLayout.tid +++ /dev/null @@ -1,19 +0,0 @@ -title: $:/plugins/multiwikiserver/AdminLayout -tags: $:/tags/Layout -name: MultiWikiServer -description: Admin Layout -icon: $:/favicon.ico - -\import [subfilter{$:/core/config/GlobalImportFilter}] - -
- -
TiddlyWiki5
- {{MultiWikiServer Administration}} -
- <$button> - <$action-setfield $tiddler="$:/layout" text="$:/core/ui/PageTemplate"/> - Switch to TiddlyWiki default user interface - -
-
diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/DefaultTiddlers.tid b/plugins/tiddlywiki/multiwikiserver/admin-ui/DefaultTiddlers.tid deleted file mode 100644 index 2438953264e..00000000000 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/DefaultTiddlers.tid +++ /dev/null @@ -1,2 +0,0 @@ -title: $:/DefaultTiddlers -text: [[MultiWikiServer Administration]] diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/MultiWikiServer Administration.tid b/plugins/tiddlywiki/multiwikiserver/admin-ui/MultiWikiServer Administration.tid deleted file mode 100644 index 4b076166f3b..00000000000 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/MultiWikiServer Administration.tid +++ /dev/null @@ -1,231 +0,0 @@ -title: MultiWikiServer Administration - -\procedure createBag(name,description,errorTiddler) - \procedure completion-createBag() - \import [subfilter{$:/core/config/GlobalImportFilter}] - <$action-log - status=<> - statusText=<> - error=<> - data=<> - headers=<> - /> - <%if [match[]] %> - <$action-setfield $tiddler=<> text=""/> - <$action-sendmessage $message="tm-server-refresh"/> - <%else%> - <$action-setfield $tiddler=<> text=<>/> - <%endif%> - \end completion-createBag - <$action-sendmessage - $message="tm-http-request" - url=`/wiki/${ [encodeuricomponent[]] }$/bags/${ [encodeuricomponent[]] }$` - method="PUT" - body=`{"description":"${ [] }$"}` - oncompletion=<> - var-errorTiddler=<> - /> -\end createBag - -\procedure createBagButton(name) - \whitespace trim -
-
- <$text text="Create a new bag"/> -
-
-
- - <$edit-text tiddler="$:/temp/NewBagName" tag="input" placeholder="(bag name)" class="mws-form-field-input"/> -
-
- - <$edit-text tiddler="$:/temp/NewBagDescription" tag="input" placeholder="(description)" class="mws-form-field-input"/> -
-
-
- <%if [[$:/temp/NewBagError]get[text]else[]!match[]] %> -
- <$text text={{$:/temp/NewBagError}}/> -
- <%endif%> -
-
- <$button class="mws-form-button"> - <$transclude - $variable="createBag" - name={{$:/temp/NewBagName}} - description={{$:/temp/NewBagDescription}} - errorTiddler="$:/temp/NewBagError" - /> - Create Bag - -
-
-\end createBagButton - -\procedure createRecipe(name,bag_names,description,errorTiddler) - \procedure completion-createRecipe() - \import [subfilter{$:/core/config/GlobalImportFilter}] - <%if [match[]] %> - <$action-setfield $tiddler=<> text=""/> - <$action-sendmessage $message="tm-server-refresh"/> - <%else%> - <$action-setfield $tiddler=<> text=<>/> - <%endif%> - \end completion-createRecipe - \procedure emptyArray() [] - \function createRecipeJson() - [enlist-input[]] :reduce[!match[]elsejsonset,] - \end createRecipeJson - <$action-sendmessage - $message="tm-http-request" - url=`/wiki/${ [encodeuricomponent[]] }$/recipes/${ [encodeuricomponent[]] }$` - method="PUT" - body=`{"bag_names":${ [] }$,"description":"${ [] }$"}` - oncompletion=<> - var-errorTiddler=<> - /> -\end createRecipe - -\procedure createRecipeButton() - \whitespace trim -
-
- <$text text="Create a new recipe"/> -
-
-
- - <$edit-text tiddler="$:/temp/NewRecipeName" tag="input" placeholder="(recipe name)" class="mws-form-field-input"/> -
-
- - <$edit-text tiddler="$:/temp/NewRecipeBagNames" tag="input" placeholder="(space separated list of bags)"/> -
-
- - <$edit-text tiddler="$:/temp/NewRecipeDescription" tag="input" placeholder="(description)" class="mws-form-field-input"/> -
-
-
- <%if [[$:/temp/NewRecipeError]get[text]else[]!match[]] %> -
- <$text text={{$:/temp/NewRecipeError}}/> -
- <%endif%> -
-
- <$button class="mws-form-button"> - <$transclude - $variable="createRecipe" - name={{$:/temp/NewRecipeName}} - bag_names={{$:/temp/NewRecipeBagNames}} - description={{$:/temp/NewRecipeDescription}} - errorTiddler="$:/temp/NewRecipeError" - /> - Create Recipe - -
-
-\end createRecipeButton - - -\procedure bagPill(element-tag:"span",is-topmost:"no") - \whitespace trim - <$genesis $type=<> class={{{ mws-bag-pill [match[yes]then[mws-bag-pill-topmost]] +[join[ ]] }}}> - - <$image - source=`/wiki/${ [{!!bag-name}encodeuricomponent[]] }$/bags/${ [{!!bag-name}encodeuricomponent[]] }$/tiddlers/%24%3A%2Ffavicon.ico` - class="mws-favicon-small" - > - <$image - source="$:/plugins/multiwikiserver/images/missing-favicon.png" - class="mws-favicon-small" - /> - - - <$text text={{!!bag-name}}/> - - - -\end - - -\procedure wikiCard() - \whitespace trim - -
- <$image - source=`/wiki/${ [{!!recipe-name}encodeuricomponent[]] }$/recipes/${ [{!!recipe-name}encodeuricomponent[]] }$/tiddlers/%24%3A%2Ffavicon.ico` - class="mws-favicon" - > - <$image - source="$:/plugins/multiwikiserver/images/missing-favicon.png" - class="mws-favicon" - /> - -
-
-
- <$text text={{!!recipe-name}}/> -
-
- <%if [list] %> -
    - <$list filter="[list]" counter="counter"> - <$transclude $variable="bagPill" is-topmost={{{ [match[yes]] }}} element-tag="li"/> - -
- <%else%> - (no bags defined) - <%endif%> -
-
- <$text text={{!!text}}/> -
-
-
-\end - -
-

Wikis

-

- These are the wikis available on this server. Click on a wiki to visit it in a new browser tab. -

-
    - <$list filter="[prefix[$:/state/MultiWikiServer/recipes/]]"> -
  • - <> -
  • - -
-
- <> -
-
- Higher numbered bags take priority if a tiddler with the same title is in more than one bag -
-

Bags

-
    - <$list filter="[prefix[$:/state/MultiWikiServer/bags/]]"> -
  • - <> - <$text text={{!!text}}/> -
  • - -
-
- <> -
-
diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/SideBarSegment.tid b/plugins/tiddlywiki/multiwikiserver/admin-ui/SideBarSegment.tid deleted file mode 100644 index d79b41aa4da..00000000000 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/SideBarSegment.tid +++ /dev/null @@ -1,10 +0,0 @@ -title: $:/plugins/multiwikiserver/SideBarSegment -tags: $:/tags/SideBarSegment -list-before: $:/core/ui/SideBarSegments/page-controls - -
-<$button> -<$action-setfield $tiddler="$:/layout" text="$:/plugins/multiwikiserver/AdminLayout"/> -Switch back to ~MultiWikiServer administration user interface - -
diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/favicon.png.meta b/plugins/tiddlywiki/multiwikiserver/admin-ui/favicon.png.meta deleted file mode 100644 index 76d0be1a8ca..00000000000 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/favicon.png.meta +++ /dev/null @@ -1,2 +0,0 @@ -title: $:/favicon.ico -type: image/png diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/layout.tid b/plugins/tiddlywiki/multiwikiserver/admin-ui/layout.tid deleted file mode 100644 index beff36af1cc..00000000000 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/layout.tid +++ /dev/null @@ -1,2 +0,0 @@ -title: $:/layout -text: $:/plugins/multiwikiserver/AdminLayout diff --git a/plugins/tiddlywiki/multiwikiserver/admin-ui/missing-favicon.png.meta b/plugins/tiddlywiki/multiwikiserver/admin-ui/missing-favicon.png.meta deleted file mode 100644 index a86d72be105..00000000000 --- a/plugins/tiddlywiki/multiwikiserver/admin-ui/missing-favicon.png.meta +++ /dev/null @@ -1,2 +0,0 @@ -title: $:/plugins/multiwikiserver/images/missing-favicon.png -type: image/png diff --git a/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-listen.js b/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-listen.js index 48681759624..0ee10f9be2c 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-listen.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-listen.js @@ -33,7 +33,8 @@ Command.prototype.execute = function() { } // Set up server this.server = $tw.mws.serverManager.createServer({ - wiki: $tw.wiki + wiki: $tw.wiki, + variables: self.params }); this.server.listen(null,null,null,{ callback: function() { diff --git a/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-test-server.js b/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-test-server.js index a0320e5a45d..ea7184e54f5 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-test-server.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/commands/mws-test-server.js @@ -74,6 +74,7 @@ TestRunner.prototype.runTests = function(callback) { }; TestRunner.prototype.runTest = function(testSpec,callback) { + const self = this; console.log(`Running Server Test: ${testSpec.description}`) if(testSpec.method === "GET" || testSpec.method === "POST") { const request = this.httpLibrary.request({ @@ -84,8 +85,8 @@ TestRunner.prototype.runTest = function(testSpec,callback) { method: testSpec.method, headers: testSpec.headers }, function(response) { - if (response.statusCode < 200 || response.statusCode >= 300) { - return callback(`Request failed to ${response.url} with status code ${response.statusCode} and ${JSON.stringify(response.headers)}`); + if (response.statusCode < 200 || response.statusCode >= 400) { + return callback(`Request failed to ${self.urlServerParsed.toString()} with status code ${response.statusCode} and ${JSON.stringify(response.headers)}`); } response.setEncoding("utf8"); let buffer = ""; @@ -94,7 +95,7 @@ TestRunner.prototype.runTest = function(testSpec,callback) { }); response.on("end", () => { const jsonData = $tw.utils.parseJSONSafe(buffer,function() {return undefined;}); - const testResult = testSpec.expectedResult(jsonData,buffer); + const testResult = testSpec.expectedResult(jsonData,buffer,response.headers); callback(testResult ? null : "Test failed"); }); }); @@ -135,6 +136,20 @@ const testSpecs = [ expectedResult: (jsonData,data) => { return jsonData["imported-tiddlers"] && $tw.utils.isArray(jsonData["imported-tiddlers"]) && jsonData["imported-tiddlers"][0] === "One White Pixel"; } + }, + { + description: "Create a recipe", + method: "POST", + path: "/recipes", + headers: { + "Accept": '*/*', + "Content-Type": 'application/x-www-form-urlencoded', + "User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' + }, + data: "recipe_name=Elephants3214234&bag_names=one%20two%20three&description=A%20bag%20of%20elephants", + expectedResult: (jsonData,data,headers) => { + return headers.location === "/"; + } } ]; diff --git a/plugins/tiddlywiki/multiwikiserver/modules/mws-server.js b/plugins/tiddlywiki/multiwikiserver/modules/mws-server.js index ec2bb1b8f4e..39e1492a92a 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/mws-server.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/mws-server.js @@ -316,7 +316,8 @@ Server.prototype.findMatchingRoute = function(request,state) { } else { match = potentialRoute.path.exec(pathname); } - if(match && request.method === potentialRoute.method) { + // Allow POST as a synonym for PUT because HTML doesn't allow PUT forms + if(match && (request.method === potentialRoute.method || (request.method === "POST" && potentialRoute.method === "PUT"))) { state.params = []; for(var p=1; p> class={{{ mws-bag-pill [match[yes]then[mws-bag-pill-topmost]] +[join[ ]] }}}> + encodeuricomponent[]] }$/bags/${ [encodeuricomponent[]] }$` rel="noopener noreferrer" target="_blank"> + encodeuricomponent[]] }$/bags/${ [encodeuricomponent[]] }$/tiddlers/%24%3A%2Ffavicon.ico` + class="mws-favicon-small" + /> + + <$text text=<>/> + + + +\end + ! Wikis Available Here -