Skip to content

Commit

Permalink
added updated http api, some refactoring and other updates
Browse files Browse the repository at this point in the history
  • Loading branch information
inmysocks committed Oct 12, 2020
1 parent 2e01d76 commit 61bfcd8
Show file tree
Hide file tree
Showing 64 changed files with 2,062 additions and 992 deletions.
6 changes: 5 additions & 1 deletion Changelog.tid
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ title: $:/plugins/OokTech/Bob/Changelog

* Fixed a regression that would prevent websocket connections if the wiki had a space in its name.
* Add a `/api/status` http route that returns settings and other wiki information
* Switched to using the `/api/status` route to set up wikis instead of the setLoggedIn websocket message to make behaviour more predictable and prevent some race conditions
* Switched to using the `/api/status` route to get wiki settings instead of the setLoggedIn websocket message to make behaviour more predictable and prevent some race conditions
* Lots of refactoring and cleanup on the wiki management functions in the back-end
* You no longer need to click a button to see the available plugins/themes/editions/languages on the server. If any new ones are added while you have a wiki open you need to either refresh the page (the reload button on your browser, nothing special) or refresh the settings.
* Big update to the http api routes
* Documented the http api

!! Version 1.6.1 Scream in your heart

Expand Down
2 changes: 1 addition & 1 deletion ConflictList.tid
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
caption: Conflict List
title: $:/plugins/Bob/ConflictList
title: $:/plugins/OokTech/Bob/ConflictList

These are the tiddlers that currently have conflicts from resyncing with the server:

Expand Down
2 changes: 1 addition & 1 deletion ControlPanel/HelpMessages/AboutPersistentUsernames.tid
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title: $:/plugins/Bob/AboutPersistentUsernames
title: $:/plugins/OokTech/Bob/AboutPersistentUsernames

If you check this box you will be able to set the username for signing edits on
the wiki and it will be saved for this browser.
Expand Down
2 changes: 1 addition & 1 deletion ControlPanel/ThisWikiTab.tid
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ caption: This Wiki
default="no"
>
Use Persistent Usernames
</$checkbox> <<helpButton "$:/plugins/Bob/AboutPersistentUsernames">>
</$checkbox> <<helpButton "$:/plugins/OokTech/Bob/AboutPersistentUsernames">>

You can set which plugins and themes are installed on this wiki here.
Installing plugins this way is not the same as dragging and dropping plugins
Expand Down
9 changes: 4 additions & 5 deletions ControlPanel/ThisWikiTab/SelectPlugins.tid
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Select Plugin Author: <$select
All
</option>
<$list
afilter='[list[$:/Bob/AvailablePluginList]splitbefore[/]]'
filter='[[$:/Bob/AvailablePluginList]indexes[]splitbefore[/]]'
filter='[list[$:/Bob/AvailablePluginList!!text]splitbefore[/]]'
variable='pluginAuthor'
>
<option>
Expand All @@ -53,7 +52,7 @@ Search: <$edit-text
>
<h2><$text text=<<pluginAuthor>>></$text></h2>
<$list
filter='[[$:/Bob/AvailablePluginList]indexes[]search{$:/state/Bob/SearchPlugins}prefix<pluginAuthor>]'
filter='[list[$:/Bob/AvailablePluginList!!text]search{$:/state/Bob/SearchPlugins}prefix<pluginAuthor>]'
>
<$list
filter='[list[$:/Bob/ActivePluginList]match<currentTiddler>]'
Expand Down Expand Up @@ -108,12 +107,12 @@ Search: <$edit-text
variable='unused'
>
<$list
filter='[[$:/Bob/AvailablePluginList]indexes[]splitbefore[/]]'
filter='[list[$:/Bob/AvailablePluginList!!text]splitbefore[/]]'
variable='pluginAuthor'
>
<h2><$text text=<<pluginAuthor>>></$text></h2>
<$list
filter='[[$:/Bob/AvailablePluginList]indexes[]prefix<pluginAuthor>search{$:/state/Bob/SearchPlugins}]'
filter='[list[$:/Bob/AvailablePluginList!!text]prefix<pluginAuthor>search{$:/state/Bob/SearchPlugins}]'
>
<$list
filter='[list[$:/Bob/ActivePluginList]match<currentTiddler>]'
Expand Down
12 changes: 6 additions & 6 deletions ControlPanel/ThisWikiTab/SelectThemes.tid
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Select Theme Author: <$select
All
</option>
<$list
filter='[[$:/Bob/AvailableThemeList]indexes[]splitbefore[/]]'
filter='[list[$:/Bob/AvailableThemeList!!text]splitbefore[/]]'
variable='themeAuthor'
>
<option>
Expand All @@ -52,10 +52,10 @@ Search: <$edit-text
>
<h2><$text text=<<themeAuthor>>></$text></h2>
<$list
filter='[[$:/Bob/AvailableThemeList]indexes[]search{$:/state/Bob/SearchThemes}prefix<themeAuthor>]'
filter='[list[$:/Bob/AvailableThemeList!!text]search{$:/state/Bob/SearchThemes}prefix<themeAuthor>]'
>
<$list
filter='[list[$:/Bob/ActiveThemeList]is[current]]'
filter='[list[$:/Bob/ActiveThemeList]match<currentTiddler>]'
emptyMessage="""
<$button
class='tc-btn-invisible'
Expand Down Expand Up @@ -107,15 +107,15 @@ Search: <$edit-text
variable='unused'
>
<$list
filter='[[$:/Bob/AvailableThemeList]indexes[]splitbefore[/]]'
filter='[list[$:/Bob/AvailableThemeList!!text]splitbefore[/]]'
variable='themeAuthor'
>
<h2><$text text=<<themeAuthor>>></$text></h2>
<$list
filter='[[$:/Bob/AvailableThemeList]indexes[]search{$:/state/Bob/SearchThemes}prefix<themeAuthor>]'
filter='[list[$:/Bob/AvailableThemeList!!text]search{$:/state/Bob/SearchThemes}prefix<themeAuthor>]'
>
<$list
filter='[list[$:/Bob/ActiveThemeList]is[current]]'
filter='[list[$:/Bob/ActiveThemeList]match<currentTiddler>]'
emptyMessage="""
<$button
class='tc-btn-invisible'
Expand Down
16 changes: 16 additions & 0 deletions Documentation/HTTPAPI/get-favicon.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-favicon
tags: [[HTTP API]]
verb: GET
route: /favicon.ico /:wikiName/favicon.ico
response: The contents of the tiddler `$:/favicon.ico` as a base64 encoded string
parameters:
description: load a wikis favicon

