Skip to content

Commit b29bd5f

Browse files
committed
Add .env option to remove auth wall from notedeck install instructions
Signed-off-by: Daniel D’Aquino <[email protected]>
1 parent 11c85d0 commit b29bd5f

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The Damus API backend for Damus Purple and other functionality.
1313
- `DB_PATH`: Path to the folder where to save mdb files.
1414
- `TESTFLIGHT_URL`: URL for the TestFlight app (optional)
1515
- `NOTEDECK_INSTALL_MD`: URL for the notedeck installation instructions markdown
16+
- `NO_AUTH_WALL_NOTEDECK_INSTALL`: Disables the authentication wall for the notedeck installation instructions when set to `"true"`.
1617

1718
#### Translations
1819

src/router_config.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -444,30 +444,27 @@ function config_router(app) {
444444
json_response(res, get_account_info_payload(user_id, account, true))
445445
return
446446
});
447-
448-
router.get('/notedeck-install-instructions', app.web_auth_manager.require_web_auth.bind(app.web_auth_manager), async (req, res) => {
449-
const pubkey = req.authorized_pubkey
450-
const { account, user_id } = get_account_and_user_id(app, pubkey)
451-
if (!account) {
452-
simple_response(res, 404)
453-
return
454-
}
455-
const account_info = get_account_info_payload(user_id, account, true)
456-
if(account_info.active == true) {
457-
const installInstructionsPath = path.resolve(process.env.NOTEDECK_INSTALL_MD);
458-
try {
459-
const installInstructions = fs.readFileSync(installInstructionsPath, { encoding: 'utf8' });
460-
json_response(res, { value: installInstructions });
461-
return
462-
} catch (err) {
463-
console.log(err);
464-
error("Failed to read file: %s", err.toString());
465-
error_response(res, 'Failed to load installation instructions');
447+
448+
if(process.env.NO_AUTH_WALL_NOTEDECK_INSTALL == "true") {
449+
router.get('/notedeck-install-instructions', async (req, res) => {
450+
provide_notedeck_instructions(req, res)
451+
});
452+
}
453+
else {
454+
router.get('/notedeck-install-instructions', app.web_auth_manager.require_web_auth.bind(app.web_auth_manager), async (req, res) => {
455+
const pubkey = req.authorized_pubkey
456+
const { account, user_id } = get_account_and_user_id(app, pubkey)
457+
if (!account) {
458+
simple_response(res, 401)
466459
return
467460
}
468-
}
469-
return
470-
});
461+
const account_info = get_account_info_payload(user_id, account, true)
462+
if(account_info.active == true) {
463+
provide_notedeck_instructions(req, res)
464+
}
465+
return
466+
});
467+
}
471468

472469
// MARK: Admin routes
473470

@@ -684,4 +681,18 @@ function get_allowed_cors_origins() {
684681
}
685682
}
686683

684+
async function provide_notedeck_instructions(req, res) {
685+
const installInstructionsPath = path.resolve(process.env.NOTEDECK_INSTALL_MD);
686+
try {
687+
const installInstructions = fs.readFileSync(installInstructionsPath, { encoding: 'utf8' });
688+
json_response(res, { value: installInstructions });
689+
return
690+
} catch (err) {
691+
console.log(err);
692+
error("Failed to read file: %s", err.toString());
693+
error_response(res, 'Failed to load installation instructions');
694+
return
695+
}
696+
}
697+
687698
module.exports = { config_router }

0 commit comments

Comments
 (0)