Skip to content

Commit

Permalink
Add explicit option to store blobs in database at setup (#4038)
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants committed Aug 17, 2023
1 parent 1591180 commit efc7b01
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 31 deletions.
3 changes: 2 additions & 1 deletion graphql/schema/types/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}

Expand Down
18 changes: 12 additions & 6 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
62 changes: 42 additions & 20 deletions ui/v2.5/src/components/Setup/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("");

Expand Down Expand Up @@ -393,27 +394,43 @@ export const Setup: React.FC = () => {
}}
/>
</p>
<InputGroup>
<Form.Control
className="text-input"
value={blobsLocation}
placeholder={intl.formatMessage({
id: "setup.paths.path_to_blobs_directory_empty_for_database",

<p>
<Form.Check
id="store-blobs-in-database"
checked={storeBlobsInDatabase}
label={intl.formatMessage({
id: "setup.paths.store_blobs_in_database",
})}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setBlobsLocation(e.currentTarget.value)
}
onChange={() => setStoreBlobsInDatabase(!storeBlobsInDatabase)}
/>
<InputGroup.Append>
<Button
variant="secondary"
</p>

{!storeBlobsInDatabase && (
<InputGroup>
<Form.Control
className="text-input"
onClick={() => setShowBlobsDialog(true)}
>
<Icon icon={faEllipsisH} />
</Button>
</InputGroup.Append>
</InputGroup>
value={blobsLocation}
placeholder={intl.formatMessage({
id: "setup.paths.path_to_blobs_directory_empty_for_default",
})}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setBlobsLocation(e.currentTarget.value)
}
disabled={storeBlobsInDatabase}
/>
<InputGroup.Append>
<Button
variant="secondary"
className="text-input"
onClick={() => setShowBlobsDialog(true)}
disabled={storeBlobsInDatabase}
>
<Icon icon={faEllipsisH} />
</Button>
</InputGroup.Append>
</InputGroup>
)}
</Form.Group>
);
}
Expand Down Expand Up @@ -543,6 +560,7 @@ export const Setup: React.FC = () => {
databaseFile,
generatedLocation,
cacheLocation,
storeBlobsInDatabase,
blobsLocation,
stashes,
});
Expand Down Expand Up @@ -631,7 +649,11 @@ export const Setup: React.FC = () => {
</dt>
<dd>
<code>
{blobsLocation !== ""
{storeBlobsInDatabase
? intl.formatMessage({
id: "setup.confirm.blobs_use_database",
})
: blobsLocation !== ""
? blobsLocation
: intl.formatMessage({
id: "setup.confirm.default_blobs_location",
Expand Down
10 changes: 6 additions & 4 deletions ui/v2.5/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<use database>",
"cache_directory": "Cache directory",
"configuration_file_location": "Configuration file location:",
"database_file_path": "Database file path",
"default_blobs_location": "<use database>",
"default_blobs_location": "<path containing configuration file>/blobs",
"default_cache_location": "<path containing configuration file>/cache",
"default_db_location": "<path containing configuration file>/stash-go.sqlite",
"default_generated_content_location": "<path containing configuration file>/generated",
Expand Down Expand Up @@ -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 <code>blobs</code>. 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. <strong>Note:</strong> 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 <code>blobs</code> 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. <strong>Note:</strong> 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 <code>cache</code> 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?",
Expand Down

0 comments on commit efc7b01

Please sign in to comment.