Sends the favicon for the wiki `:wikiName`, the rouse `/favicon.ico` returns
the favicon for the root wiki. If `:wikiName` has any `/` characters they are
preserved in the path.

Example Routes:

* `/favicon.ico`
* `/Wiki/Name/favicon.ico`
39 changes: 39 additions & 0 deletions Documentation/HTTPAPI/get-fetch-list.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/fetch-list
tags: [[HTTP API]]
verb: GET
route: /api/fetch/list
response: A JSON object containing a list of tiddler titles and optionally additional fields from the tiddlers
parameters: `wiki` `filter` `fields`
description: fetch a list of tiddler titles from a wiki using a filter

Requests a list of tiddler titles selected using a filter evaluated in a named
wiki.

The url parameters are:

* `wiki` is the name of the wiki to fetch titles from, it must be url encoded if it has spaces or `/` characters
* `filter` is the filter to run in the target wiki
* `fields` is a comma separated list of fields that are returned in the `info` part of the returned object. Defaults to `modified`

The returned JSON object has the form:

```
{
list: [tiddler1, tiddler2],
info: {
tiddler1: {
field1: "field value",
field2: "field2 value"
},
tiddler2: {
field1: "other field value",
field2: "other field2 value"
}
}
}
```

Examples:

* `/api/fetch/list?wiki=SomeWiki&filter=[tag[foo]]`
* `/api/fetch/list?wiki=SomeOtherWiki&filter=[tag[bar]]`
17 changes: 17 additions & 0 deletions Documentation/HTTPAPI/get-fetch-plugin.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/fetch-plugin
tags: [[HTTP API]]
verb: GET
route: /api/fetch/plugins/:plugin
response: The plugin tiddler as JSON
parameters:
description: fetch a plugin from the server

The requested plugin is returned as JSON.
To use this route the `pluginLibrary` key in the `API` section of the settings
must be set to `yes`.

The `:plugin` part of the path should be in the from `Author/PluginName`.

Example:

* `/api/fetch/plugins/OokTech/Bob`
13 changes: 13 additions & 0 deletions Documentation/HTTPAPI/get-fetch-tiddler-html.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-fetch-tiddler-html
tags: [[HTTP API]]
verb: GET
route: /api/fetch/tiddler/html
response: The rendered html of the requested tiddler
parameters: `wiki` `tiddler`
description: get the rendered html of a tiddler

Get the rendered html version of a tiddler.

Example:

* `/api/fetch/tiddler/html?wiki=SomeWiki&tiddler=tiddlerTitle`
24 changes: 24 additions & 0 deletions Documentation/HTTPAPI/get-fetch-tiddlers.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-fetch-tiddlers
tags: [[HTTP API]]
verb: GET
route: /api/fetch
response: Tiddlers in JSON format
parameters: `wiki` `filter` `tiddler`
description: fetch tiddlers from the server

