mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Setup tweaks (#4304)
This commit is contained in:
parent
b915428f06
commit
fc1fc20df4
1 changed files with 244 additions and 240 deletions
|
|
@ -34,7 +34,7 @@ export const Setup: React.FC = () => {
|
||||||
const [saveUI] = useConfigureUI();
|
const [saveUI] = useConfigureUI();
|
||||||
|
|
||||||
const [step, setStep] = useState(0);
|
const [step, setStep] = useState(0);
|
||||||
const [configLocation, setConfigLocation] = useState("");
|
const [setupInWorkDir, setSetupInWorkDir] = useState(false);
|
||||||
const [stashes, setStashes] = useState<GQL.StashConfig[]>([]);
|
const [stashes, setStashes] = useState<GQL.StashConfig[]>([]);
|
||||||
const [showStashAlert, setShowStashAlert] = useState(false);
|
const [showStashAlert, setShowStashAlert] = useState(false);
|
||||||
const [databaseFile, setDatabaseFile] = useState("");
|
const [databaseFile, setDatabaseFile] = useState("");
|
||||||
|
|
@ -65,6 +65,13 @@ export const Setup: React.FC = () => {
|
||||||
return paths.join(pathSep);
|
return paths.join(pathSep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simply returns everything preceding the last path separator
|
||||||
|
function pathDir(path: string) {
|
||||||
|
const lastSep = path.lastIndexOf(pathSep);
|
||||||
|
if (lastSep === -1) return "";
|
||||||
|
return path.slice(0, lastSep);
|
||||||
|
}
|
||||||
|
|
||||||
const workingDir = status?.workingDir ?? ".";
|
const workingDir = status?.workingDir ?? ".";
|
||||||
|
|
||||||
// When running Stash.app, the working directory is (usually) set to /.
|
// When running Stash.app, the working directory is (usually) set to /.
|
||||||
|
|
@ -75,15 +82,15 @@ export const Setup: React.FC = () => {
|
||||||
const fallbackStashDir = pathJoin(homeDir, ".stash");
|
const fallbackStashDir = pathJoin(homeDir, ".stash");
|
||||||
const fallbackConfigPath = pathJoin(fallbackStashDir, "config.yml");
|
const fallbackConfigPath = pathJoin(fallbackStashDir, "config.yml");
|
||||||
|
|
||||||
useEffect(() => {
|
const overrideConfig = status?.configPath;
|
||||||
if (status?.configPath) {
|
const overrideGenerated = configuration?.general.generatedPath;
|
||||||
setConfigLocation(status.configPath);
|
const overrideCache = configuration?.general.cachePath;
|
||||||
}
|
const overrideBlobs = configuration?.general.blobsPath;
|
||||||
}, [status?.configPath]);
|
const overrideDatabase = configuration?.general.databasePath;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (configuration) {
|
if (configuration) {
|
||||||
const { stashes: configStashes, generatedPath } = configuration.general;
|
const configStashes = configuration.general.stashes;
|
||||||
if (configStashes.length > 0) {
|
if (configStashes.length > 0) {
|
||||||
setStashes(
|
setStashes(
|
||||||
configStashes.map((s) => {
|
configStashes.map((s) => {
|
||||||
|
|
@ -92,9 +99,6 @@ export const Setup: React.FC = () => {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (generatedPath) {
|
|
||||||
setGeneratedLocation(generatedPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [configuration]);
|
}, [configuration]);
|
||||||
|
|
||||||
|
|
@ -113,8 +117,8 @@ export const Setup: React.FC = () => {
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
|
||||||
function onConfigLocationChosen(loc: string) {
|
function onConfigLocationChosen(inWorkDir: boolean) {
|
||||||
setConfigLocation(loc);
|
setSetupInWorkDir(inWorkDir);
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,7 +183,7 @@ export const Setup: React.FC = () => {
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id="setup.welcome_specific_config.config_path"
|
id="setup.welcome_specific_config.config_path"
|
||||||
values={{
|
values={{
|
||||||
path: configLocation,
|
path: overrideConfig,
|
||||||
code: (chunks: string) => <code>{chunks}</code>,
|
code: (chunks: string) => <code>{chunks}</code>,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
@ -242,7 +246,7 @@ export const Setup: React.FC = () => {
|
||||||
<div className="d-flex justify-content-center">
|
<div className="d-flex justify-content-center">
|
||||||
<Button
|
<Button
|
||||||
variant="secondary mx-2 p-5"
|
variant="secondary mx-2 p-5"
|
||||||
onClick={() => onConfigLocationChosen("")}
|
onClick={() => onConfigLocationChosen(false)}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id="setup.welcome.in_current_stash_directory"
|
id="setup.welcome.in_current_stash_directory"
|
||||||
|
|
@ -256,7 +260,7 @@ export const Setup: React.FC = () => {
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary mx-2 p-5"
|
variant="secondary mx-2 p-5"
|
||||||
onClick={() => onConfigLocationChosen("config.yml")}
|
onClick={() => onConfigLocationChosen(true)}
|
||||||
disabled={macApp}
|
disabled={macApp}
|
||||||
>
|
>
|
||||||
{macApp ? (
|
{macApp ? (
|
||||||
|
|
@ -331,8 +335,44 @@ export const Setup: React.FC = () => {
|
||||||
return <FolderSelectDialog onClose={onBlobsClosed} />;
|
return <FolderSelectDialog onClose={onBlobsClosed} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeRenderDatabase() {
|
||||||
|
if (overrideDatabase) return;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form.Group id="database">
|
||||||
|
<h3>
|
||||||
|
<FormattedMessage id="setup.paths.where_can_stash_store_its_database" />
|
||||||
|
</h3>
|
||||||
|
<p>
|
||||||
|
<FormattedMessage
|
||||||
|
id="setup.paths.where_can_stash_store_its_database_description"
|
||||||
|
values={{
|
||||||
|
code: (chunks: string) => <code>{chunks}</code>,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<br />
|
||||||
|
<FormattedMessage
|
||||||
|
id="setup.paths.where_can_stash_store_its_database_warning"
|
||||||
|
values={{
|
||||||
|
strong: (chunks: string) => <strong>{chunks}</strong>,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
<Form.Control
|
||||||
|
className="text-input"
|
||||||
|
defaultValue={databaseFile}
|
||||||
|
placeholder={intl.formatMessage({
|
||||||
|
id: "setup.paths.database_filename_empty_for_default",
|
||||||
|
})}
|
||||||
|
onChange={(e) => setDatabaseFile(e.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function maybeRenderGenerated() {
|
function maybeRenderGenerated() {
|
||||||
if (!configuration?.general.generatedPath) {
|
if (overrideGenerated) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form.Group id="generated">
|
<Form.Group id="generated">
|
||||||
<h3>
|
<h3>
|
||||||
|
|
@ -353,9 +393,7 @@ export const Setup: React.FC = () => {
|
||||||
placeholder={intl.formatMessage({
|
placeholder={intl.formatMessage({
|
||||||
id: "setup.paths.path_to_generated_directory_empty_for_default",
|
id: "setup.paths.path_to_generated_directory_empty_for_default",
|
||||||
})}
|
})}
|
||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
onChange={(e) => setGeneratedLocation(e.currentTarget.value)}
|
||||||
setGeneratedLocation(e.currentTarget.value)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<InputGroup.Append>
|
<InputGroup.Append>
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -370,7 +408,6 @@ export const Setup: React.FC = () => {
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function onCacheSelectClosed(d?: string) {
|
function onCacheSelectClosed(d?: string) {
|
||||||
if (d) {
|
if (d) {
|
||||||
|
|
@ -389,7 +426,8 @@ export const Setup: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeRenderCache() {
|
function maybeRenderCache() {
|
||||||
if (!configuration?.general.cachePath) {
|
if (overrideCache) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form.Group id="cache">
|
<Form.Group id="cache">
|
||||||
<h3>
|
<h3>
|
||||||
|
|
@ -410,9 +448,7 @@ export const Setup: React.FC = () => {
|
||||||
placeholder={intl.formatMessage({
|
placeholder={intl.formatMessage({
|
||||||
id: "setup.paths.path_to_cache_directory_empty_for_default",
|
id: "setup.paths.path_to_cache_directory_empty_for_default",
|
||||||
})}
|
})}
|
||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
onChange={(e) => setCacheLocation(e.currentTarget.value)}
|
||||||
setCacheLocation(e.currentTarget.value)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<InputGroup.Append>
|
<InputGroup.Append>
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -427,10 +463,10 @@ export const Setup: React.FC = () => {
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function maybeRenderBlobs() {
|
function maybeRenderBlobs() {
|
||||||
if (!configuration?.general.blobsPath) {
|
if (overrideBlobs) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form.Group id="blobs">
|
<Form.Group id="blobs">
|
||||||
<h3>
|
<h3>
|
||||||
|
|
@ -473,9 +509,7 @@ export const Setup: React.FC = () => {
|
||||||
placeholder={intl.formatMessage({
|
placeholder={intl.formatMessage({
|
||||||
id: "setup.paths.path_to_blobs_directory_empty_for_default",
|
id: "setup.paths.path_to_blobs_directory_empty_for_default",
|
||||||
})}
|
})}
|
||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
onChange={(e) => setBlobsLocation(e.currentTarget.value)}
|
||||||
setBlobsLocation(e.currentTarget.value)
|
|
||||||
}
|
|
||||||
disabled={storeBlobsInDatabase}
|
disabled={storeBlobsInDatabase}
|
||||||
/>
|
/>
|
||||||
<InputGroup.Append>
|
<InputGroup.Append>
|
||||||
|
|
@ -493,7 +527,6 @@ export const Setup: React.FC = () => {
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function renderSetPaths() {
|
function renderSetPaths() {
|
||||||
return (
|
return (
|
||||||
|
|
@ -522,36 +555,7 @@ export const Setup: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Group id="database">
|
{maybeRenderDatabase()}
|
||||||
<h3>
|
|
||||||
<FormattedMessage id="setup.paths.where_can_stash_store_its_database" />
|
|
||||||
</h3>
|
|
||||||
<p>
|
|
||||||
<FormattedMessage
|
|
||||||
id="setup.paths.where_can_stash_store_its_database_description"
|
|
||||||
values={{
|
|
||||||
code: (chunks: string) => <code>{chunks}</code>,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<br />
|
|
||||||
<FormattedMessage
|
|
||||||
id="setup.paths.where_can_stash_store_its_database_warning"
|
|
||||||
values={{
|
|
||||||
strong: (chunks: string) => <strong>{chunks}</strong>,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
<Form.Control
|
|
||||||
className="text-input"
|
|
||||||
defaultValue={databaseFile}
|
|
||||||
placeholder={intl.formatMessage({
|
|
||||||
id: "setup.paths.database_filename_empty_for_default",
|
|
||||||
})}
|
|
||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
|
||||||
setDatabaseFile(e.currentTarget.value)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Form.Group>
|
|
||||||
{maybeRenderGenerated()}
|
{maybeRenderGenerated()}
|
||||||
{maybeRenderCache()}
|
{maybeRenderCache()}
|
||||||
{maybeRenderBlobs()}
|
{maybeRenderBlobs()}
|
||||||
|
|
@ -587,6 +591,11 @@ export const Setup: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onSave() {
|
async function onSave() {
|
||||||
|
let configLocation = overrideConfig;
|
||||||
|
if (!configLocation) {
|
||||||
|
configLocation = setupInWorkDir ? "config.yml" : "";
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await mutateSetup({
|
await mutateSetup({
|
||||||
|
|
@ -616,40 +625,22 @@ export const Setup: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderConfirm() {
|
function renderConfirm() {
|
||||||
let cfgPath = "";
|
let cfgDir: string;
|
||||||
let config = configLocation;
|
let config: string;
|
||||||
if (configLocation === "config.yml") {
|
if (overrideConfig) {
|
||||||
cfgPath = pwd;
|
cfgDir = pathDir(overrideConfig);
|
||||||
config = pathJoin(cfgPath, "config.yml");
|
config = overrideConfig;
|
||||||
} else if (configLocation === "") {
|
|
||||||
cfgPath = fallbackStashDir;
|
|
||||||
config = pathJoin(cfgPath, "config.yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
let database = databaseFile;
|
|
||||||
if (database === "") {
|
|
||||||
database = pathJoin(cfgPath, "stash-go.sqlite");
|
|
||||||
}
|
|
||||||
|
|
||||||
let generated = generatedLocation;
|
|
||||||
if (generated === "") {
|
|
||||||
generated = pathJoin(cfgPath, "generated");
|
|
||||||
}
|
|
||||||
|
|
||||||
let cache = cacheLocation;
|
|
||||||
if (cache === "") {
|
|
||||||
cache = pathJoin(cfgPath, "cache");
|
|
||||||
}
|
|
||||||
|
|
||||||
let blobs;
|
|
||||||
if (storeBlobsInDatabase) {
|
|
||||||
blobs = intl.formatMessage({
|
|
||||||
id: "setup.confirm.blobs_use_database",
|
|
||||||
});
|
|
||||||
} else if (blobsLocation !== "") {
|
|
||||||
blobs = blobsLocation;
|
|
||||||
} else {
|
} else {
|
||||||
blobs = pathJoin(cfgPath, "blobs");
|
cfgDir = setupInWorkDir ? pwd : fallbackStashDir;
|
||||||
|
config = pathJoin(cfgDir, "config.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
function joinCfgDir(path: string) {
|
||||||
|
if (cfgDir) {
|
||||||
|
return pathJoin(cfgDir, path);
|
||||||
|
} else {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -684,38 +675,52 @@ export const Setup: React.FC = () => {
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
{!overrideDatabase && (
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
<FormattedMessage id="setup.confirm.database_file_path" />
|
<FormattedMessage id="setup.confirm.database_file_path" />
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<code>{database}</code>
|
<code>{databaseFile || joinCfgDir("stash-go.sqlite")}</code>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
)}
|
||||||
|
{!overrideGenerated && (
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
<FormattedMessage id="setup.confirm.generated_directory" />
|
<FormattedMessage id="setup.confirm.generated_directory" />
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<code>{generated}</code>
|
<code>{generatedLocation || joinCfgDir("generated")}</code>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
)}
|
||||||
|
{!overrideCache && (
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
<FormattedMessage id="setup.confirm.cache_directory" />
|
<FormattedMessage id="setup.confirm.cache_directory" />
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<code>{cache}</code>
|
<code>{cacheLocation || joinCfgDir("cache")}</code>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
)}
|
||||||
|
{!overrideBlobs && (
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
<FormattedMessage id="setup.confirm.blobs_directory" />
|
<FormattedMessage id="setup.confirm.blobs_directory" />
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<code>{blobs}</code>
|
<code>
|
||||||
|
{storeBlobsInDatabase ? (
|
||||||
|
<FormattedMessage id="setup.confirm.blobs_use_database" />
|
||||||
|
) : (
|
||||||
|
blobsLocation || joinCfgDir("blobs")
|
||||||
|
)}
|
||||||
|
</code>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
<section className="mt-5">
|
<section className="mt-5">
|
||||||
<div className="d-flex justify-content-center">
|
<div className="d-flex justify-content-center">
|
||||||
|
|
@ -864,8 +869,7 @@ export const Setup: React.FC = () => {
|
||||||
return <LoadingIndicator />;
|
return <LoadingIndicator />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const welcomeStep =
|
const welcomeStep = overrideConfig
|
||||||
status && status.configPath !== ""
|
|
||||||
? renderWelcomeSpecificConfig
|
? renderWelcomeSpecificConfig
|
||||||
: renderWelcome;
|
: renderWelcome;
|
||||||
const steps = [welcomeStep, renderSetPaths, renderConfirm, renderFinish];
|
const steps = [welcomeStep, renderSetPaths, renderConfirm, renderFinish];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue