Skip to content

Commit

Permalink
feat: disable sync if tidgi is in readOnlyMode
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Feb 10, 2024
1 parent 5b625e9 commit af1ba3b
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ exports.path = /^\/tw-mobile-sync\/sync$/;
// TODO: use this custom endpoint to handle conflict on server side
const handler: ServerEndpointHandler = function handler(request: Http.ClientRequest & Http.InformationEvent, response: Http.ServerResponse, context) {
response.setHeader('Access-Control-Allow-Origin', '*');
/**
* TidGi allow user to set read-only mode for server, and set this info tiddler for here to use to prevent user sync back to server.
*/
const readOnlyMode = context.wiki.getTiddlerText('$:/info/tidgi/readOnlyMode') === 'yes';
if (readOnlyMode) {
response.writeHead(403);
response.end(`Don't sync back to readonly server.`, 'utf8');
return;
}

try {
const data = $tw.utils.parseJSONSafe(context.data) as ISyncEndPointRequest;
Expand Down

0 comments on commit af1ba3b

Please sign in to comment.