From efc7b01cf665a7033c40d4d9309067e234474616 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Thu, 17 Aug 2023 15:09:43 +1000 Subject: [PATCH] Add explicit option to store blobs in database at setup (#4038) --- graphql/schema/types/config.graphql | 3 +- internal/manager/manager.go | 18 +++++--- ui/v2.5/src/components/Setup/Setup.tsx | 62 +++++++++++++++++--------- ui/v2.5/src/locales/en-GB.json | 10 +++-- 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/graphql/schema/types/config.graphql b/graphql/schema/types/config.graphql index a92bcc168..bbbb63373 100644 --- a/graphql/schema/types/config.graphql +++ b/graphql/schema/types/config.graphql @@ -8,7 +8,8 @@ input SetupInput { generatedLocation: String! "Empty to indicate default" cacheLocation: String! - "Empty to indicate database storage for blobs" + storeBlobsInDatabase: Boolean! + "Empty to indicate default - only applicable if storeBlobsInDatabase is false" blobsLocation: String! } diff --git a/internal/manager/manager.go b/internal/manager/manager.go index caad6e347..0b1c50abe 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -100,7 +100,9 @@ type SetupInput struct { GeneratedLocation string `json:"generatedLocation"` // Empty to indicate default CacheLocation string `json:"cacheLocation"` - // Empty to indicate database storage for blobs + + StoreBlobsInDatabase bool `json:"storeBlobsInDatabase"` + // Empty to indicate default BlobsLocation string `json:"blobsLocation"` } @@ -596,6 +598,10 @@ func setSetupDefaults(input *SetupInput) { if input.DatabaseFile == "" { input.DatabaseFile = filepath.Join(configDir, "stash-go.sqlite") } + + if input.BlobsLocation == "" { + input.BlobsLocation = filepath.Join(configDir, "blobs") + } } func (s *Manager) Setup(ctx context.Context, input SetupInput) error { @@ -648,20 +654,20 @@ func (s *Manager) Setup(ctx context.Context, input SetupInput) error { s.Config.Set(config.Cache, input.CacheLocation) } - // if blobs path was provided then use filesystem based blob storage - if input.BlobsLocation != "" { + if input.StoreBlobsInDatabase { + s.Config.Set(config.BlobsStorage, config.BlobStorageTypeDatabase) + } else { if !c.HasOverride(config.BlobsPath) { if exists, _ := fsutil.DirExists(input.BlobsLocation); !exists { if err := os.MkdirAll(input.BlobsLocation, 0755); err != nil { return fmt.Errorf("error creating blobs directory: %v", err) } } + + s.Config.Set(config.BlobsPath, input.BlobsLocation) } - s.Config.Set(config.BlobsPath, input.BlobsLocation) s.Config.Set(config.BlobsStorage, config.BlobStorageTypeFilesystem) - } else { - s.Config.Set(config.BlobsStorage, config.BlobStorageTypeDatabase) } // set the configuration diff --git a/ui/v2.5/src/components/Setup/Setup.tsx b/ui/v2.5/src/components/Setup/Setup.tsx index f4f825322..7774b2452 100644 --- a/ui/v2.5/src/components/Setup/Setup.tsx +++ b/ui/v2.5/src/components/Setup/Setup.tsx @@ -40,7 +40,8 @@ export const Setup: React.FC = () => { const [databaseFile, setDatabaseFile] = useState(""); const [generatedLocation, setGeneratedLocation] = useState(""); const [cacheLocation, setCacheLocation] = useState(""); - const [blobsLocation, setBlobsLocation] = useState("blobs"); + const [storeBlobsInDatabase, setStoreBlobsInDatabase] = useState(false); + const [blobsLocation, setBlobsLocation] = useState(""); const [loading, setLoading] = useState(false); const [setupError, setSetupError] = useState(""); @@ -393,27 +394,43 @@ export const Setup: React.FC = () => { }} />

- - + ) => - setBlobsLocation(e.currentTarget.value) - } + onChange={() => setStoreBlobsInDatabase(!storeBlobsInDatabase)} /> - - - - + value={blobsLocation} + placeholder={intl.formatMessage({ + id: "setup.paths.path_to_blobs_directory_empty_for_default", + })} + onChange={(e: React.ChangeEvent) => + setBlobsLocation(e.currentTarget.value) + } + disabled={storeBlobsInDatabase} + /> + + + + + )} ); } @@ -543,6 +560,7 @@ export const Setup: React.FC = () => { databaseFile, generatedLocation, cacheLocation, + storeBlobsInDatabase, blobsLocation, stashes, }); @@ -631,7 +649,11 @@ export const Setup: React.FC = () => {
- {blobsLocation !== "" + {storeBlobsInDatabase + ? intl.formatMessage({ + id: "setup.confirm.blobs_use_database", + }) + : blobsLocation !== "" ? blobsLocation : intl.formatMessage({ id: "setup.confirm.default_blobs_location", diff --git a/ui/v2.5/src/locales/en-GB.json b/ui/v2.5/src/locales/en-GB.json index 6775e71ca..b0efd4170 100644 --- a/ui/v2.5/src/locales/en-GB.json +++ b/ui/v2.5/src/locales/en-GB.json @@ -1149,10 +1149,11 @@ "confirm": { "almost_ready": "We're almost ready to complete the configuration. Please confirm the following settings. You can click back to change anything incorrect. If everything looks good, click Confirm to create your system.", "blobs_directory": "Binary data directory", + "blobs_use_database": "", "cache_directory": "Cache directory", "configuration_file_location": "Configuration file location:", "database_file_path": "Database file path", - "default_blobs_location": "", + "default_blobs_location": "/blobs", "default_cache_location": "/cache", "default_db_location": "/stash-go.sqlite", "default_generated_content_location": "/generated", @@ -1190,14 +1191,15 @@ "paths": { "database_filename_empty_for_default": "database filename (empty for default)", "description": "Next up, we need to determine where to find your porn collection, and where to store the Stash database, generated files and cache files. These settings can be changed later if needed.", - "path_to_blobs_directory_empty_for_database": "path to blobs directory (empty to use database)", + "path_to_blobs_directory_empty_for_default": "path to blobs directory (empty for default)", "path_to_cache_directory_empty_for_default": "path to cache directory (empty for default)", "path_to_generated_directory_empty_for_default": "path to generated directory (empty for default)", "set_up_your_paths": "Set up your paths", "stash_alert": "No library paths have been selected. No media will be able to be scanned into Stash. Are you sure?", + "store_blobs_in_database": "Store blobs in database", "where_can_stash_store_blobs": "Where can Stash store database binary data?", - "where_can_stash_store_blobs_description": "Stash can store binary data such as scene covers, performer, studio and tag images either in the database or in the filesystem. By default, it will store this data in the filesystem in the subdirectory blobs. If you want to change this, please enter an absolute or relative (to the current working directory) path. Stash will create this directory if it does not already exist.", - "where_can_stash_store_blobs_description_addendum": "Alternatively, if you want to store this data in the database, you can leave this field blank. Note: This will increase the size of your database file, and will increase database migration times.", + "where_can_stash_store_blobs_description": "Stash can store binary data such as scene covers, performer, studio and tag images either in the database or in the filesystem. By default, it will store this data in the filesystem in the subdirectory blobs within the directory containing your config file. If you want to change this, please enter an absolute or relative (to the current working directory) path. Stash will create this directory if it does not already exist.", + "where_can_stash_store_blobs_description_addendum": "Alternatively, you can store this data in the database. Note: This will increase the size of your database file, and will increase database migration times.", "where_can_stash_store_cache_files": "Where can Stash store cache files?", "where_can_stash_store_cache_files_description": "In order for some functionality like HLS/DASH live transcoding to function, Stash requires a cache directory for temporary files. By default, Stash will create a cache directory within the directory containing your config file. If you want to change this, please enter an absolute or relative (to the current working directory) path. Stash will create this directory if it does not already exist.", "where_can_stash_store_its_database": "Where can Stash store its database?",