-
-
Notifications
You must be signed in to change notification settings - Fork 994
feat: add runtime base path support #3405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
DoubleThePsycho
wants to merge
6
commits into
seerr-team:develop
from
DoubleThePsycho:feat/runtime-base-path
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1d5648d
feat: add runtime base path support
DoubleThePsycho f4be51e
fix: validate runtime base path
DoubleThePsycho 3c72819
fix: revalidate restart status after base path changes
DoubleThePsycho b97bb29
fix: revalidate restart status after network changes
DoubleThePsycho 5b9dec9
fix: refresh both status cache variants
DoubleThePsycho 08cc3f2
fix: refresh both status cache variants
DoubleThePsycho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { isValidBasePath, normalizeBasePath } from '@server/utils/basePath'; | ||
| import type { RequestHandler } from 'express'; | ||
|
|
||
| const validateNetworkBasePath: RequestHandler = (req, _res, next) => { | ||
| if ( | ||
| req.method !== 'POST' || | ||
| req.path !== '/network' || | ||
| !Object.prototype.hasOwnProperty.call(req.body ?? {}, 'basePath') | ||
| ) { | ||
| return next(); | ||
| } | ||
|
|
||
| if (!isValidBasePath(req.body.basePath)) { | ||
| return next({ | ||
| status: 400, | ||
| message: 'Invalid URL base path.', | ||
| }); | ||
| } | ||
|
|
||
| req.body.basePath = normalizeBasePath(req.body.basePath); | ||
| return next(); | ||
| }; | ||
|
|
||
| export default validateNetworkBasePath; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { appDataPath } from '@server/utils/appDataVolume'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| const SETTINGS_PATH = path.join(appDataPath(), 'settings.json'); | ||
| const BASE_PATH_PATTERN = /^(?:|\/[A-Za-z0-9._~-]+(?:\/[A-Za-z0-9._~-]+)*)$/; | ||
|
|
||
| export const normalizeBasePath = (value?: string): string => { | ||
| const normalized = value?.trim().replace(/^\/+|\/+$/g, '') ?? ''; | ||
|
|
||
| return normalized ? `/${normalized}` : ''; | ||
| }; | ||
|
|
||
| export const isValidBasePath = (value: unknown): value is string => | ||
| typeof value === 'string' && BASE_PATH_PATTERN.test(value); | ||
|
|
||
| const getStoredBasePath = (): string => { | ||
| try { | ||
| const settings = JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf-8')) as { | ||
| network?: { basePath?: string }; | ||
| }; | ||
|
|
||
| return normalizeBasePath(settings.network?.basePath); | ||
| } catch { | ||
| return ''; | ||
| } | ||
| }; | ||
|
|
||
| export const getRuntimeBasePath = (): string => { | ||
| const hasEnvironmentOverride = Object.prototype.hasOwnProperty.call( | ||
| process.env, | ||
| 'SEERR_BASE_PATH' | ||
| ); | ||
|
|
||
| return normalizeBasePath( | ||
| hasEnvironmentOverride ? process.env.SEERR_BASE_PATH : getStoredBasePath() | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.