refactor: remove "cleanUrl" related code for now

that should be part of a later PR
This commit is contained in:
Panagiotis Papadopoulos
2025-04-25 08:27:01 +02:00
parent 00b5aef890
commit 43166dbeb5
7 changed files with 9 additions and 105 deletions

View File

@@ -39,20 +39,11 @@ const TPL = /*html*/`
</div>
</div>
<div class="form-group">
<label class="tn-checkbox">
<input class="form-check-input use-clean-urls" type="checkbox" name="useCleanUrls" value="true">
${t("share.use_clean_urls")}
</label>
<p class="form-text">${t("share.use_clean_urls_description")}</p>
</div>
</div>`;
export default class ShareSettingsOptions extends OptionsWidget {
private $redirectBareDomain!: JQuery<HTMLInputElement>;
private $showLoginInShareTheme!: JQuery<HTMLInputElement>;
private $useCleanUrls!: JQuery<HTMLInputElement>;
private $sharePath!: JQuery<HTMLInputElement>;
private $shareRootCheck!: JQuery<HTMLElement>;
private $shareRootStatus!: JQuery<HTMLElement>;
@@ -63,7 +54,6 @@ export default class ShareSettingsOptions extends OptionsWidget {
this.$redirectBareDomain = this.$widget.find(".redirect-bare-domain");
this.$showLoginInShareTheme = this.$widget.find(".show-login-in-share-theme");
this.$useCleanUrls = this.$widget.find(".use-clean-urls");
this.$sharePath = this.$widget.find(".share-path");
this.$shareRootCheck = this.$widget.find(".share-root-check");
this.$shareRootStatus = this.$widget.find(".share-root-status");
@@ -82,11 +72,6 @@ export default class ShareSettingsOptions extends OptionsWidget {
await this.updateOption<"showLoginInShareTheme">("showLoginInShareTheme", showLoginInShareTheme.toString());
});
this.$useCleanUrls.on('change', async () => {
const useCleanUrls = this.$useCleanUrls.is(":checked");
await this.updateOption<"useCleanUrls">("useCleanUrls", useCleanUrls.toString());
});
this.$sharePath.on('change', async () => {
const DEFAULT_SHAREPATH = "/share";
const sharePathInput = this.$sharePath.val()?.trim() || "";
@@ -122,7 +107,6 @@ export default class ShareSettingsOptions extends OptionsWidget {
this.$shareRootCheck.toggle(redirectBareDomain);
this.$showLoginInShareTheme.prop("checked", options.showLoginInShareTheme === "true");
this.$useCleanUrls.prop("checked", options.useCleanUrls === "true");
this.$sharePath.val(options.sharePath);
}

View File

@@ -83,7 +83,6 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"redirectBareDomain",
"showLoginInShareTheme",
"shareSubtree",
"useCleanUrls",
"sharePath",
"splitEditorOrientation",

View File

@@ -105,8 +105,6 @@ const uploadMiddlewareWithErrorHandling = function (req: express.Request, res: e
};
function register(app: express.Application) {
// @pano9000: comment out for now to fix other functionality first
//app.use(auth.checkCleanUrl);
route(GET, "/", [auth.checkAuth, csrfMiddleware], indexRoute.index);
route(GET, "/login", [auth.checkAppInitialized, auth.checkPasswordSet], loginRoute.loginPage);

View File

@@ -74,47 +74,6 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {
}
}
/**
* Checks if a URL path might be a shared note ID when clean URLs are enabled
*/
function checkCleanUrl(req: Request, res: Response, next: NextFunction) {
// Only process if not logged in and clean URLs are enabled
if (!req.session.loggedIn && !isElectron && !noAuthentication &&
options.getOptionOrNull("redirectBareDomain") === "true" &&
options.getOptionOrNull("useCleanUrls") === "true") {
// Get the configured share path
const sharePath = options.getOption("sharePath") || '/share';
// Get path without leading slash
const path = req.path.substring(1);
// Skip processing for known routes, empty paths, and paths that already start with sharePath
if (!path ||
path === 'login' ||
path === 'setup' ||
path.startsWith('api/') ||
req.path === sharePath ||
req.path.startsWith(`${sharePath}/`)) {
log.info(`checkCleanUrl: Skipping redirect. Path: ${req.path}, SharePath: ${sharePath}`);
next();
return;
}
// If sharePath is just '/', we don't need to redirect
if (sharePath === '/') {
log.info(`checkCleanUrl: SharePath is root, skipping redirect. Path: ${req.path}`);
next();
return;
}
// Redirect to the share URL with this ID
log.info(`checkCleanUrl: Redirecting to share path. From: ${req.path}, To: ${sharePath}/${path}`);
res.redirect(`${sharePath}/${path}`);
} else {
next();
}
}
/**
* Middleware for API authentication - works for both sync and normal API
@@ -216,7 +175,6 @@ function checkCredentials(req: Request, res: Response, next: NextFunction) {
export default {
checkAuth,
checkCleanUrl,
checkApiAuth,
checkAppInitialized,
checkPasswordSet,

View File

@@ -186,7 +186,6 @@ const defaultOptions: DefaultOption[] = [
},
{ name: "redirectBareDomain", value: "false", isSynced: true },
{ name: "showLoginInShareTheme", value: "false", isSynced: true },
{ name: "useCleanUrls", value: "false", isSynced: true },
{ name: "shareSubtree", value: "false", isSynced: true },
// AI Options

View File

@@ -122,7 +122,6 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
redirectBareDomain: boolean;
showLoginInShareTheme: boolean;
shareSubtree: boolean;
useCleanUrls: boolean;
sharePath: string;
// AI/LLM integration options

View File

@@ -203,53 +203,20 @@ function register(router: Router) {
}
}
const sharePath = options.getOptionOrNull("sharePath") || '/share';
const sharePath = options.getOptionOrNull("sharePath") || "/share";
// Handle root path specially
if (sharePath === '/') {
router.get('/', (req, res, next) => {
shacaLoader.ensureLoad();
router.get(`${sharePath}/`, (req, res, next) => {
if (!shaca.shareRootNote) {
res.status(404).json({ message: "Share root not found" });
return;
}
shacaLoader.ensureLoad();
renderNote(shaca.shareRootNote, req, res);
});
} else {
if (!shaca.shareRootNote) {
res.status(404).json({ message: "Share root not found" });
return;
}
router.get(`${sharePath}/`, (req, res, next) => {
renderNote(shaca.shareRootNote, req, res);
});
shacaLoader.ensureLoad();
if (!shaca.shareRootNote) {
res.status(404).json({ message: "Share root not found" });
return;
}
renderNote(shaca.shareRootNote, req, res);
});
}
if (sharePath === '/' && options.getOptionBool("useCleanUrls") && options.getOptionBool("redirectBareDomain")) {
router.get("/:shareId", (req, res, next) => {
shacaLoader.ensureLoad();
const { shareId } = req.params;
// Skip processing for known routes
if (shareId === 'login' || shareId === 'setup' || shareId.startsWith('api/')) {
next();
return;
}
const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];
renderNote(note, req, res);
});
}
router.get(`${sharePath}/:shareId`, (req, res, next) => {
shacaLoader.ensureLoad();