Return a tiddler by title, or a set of tiddlers using a filter, from the named
wiki.

If both `filter` and `tiddler` are present the filter is used and the tiddler
title is ignored.

Parameters:

* `wiki` the wiki to fetch the tiddlers from
* `filter` the filter to evaluate in the wiki to select tiddlers to fetch
* `tiddler` the title of a single tiddler to return

Examples:

* `/api/fetch?wiki=someWiki&filter=[tag[foo]]`
* `/api/fetch?wiki=someOtherWiki&tiddler=tiddlerTitle`
20 changes: 20 additions & 0 deletions Documentation/HTTPAPI/get-files.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-files
tags: [[HTTP API]]
verb: GET
route: /files/:filename /:wikiName/files/:filename
response: The named file in binary format
parameters:
description: load a media file from the server

If the `/files/:filename` path is used the files are taken from the globally
available files in the folder given by the file path root.
If the `/:wikiName/files/:filename` path is used the files are taken from the
`files` folder specific to the wiki `:wikiName`.

If the `perWikiFiles` setting is set to `yes` wiki specific files are only
available in the wiki associated with them.

Examples:

* `/files/foo.jpg`
* `/someWiki/files/bar.png`
37 changes: 37 additions & 0 deletions Documentation/HTTPAPI/get-list-files.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-list-files
tags: [[HTTP API]]
verb: GET
route: /api/list/files /api/list/files/path/:prefix /api/list/files/wiki/:wikiname
response: JSON object with a list of globally available files
parameters:
description: get a list of available files on the server

Using the `/api/list/files/` path the list of files returned is from the folder
listed as the `filePathRoot`.

Using the `/api/list/files/path/:prefix` path returns the list of files served
using the prefix `:prefix`.

Using the `/api/list/files/wiki/:wikiname` path returns the files specific to
the wiki `:wikiname`. These files are in the `files` folder next to the
`tiddlers` folder for the wiki.

This does not list files in sub-folders.

The response object is in the form:

```
{
prefix: "/files/",
files: ["file1.png", "file2.jpg"]
}
```

The value to put in the `_canonical_uri` field to access the file is the prefix
appended to the front of the file name, like `/files/file1.png`.

Example:

* `/api/list/files`
* `/api/list/files/path/foo`
* `/api/list/files/wiki/someWiki`
35 changes: 35 additions & 0 deletions Documentation/HTTPAPI/get-list-plugins.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-list-plugins
tags: [[HTTP API]]
verb: GET
route: /api/list/plugins
response: An array of JSON objects that contain information about the available plugins
parameters:
description: get a list of available plugins

Return a list of JSON objects that each contain metadata for an available
plugin.

The retuned object is in the form:

```
[
{
name: "OokTec/Bob",
description: "plugin description",
version: "0.0.0",
tiddlerName: "$:/plugins/OokTech/Bob",
readme: "Readme text"
},
{
name: "OokTec/Login",
description: "plugin description",
version: "0.0.0",
tiddlerName: "$:/plugins/OokTech/Login",
readme: "Readme text"
}
]
```

Example:

* `/api/list/plugins`
19 changes: 19 additions & 0 deletions Documentation/HTTPAPI/get-list-wikis.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-list-wikis
tags: [[HTTP API]]
verb: GET
route: /api/list/wikis
response: A JSON object containing a list of available wikis
parameters:
description: get a list of available wikis

The returned object is in the form:

```
{
wikis: ["Wiki1", "Wiki2"]
}
```

Example:

* `/api/list/wikis`
35 changes: 35 additions & 0 deletions Documentation/HTTPAPI/get-status.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
title: $:/plugins/OokTech/Bob/Documentation/HTTPAPI/get-status
tags: [[HTTP API]]
verb: GET
route: /api/status
response: A JSON object containing status information about the server
parameters:
description: get server status information

The returned status is used to get sever settings in opened wikis.

The fields `logged_in`, `username`, `authentication_level` and `read_only`
currently have no meaning.

The returned JSON object is in the form:

```
{
logged_in: false,
username: "",
authentication_level: "Guest",
tiddlywiki_version: 5.1.22,
bob_version: 1.6.2,
read_only: false,
available_wikis: ["wiki1", "wiki2"],
available_themes: ["theme1", "theme2"],
available_plugins: ["OokTech/Bob", "OokTech/Login"],
available_editions: ["edition1", "edition2"],
available_languages: ["language1", "language2"],
settings: {/* The full server settings */}
}
```

Example:

* `/api/status`
Loading

0 comments on commit 61bfcd8

Please sign in to comment.