Skip to content

Commit

Permalink
Add Clean generated files task (#4607)
Browse files Browse the repository at this point in the history
* Add clean generate task
* Add to library tasks
* Save and read defaults
* Stop handling and logging
* Make filename parsing more robust
  • Loading branch information
WithoutPants committed Feb 23, 2024
1 parent 4a3ce8b commit ba1ebba
Show file tree
Hide file tree
Showing 16 changed files with 994 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ models:
model: github.com/stashapp/stash/internal/manager/config.ConfigDisableDropdownCreate
ScanMetadataOptions:
model: github.com/stashapp/stash/internal/manager/config.ScanMetadataOptions
CleanGeneratedInput:
model: github.com/stashapp/stash/internal/manager/task.CleanGeneratedOptions
AutoTagMetadataOptions:
model: github.com/stashapp/stash/internal/manager/config.AutoTagMetadataOptions
SystemStatus:
Expand Down
2 changes: 2 additions & 0 deletions graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ type Mutation {
metadataAutoTag(input: AutoTagMetadataInput!): ID!
"Clean metadata. Returns the job ID"
metadataClean(input: CleanMetadataInput!): ID!
"Clean generated files. Returns the job ID"
metadataCleanGenerated(input: CleanGeneratedInput!): ID!
"Identifies scenes using scrapers. Returns the job ID"
metadataIdentify(input: IdentifyMetadataInput!): ID!

Expand Down
20 changes: 20 additions & 0 deletions graphql/schema/types/metadata.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ input CleanMetadataInput {
dryRun: Boolean!
}

input CleanGeneratedInput {
"Clean blob files without blob entries"
blobFiles: Boolean
"Clean sprite and vtt files without scene entries"
sprites: Boolean
"Clean preview files without scene entries"
screenshots: Boolean
"Clean scene transcodes without scene entries"
transcodes: Boolean

"Clean marker files without marker entries"
markers: Boolean

"Clean image thumbnails/clips without image entries"
imageThumbnails: Boolean

"Do a dry run. Don't delete any files"
dryRun: Boolean
}

input AutoTagMetadataInput {
"Paths to tag, null for all files"
paths: [String!]
Expand Down
16 changes: 16 additions & 0 deletions internal/api/resolver_mutation_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stashapp/stash/internal/identify"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/internal/manager/task"
"github.com/stashapp/stash/pkg/logger"
)

Expand Down Expand Up @@ -98,6 +99,21 @@ func (r *mutationResolver) MetadataClean(ctx context.Context, input manager.Clea
return strconv.Itoa(jobID), nil
}

func (r *mutationResolver) MetadataCleanGenerated(ctx context.Context, input task.CleanGeneratedOptions) (string, error) {
mgr := manager.GetInstance()
t := &task.CleanGeneratedJob{
Options: input,
Paths: mgr.Paths,
BlobsStorageType: mgr.Config.GetBlobsStorage(),
VideoFileNamingAlgorithm: mgr.Config.GetVideoFileNamingAlgorithm(),
Repository: mgr.Repository,
BlobCleaner: mgr.Repository.Blob,
}
jobID := mgr.JobManager.Add(ctx, "Cleaning generated files...", t)

return strconv.Itoa(jobID), nil
}

func (r *mutationResolver) MigrateHashNaming(ctx context.Context) (string, error) {
jobID := manager.GetInstance().MigrateHash(ctx)
return strconv.Itoa(jobID), nil
Expand Down

0 comments on commit ba1ebba

Please sign in to comment.