mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
fix: make sure no HTTP put work on readOnlyMode
This commit is contained in:
parent
fae5143a50
commit
3388dacb5a
2 changed files with 12 additions and 2 deletions
|
|
@ -26,6 +26,11 @@ export interface IWikiServerRouteResponse {
|
|||
export class IpcServerRoutes {
|
||||
private wikiInstance!: ITiddlyWiki;
|
||||
private readonly pendingIpcServerRoutesRequests: Array<(value: void | PromiseLike<void>) => void> = [];
|
||||
#readonlyMode = false;
|
||||
|
||||
setConfig({ readOnlyMode }: { readOnlyMode?: boolean }) {
|
||||
this.#readonlyMode = Boolean(readOnlyMode);
|
||||
}
|
||||
|
||||
setWikiInstance(wikiInstance: ITiddlyWiki) {
|
||||
this.wikiInstance = wikiInstance;
|
||||
|
|
@ -95,7 +100,7 @@ export class IpcServerRoutes {
|
|||
const data: IWikiServerStatusObject = {
|
||||
username: userName,
|
||||
anonymous: false,
|
||||
read_only: false,
|
||||
read_only: this.#readonlyMode,
|
||||
space: {
|
||||
recipe: 'default',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -78,7 +78,11 @@ export function startNodeJSWiki({
|
|||
*
|
||||
* @url https://wiki.zhiheng.io/static/TiddlyWiki%253A%2520Readonly%2520for%2520Node.js%2520Server.html
|
||||
*/
|
||||
const readonlyArguments = readOnlyMode === true ? ['gzip=yes', 'readers=(anon)', `writers=${userName}`, `username=${userName}`, `password=${nanoid()}`] : [];
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||
const readonlyArguments = readOnlyMode === true ? ['gzip=yes', 'readers=(anon)', `writers=${userName || nanoid()}`, `username=${userName}`, `password=${nanoid()}`] : [];
|
||||
if (readOnlyMode === true) {
|
||||
wikiInstance.preloadTiddler({ title: '$:/info/tidgi/readOnlyMode', text: 'yes' });
|
||||
}
|
||||
/**
|
||||
* Use authenticated-user-header to provide `TIDGI_AUTH_TOKEN_HEADER` as header key to receive a value as username (we use it as token).
|
||||
*
|
||||
|
|
@ -151,6 +155,7 @@ export function startNodeJSWiki({
|
|||
});
|
||||
wikiInstance.boot.startup({ bootPath: TIDDLYWIKI_PACKAGE_FOLDER });
|
||||
// after setWikiInstance, ipc server routes will start serving content
|
||||
ipcServerRoutes.setConfig({ readOnlyMode });
|
||||
ipcServerRoutes.setWikiInstance(wikiInstance);
|
||||
wikiOperationsInWikiWorker.setWikiInstance(wikiInstance);
|
||||
observer.next({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue