mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Ran formatter and fixed some lint issues
This commit is contained in:
@@ -12,7 +12,7 @@ before_install:
|
|||||||
- yarn install
|
- yarn install
|
||||||
- ./node_modules/@angular/cli/bin/ng build --prod
|
- ./node_modules/@angular/cli/bin/ng build --prod
|
||||||
- cd ../..
|
- cd ../..
|
||||||
- go get -v golang.org/x/lint/golint
|
- go get -v github.com/mgechev/revive
|
||||||
script:
|
script:
|
||||||
- make lint
|
- make lint
|
||||||
- make vet
|
- make vet
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -22,4 +22,4 @@ vet:
|
|||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint:
|
lint:
|
||||||
go list ./... | grep -v vendor | xargs golint -set_exit_status
|
revive -config revive.toml -exclude ./vendor/... ./...
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -34,6 +34,10 @@ Not yet, but this will come in the future.
|
|||||||
|
|
||||||
# Development
|
# Development
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
* [Revive](https://github.com/mgechev/revive) - Configurable linter `go get github.com/mgechev/revive`
|
||||||
|
|
||||||
## Environment
|
## Environment
|
||||||
|
|
||||||
### macOS
|
### macOS
|
||||||
@@ -53,14 +57,18 @@ TODO
|
|||||||
|
|
||||||
* `make build` - Builds the binary
|
* `make build` - Builds the binary
|
||||||
* `make gqlgen` - Regenerate Go GraphQL files
|
* `make gqlgen` - Regenerate Go GraphQL files
|
||||||
|
* `make vet` - Run `go vet`
|
||||||
|
* `make lint` - Run the linter
|
||||||
|
|
||||||
## Building a release
|
## Building a release
|
||||||
|
|
||||||
1. cd into the UI directory and run `ng build --prod`
|
1. cd into the UI directory and run `ng build --prod` to compile the frontend
|
||||||
2. cd back to the root directory and run `make build` to build the executable
|
2. cd back to the root directory and run `make build` to build the executable for your current platform
|
||||||
|
|
||||||
#### Notes for the dev
|
## Cross compiling
|
||||||
|
|
||||||
https://blog.filippo.io/easy-windows-and-linux-cross-compilers-for-macos/
|
This project makes use of [this](https://github.com/bep/dockerfiles/tree/master/ci-goreleaser) docker container to create an environment
|
||||||
|
where the app can be cross compiled. This process is kicked off by CI via the `scripts/cross-compile.sh` script. Run the following
|
||||||
|
command to open a bash shell to the container to poke around:
|
||||||
|
|
||||||
`docker run --rm --mount type=bind,source="$(pwd)",target=/stash -w /stash -i -t bepsays/ci-goreleaser:1.11-2 /bin/bash`
|
`docker run --rm --mount type=bind,source="$(pwd)",target=/stash -w /stash -i -t bepsays/ci-goreleaser:1.11-2 /bin/bash`
|
||||||
12
api/context_keys.go
Normal file
12
api/context_keys.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/40891345/fix-should-not-use-basic-type-string-as-key-in-context-withvalue-golint
|
||||||
|
|
||||||
|
type key int
|
||||||
|
|
||||||
|
const (
|
||||||
|
galleryKey key = 0
|
||||||
|
performerKey key = 1
|
||||||
|
sceneKey key = 2
|
||||||
|
studioKey key = 3
|
||||||
|
)
|
||||||
@@ -19,8 +19,8 @@ func (r *performerResolver) Name(ctx context.Context, obj *models.Performer) (*s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *performerResolver) URL(ctx context.Context, obj *models.Performer) (*string, error) {
|
func (r *performerResolver) URL(ctx context.Context, obj *models.Performer) (*string, error) {
|
||||||
if obj.Url.Valid {
|
if obj.URL.Valid {
|
||||||
return &obj.Url.String, nil
|
return &obj.URL.String, nil
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ func (r *performerResolver) Favorite(ctx context.Context, obj *models.Performer)
|
|||||||
|
|
||||||
func (r *performerResolver) ImagePath(ctx context.Context, obj *models.Performer) (*string, error) {
|
func (r *performerResolver) ImagePath(ctx context.Context, obj *models.Performer) (*string, error) {
|
||||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||||
imagePath := urlbuilders.NewPerformerURLBuilder(baseURL, obj.ID).GetPerformerImageUrl()
|
imagePath := urlbuilders.NewPerformerURLBuilder(baseURL, obj.ID).GetPerformerImageURL()
|
||||||
return &imagePath, nil
|
return &imagePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ func (r *sceneResolver) Details(ctx context.Context, obj *models.Scene) (*string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *sceneResolver) URL(ctx context.Context, obj *models.Scene) (*string, error) {
|
func (r *sceneResolver) URL(ctx context.Context, obj *models.Scene) (*string, error) {
|
||||||
if obj.Url.Valid {
|
if obj.URL.Valid {
|
||||||
return &obj.Url.String, nil
|
return &obj.URL.String, nil
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -69,12 +69,12 @@ func (r *sceneResolver) File(ctx context.Context, obj *models.Scene) (models.Sce
|
|||||||
func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (models.ScenePathsType, error) {
|
func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (models.ScenePathsType, error) {
|
||||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||||
builder := urlbuilders.NewSceneURLBuilder(baseURL, obj.ID)
|
builder := urlbuilders.NewSceneURLBuilder(baseURL, obj.ID)
|
||||||
screenshotPath := builder.GetScreenshotUrl()
|
screenshotPath := builder.GetScreenshotURL()
|
||||||
previewPath := builder.GetStreamPreviewUrl()
|
previewPath := builder.GetStreamPreviewURL()
|
||||||
streamPath := builder.GetStreamUrl()
|
streamPath := builder.GetStreamURL()
|
||||||
webpPath := builder.GetStreamPreviewImageUrl()
|
webpPath := builder.GetStreamPreviewImageURL()
|
||||||
vttPath := builder.GetSpriteVttUrl()
|
vttPath := builder.GetSpriteVTTURL()
|
||||||
chaptersVttPath := builder.GetChaptersVttUrl()
|
chaptersVttPath := builder.GetChaptersVTTURL()
|
||||||
return models.ScenePathsType{
|
return models.ScenePathsType{
|
||||||
Screenshot: &screenshotPath,
|
Screenshot: &screenshotPath,
|
||||||
Preview: &previewPath,
|
Preview: &previewPath,
|
||||||
@@ -82,7 +82,6 @@ func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (models.Sc
|
|||||||
Webp: &webpPath,
|
Webp: &webpPath,
|
||||||
Vtt: &vttPath,
|
Vtt: &vttPath,
|
||||||
ChaptersVtt: &chaptersVttPath,
|
ChaptersVtt: &chaptersVttPath,
|
||||||
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ func (r *sceneMarkerResolver) Tags(ctx context.Context, obj *models.SceneMarker)
|
|||||||
func (r *sceneMarkerResolver) Stream(ctx context.Context, obj *models.SceneMarker) (string, error) {
|
func (r *sceneMarkerResolver) Stream(ctx context.Context, obj *models.SceneMarker) (string, error) {
|
||||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||||
sceneID := int(obj.SceneID.Int64)
|
sceneID := int(obj.SceneID.Int64)
|
||||||
return urlbuilders.NewSceneURLBuilder(baseURL, sceneID).GetSceneMarkerStreamUrl(obj.ID), nil
|
return urlbuilders.NewSceneURLBuilder(baseURL, sceneID).GetSceneMarkerStreamURL(obj.ID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *sceneMarkerResolver) Preview(ctx context.Context, obj *models.SceneMarker) (string, error) {
|
func (r *sceneMarkerResolver) Preview(ctx context.Context, obj *models.SceneMarker) (string, error) {
|
||||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||||
sceneID := int(obj.SceneID.Int64)
|
sceneID := int(obj.SceneID.Int64)
|
||||||
return urlbuilders.NewSceneURLBuilder(baseURL, sceneID).GetSceneMarkerStreamPreviewUrl(obj.ID), nil
|
return urlbuilders.NewSceneURLBuilder(baseURL, sceneID).GetSceneMarkerStreamPreviewURL(obj.ID), nil
|
||||||
}
|
}
|
||||||
@@ -19,15 +19,15 @@ func (r *studioResolver) Name(ctx context.Context, obj *models.Studio) (string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *studioResolver) URL(ctx context.Context, obj *models.Studio) (*string, error) {
|
func (r *studioResolver) URL(ctx context.Context, obj *models.Studio) (*string, error) {
|
||||||
if obj.Url.Valid {
|
if obj.URL.Valid {
|
||||||
return &obj.Url.String, nil
|
return &obj.URL.String, nil
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *studioResolver) ImagePath(ctx context.Context, obj *models.Studio) (*string, error) {
|
func (r *studioResolver) ImagePath(ctx context.Context, obj *models.Studio) (*string, error) {
|
||||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||||
imagePath := urlbuilders.NewStudioURLBuilder(baseURL, obj.ID).GetStudioImageUrl()
|
imagePath := urlbuilders.NewStudioURLBuilder(baseURL, obj.ID).GetStudioImageURL()
|
||||||
return &imagePath, nil
|
return &imagePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per
|
|||||||
newPerformer.Name = sql.NullString{String: *input.Name, Valid: true}
|
newPerformer.Name = sql.NullString{String: *input.Name, Valid: true}
|
||||||
}
|
}
|
||||||
if input.URL != nil {
|
if input.URL != nil {
|
||||||
newPerformer.Url = sql.NullString{ String: *input.URL, Valid: true }
|
newPerformer.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||||
}
|
}
|
||||||
if input.Birthdate != nil {
|
if input.Birthdate != nil {
|
||||||
newPerformer.Birthdate = sql.NullString{String: *input.Birthdate, Valid: true}
|
newPerformer.Birthdate = sql.NullString{String: *input.Birthdate, Valid: true}
|
||||||
@@ -112,7 +112,7 @@ func (r *mutationResolver) PerformerUpdate(ctx context.Context, input models.Per
|
|||||||
updatedPerformer.Name = sql.NullString{String: *input.Name, Valid: true}
|
updatedPerformer.Name = sql.NullString{String: *input.Name, Valid: true}
|
||||||
}
|
}
|
||||||
if input.URL != nil {
|
if input.URL != nil {
|
||||||
updatedPerformer.Url = sql.NullString{ String: *input.URL, Valid: true }
|
updatedPerformer.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||||
}
|
}
|
||||||
if input.Birthdate != nil {
|
if input.Birthdate != nil {
|
||||||
updatedPerformer.Birthdate = sql.NullString{String: *input.Birthdate, Valid: true}
|
updatedPerformer.Birthdate = sql.NullString{String: *input.Birthdate, Valid: true}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func (r *mutationResolver) SceneUpdate(ctx context.Context, input models.SceneUp
|
|||||||
updatedScene.Details = sql.NullString{String: *input.Details, Valid: true}
|
updatedScene.Details = sql.NullString{String: *input.Details, Valid: true}
|
||||||
}
|
}
|
||||||
if input.URL != nil {
|
if input.URL != nil {
|
||||||
updatedScene.Url = sql.NullString{ String: *input.URL, Valid: true }
|
updatedScene.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||||
}
|
}
|
||||||
if input.Date != nil {
|
if input.Date != nil {
|
||||||
updatedScene.Date = sql.NullString{String: *input.Date, Valid: true}
|
updatedScene.Date = sql.NullString{String: *input.Date, Valid: true}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (r *mutationResolver) StudioCreate(ctx context.Context, input models.Studio
|
|||||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
||||||
}
|
}
|
||||||
if input.URL != nil {
|
if input.URL != nil {
|
||||||
newStudio.Url = sql.NullString{ String: *input.URL, Valid: true }
|
newStudio.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the transaction and save the studio
|
// Start the transaction and save the studio
|
||||||
@@ -66,7 +66,7 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio
|
|||||||
updatedStudio.Name = sql.NullString{String: *input.Name, Valid: true}
|
updatedStudio.Name = sql.NullString{String: *input.Name, Valid: true}
|
||||||
}
|
}
|
||||||
if input.URL != nil {
|
if input.URL != nil {
|
||||||
updatedStudio.Url = sql.NullString{ String: *input.URL, Valid: true }
|
updatedStudio.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the transaction and save the studio
|
// Start the transaction and save the studio
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/stashapp/stash/logger"
|
|
||||||
"github.com/stashapp/stash/manager"
|
"github.com/stashapp/stash/manager"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -15,8 +14,7 @@ func (r *subscriptionResolver) MetadataUpdate(ctx context.Context) (<-chan strin
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case t := <-ticker.C:
|
case _ = <-ticker.C:
|
||||||
logger.Trace("metadata subscription tick at %s", t)
|
|
||||||
manager.GetInstance().HandleMetadataUpdateSubscriptionTick(msg)
|
manager.GetInstance().HandleMetadataUpdateSubscriptionTick(msg)
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (rs galleryRoutes) Routes() chi.Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs galleryRoutes) File(w http.ResponseWriter, r *http.Request) {
|
func (rs galleryRoutes) File(w http.ResponseWriter, r *http.Request) {
|
||||||
gallery := r.Context().Value("gallery").(*models.Gallery)
|
gallery := r.Context().Value(galleryKey).(*models.Gallery)
|
||||||
fileIndex, _ := strconv.Atoi(chi.URLParam(r, "fileIndex"))
|
fileIndex, _ := strconv.Atoi(chi.URLParam(r, "fileIndex"))
|
||||||
thumb := r.URL.Query().Get("thumb")
|
thumb := r.URL.Query().Get("thumb")
|
||||||
w.Header().Add("Cache-Control", "max-age=604800000") // 1 Week
|
w.Header().Add("Cache-Control", "max-age=604800000") // 1 Week
|
||||||
@@ -48,7 +48,7 @@ func GalleryCtx(next http.Handler) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), "gallery", gallery)
|
ctx := context.WithValue(r.Context(), galleryKey, gallery)
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ func (rs performerRoutes) Routes() chi.Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs performerRoutes) Image(w http.ResponseWriter, r *http.Request) {
|
func (rs performerRoutes) Image(w http.ResponseWriter, r *http.Request) {
|
||||||
performer := r.Context().Value("performer").(*models.Performer)
|
performer := r.Context().Value(performerKey).(*models.Performer)
|
||||||
_, _ = w.Write(performer.Image)
|
_, _ = w.Write(performer.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ func PerformerCtx(next http.Handler) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), "performer", performer)
|
ctx := context.WithValue(r.Context(), performerKey, performer)
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -38,31 +38,31 @@ func (rs sceneRoutes) Routes() chi.Router {
|
|||||||
// region Handlers
|
// region Handlers
|
||||||
|
|
||||||
func (rs sceneRoutes) Stream(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) Stream(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
filepath := manager.GetInstance().Paths.Scene.GetStreamPath(scene.Path, scene.Checksum)
|
filepath := manager.GetInstance().Paths.Scene.GetStreamPath(scene.Path, scene.Checksum)
|
||||||
http.ServeFile(w, r, filepath)
|
http.ServeFile(w, r, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) Screenshot(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) Screenshot(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
filepath := manager.GetInstance().Paths.Scene.GetScreenshotPath(scene.Checksum)
|
filepath := manager.GetInstance().Paths.Scene.GetScreenshotPath(scene.Checksum)
|
||||||
http.ServeFile(w, r, filepath)
|
http.ServeFile(w, r, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) Preview(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) Preview(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
filepath := manager.GetInstance().Paths.Scene.GetStreamPreviewPath(scene.Checksum)
|
filepath := manager.GetInstance().Paths.Scene.GetStreamPreviewPath(scene.Checksum)
|
||||||
http.ServeFile(w, r, filepath)
|
http.ServeFile(w, r, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) Webp(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) Webp(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
filepath := manager.GetInstance().Paths.Scene.GetStreamPreviewImagePath(scene.Checksum)
|
filepath := manager.GetInstance().Paths.Scene.GetStreamPreviewImagePath(scene.Checksum)
|
||||||
http.ServeFile(w, r, filepath)
|
http.ServeFile(w, r, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) ChapterVtt(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) ChapterVtt(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
qb := models.NewSceneMarkerQueryBuilder()
|
qb := models.NewSceneMarkerQueryBuilder()
|
||||||
sceneMarkers, err := qb.FindBySceneID(scene.ID, nil)
|
sceneMarkers, err := qb.FindBySceneID(scene.ID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -83,21 +83,21 @@ func (rs sceneRoutes) ChapterVtt(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) VttThumbs(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) VttThumbs(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
w.Header().Set("Content-Type", "text/vtt")
|
w.Header().Set("Content-Type", "text/vtt")
|
||||||
filepath := manager.GetInstance().Paths.Scene.GetSpriteVttFilePath(scene.Checksum)
|
filepath := manager.GetInstance().Paths.Scene.GetSpriteVttFilePath(scene.Checksum)
|
||||||
http.ServeFile(w, r, filepath)
|
http.ServeFile(w, r, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) VttSprite(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) VttSprite(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
w.Header().Set("Content-Type", "image/jpeg")
|
w.Header().Set("Content-Type", "image/jpeg")
|
||||||
filepath := manager.GetInstance().Paths.Scene.GetSpriteImageFilePath(scene.Checksum)
|
filepath := manager.GetInstance().Paths.Scene.GetSpriteImageFilePath(scene.Checksum)
|
||||||
http.ServeFile(w, r, filepath)
|
http.ServeFile(w, r, filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) SceneMarkerStream(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) SceneMarkerStream(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
sceneMarkerID, _ := strconv.Atoi(chi.URLParam(r, "sceneMarkerId"))
|
sceneMarkerID, _ := strconv.Atoi(chi.URLParam(r, "sceneMarkerId"))
|
||||||
qb := models.NewSceneMarkerQueryBuilder()
|
qb := models.NewSceneMarkerQueryBuilder()
|
||||||
sceneMarker, err := qb.Find(sceneMarkerID)
|
sceneMarker, err := qb.Find(sceneMarkerID)
|
||||||
@@ -111,7 +111,7 @@ func (rs sceneRoutes) SceneMarkerStream(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs sceneRoutes) SceneMarkerPreview(w http.ResponseWriter, r *http.Request) {
|
func (rs sceneRoutes) SceneMarkerPreview(w http.ResponseWriter, r *http.Request) {
|
||||||
scene := r.Context().Value("scene").(*models.Scene)
|
scene := r.Context().Value(sceneKey).(*models.Scene)
|
||||||
sceneMarkerID, _ := strconv.Atoi(chi.URLParam(r, "sceneMarkerId"))
|
sceneMarkerID, _ := strconv.Atoi(chi.URLParam(r, "sceneMarkerId"))
|
||||||
qb := models.NewSceneMarkerQueryBuilder()
|
qb := models.NewSceneMarkerQueryBuilder()
|
||||||
sceneMarker, err := qb.Find(sceneMarkerID)
|
sceneMarker, err := qb.Find(sceneMarkerID)
|
||||||
@@ -145,7 +145,7 @@ func SceneCtx(next http.Handler) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), "scene", scene)
|
ctx := context.WithValue(r.Context(), sceneKey, scene)
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ func (rs studioRoutes) Routes() chi.Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
|
func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
|
||||||
studio := r.Context().Value("studio").(*models.Studio)
|
studio := r.Context().Value(studioKey).(*models.Studio)
|
||||||
_, _ = w.Write(studio.Image)
|
_, _ = w.Write(studio.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ func StudioCtx(next http.Handler) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), "studio", studio)
|
ctx := context.WithValue(r.Context(), studioKey, studio)
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -187,13 +187,14 @@ func makeTLSConfig() *tls.Config {
|
|||||||
return tlsConfig
|
return tlsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type contextKey struct {
|
type contextKey struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
BaseURLCtxKey = &contextKey{"BaseURL"}
|
BaseURLCtxKey = &contextKey{"BaseURL"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func BaseURLMiddleware(next http.Handler) http.Handler {
|
func BaseURLMiddleware(next http.Handler) http.Handler {
|
||||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ package urlbuilders
|
|||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
type galleryURLBuilder struct {
|
type GalleryURLBuilder struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
GalleryID string
|
GalleryID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGalleryURLBuilder(baseURL string, galleryID int) galleryURLBuilder {
|
func NewGalleryURLBuilder(baseURL string, galleryID int) GalleryURLBuilder {
|
||||||
return galleryURLBuilder{
|
return GalleryURLBuilder{
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
GalleryID: strconv.Itoa(galleryID),
|
GalleryID: strconv.Itoa(galleryID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b galleryURLBuilder) GetGalleryImageUrl(fileIndex int) string {
|
func (b GalleryURLBuilder) GetGalleryImageURL(fileIndex int) string {
|
||||||
return b.BaseURL + "/gallery/" + b.GalleryID + "/" + strconv.Itoa(fileIndex)
|
return b.BaseURL + "/gallery/" + b.GalleryID + "/" + strconv.Itoa(fileIndex)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ package urlbuilders
|
|||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
type performerURLBuilder struct {
|
type PerformerURLBuilder struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
PerformerID string
|
PerformerID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPerformerURLBuilder(baseURL string, performerID int) performerURLBuilder {
|
func NewPerformerURLBuilder(baseURL string, performerID int) PerformerURLBuilder {
|
||||||
return performerURLBuilder{
|
return PerformerURLBuilder{
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
PerformerID: strconv.Itoa(performerID),
|
PerformerID: strconv.Itoa(performerID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b performerURLBuilder) GetPerformerImageUrl() string {
|
func (b PerformerURLBuilder) GetPerformerImageURL() string {
|
||||||
return b.BaseURL + "/performer/" + b.PerformerID + "/image"
|
return b.BaseURL + "/performer/" + b.PerformerID + "/image"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,46 +2,46 @@ package urlbuilders
|
|||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
type sceneURLBuilder struct {
|
type SceneURLBuilder struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
SceneID string
|
SceneID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSceneURLBuilder(baseURL string, sceneID int) sceneURLBuilder {
|
func NewSceneURLBuilder(baseURL string, sceneID int) SceneURLBuilder {
|
||||||
return sceneURLBuilder{
|
return SceneURLBuilder{
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
SceneID: strconv.Itoa(sceneID),
|
SceneID: strconv.Itoa(sceneID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetStreamUrl() string {
|
func (b SceneURLBuilder) GetStreamURL() string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/stream.mp4"
|
return b.BaseURL + "/scene/" + b.SceneID + "/stream.mp4"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetStreamPreviewUrl() string {
|
func (b SceneURLBuilder) GetStreamPreviewURL() string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/preview"
|
return b.BaseURL + "/scene/" + b.SceneID + "/preview"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetStreamPreviewImageUrl() string {
|
func (b SceneURLBuilder) GetStreamPreviewImageURL() string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/webp"
|
return b.BaseURL + "/scene/" + b.SceneID + "/webp"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetSpriteVttUrl() string {
|
func (b SceneURLBuilder) GetSpriteVTTURL() string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "_thumbs.vtt"
|
return b.BaseURL + "/scene/" + b.SceneID + "_thumbs.vtt"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetScreenshotUrl() string {
|
func (b SceneURLBuilder) GetScreenshotURL() string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/screenshot"
|
return b.BaseURL + "/scene/" + b.SceneID + "/screenshot"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetChaptersVttUrl() string {
|
func (b SceneURLBuilder) GetChaptersVTTURL() string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/vtt/chapter"
|
return b.BaseURL + "/scene/" + b.SceneID + "/vtt/chapter"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetSceneMarkerStreamUrl(sceneMarkerId int) string {
|
func (b SceneURLBuilder) GetSceneMarkerStreamURL(sceneMarkerID int) string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/scene_marker/" + strconv.Itoa(sceneMarkerId) + "/stream"
|
return b.BaseURL + "/scene/" + b.SceneID + "/scene_marker/" + strconv.Itoa(sceneMarkerID) + "/stream"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b sceneURLBuilder) GetSceneMarkerStreamPreviewUrl(sceneMarkerId int) string {
|
func (b SceneURLBuilder) GetSceneMarkerStreamPreviewURL(sceneMarkerID int) string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/scene_marker/" + strconv.Itoa(sceneMarkerId) + "/preview"
|
return b.BaseURL + "/scene/" + b.SceneID + "/scene_marker/" + strconv.Itoa(sceneMarkerID) + "/preview"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ package urlbuilders
|
|||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
type studioURLBuilder struct {
|
type StudioURLBuilder struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
StudioID string
|
StudioID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStudioURLBuilder(baseURL string, studioID int) studioURLBuilder {
|
func NewStudioURLBuilder(baseURL string, studioID int) StudioURLBuilder {
|
||||||
return studioURLBuilder{
|
return StudioURLBuilder{
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
StudioID: strconv.Itoa(studioID),
|
StudioID: strconv.Itoa(studioID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b studioURLBuilder) GetStudioImageUrl() string {
|
func (b StudioURLBuilder) GetStudioImageURL() string {
|
||||||
return b.BaseURL + "/studio/" + b.StudioID + "/image"
|
return b.BaseURL + "/studio/" + b.StudioID + "/image"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func Download(configDirectory string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("FFMPeg was downloaded to %s. ")
|
return fmt.Errorf("ffmpeg was downloaded to %s", archivePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -101,17 +101,15 @@ func getFFMPEGURL() string {
|
|||||||
func getFFMPEGFilename() string {
|
func getFFMPEGFilename() string {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return "ffmpeg.exe"
|
return "ffmpeg.exe"
|
||||||
} else {
|
|
||||||
return "ffmpeg"
|
|
||||||
}
|
}
|
||||||
|
return "ffmpeg"
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFFProbeFilename() string {
|
func getFFProbeFilename() string {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return "ffprobe.exe"
|
return "ffprobe.exe"
|
||||||
} else {
|
|
||||||
return "ffprobe"
|
|
||||||
}
|
}
|
||||||
|
return "ffprobe"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if FFMPEG in the path has the correct flags
|
// Checks if FFMPEG in the path has the correct flags
|
||||||
|
|||||||
@@ -141,8 +141,8 @@ func (v *VideoFile) GetVideoStream() *FFProbeStream {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VideoFile) getStreamIndex(fileType string, probeJson FFProbeJSON) int {
|
func (v *VideoFile) getStreamIndex(fileType string, probeJSON FFProbeJSON) int {
|
||||||
for i, stream := range probeJson.Streams {
|
for i, stream := range probeJSON.Streams {
|
||||||
if stream.CodecType == fileType {
|
if stream.CodecType == fileType {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func Debug(args ...interface{}) {
|
|||||||
logger.Debug(args...)
|
logger.Debug(args...)
|
||||||
l := &LogItem{
|
l := &LogItem{
|
||||||
Type: "debug",
|
Type: "debug",
|
||||||
Message: fmt.Sprint(args),
|
Message: fmt.Sprint(args...),
|
||||||
}
|
}
|
||||||
addLogItem(l)
|
addLogItem(l)
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ func Info(args ...interface{}) {
|
|||||||
logger.Info(args...)
|
logger.Info(args...)
|
||||||
l := &LogItem{
|
l := &LogItem{
|
||||||
Type: "info",
|
Type: "info",
|
||||||
Message: fmt.Sprint(args),
|
Message: fmt.Sprint(args...),
|
||||||
}
|
}
|
||||||
addLogItem(l)
|
addLogItem(l)
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ func Warn(args ...interface{}) {
|
|||||||
logger.Warn(args...)
|
logger.Warn(args...)
|
||||||
l := &LogItem{
|
l := &LogItem{
|
||||||
Type: "warn",
|
Type: "warn",
|
||||||
Message: fmt.Sprint(args),
|
Message: fmt.Sprint(args...),
|
||||||
}
|
}
|
||||||
addLogItem(l)
|
addLogItem(l)
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ func Error(args ...interface{}) {
|
|||||||
logger.Error(args...)
|
logger.Error(args...)
|
||||||
l := &LogItem{
|
l := &LogItem{
|
||||||
Type: "error",
|
Type: "error",
|
||||||
Message: fmt.Sprint(args),
|
Message: fmt.Sprint(args...),
|
||||||
}
|
}
|
||||||
addLogItem(l)
|
addLogItem(l)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,12 +112,11 @@ func (g *PreviewGenerator) generateImage(encoder *ffmpeg.Encoder) error {
|
|||||||
tmpOutputPath := instance.Paths.Generated.GetTmpPath(g.ImageFilename)
|
tmpOutputPath := instance.Paths.Generated.GetTmpPath(g.ImageFilename)
|
||||||
if err := encoder.ScenePreviewVideoToImage(g.Info.VideoFile, 640, videoPreviewPath, tmpOutputPath); err != nil {
|
if err := encoder.ScenePreviewVideoToImage(g.Info.VideoFile, 640, videoPreviewPath, tmpOutputPath); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
}
|
||||||
if err := os.Rename(tmpOutputPath, outputPath); err != nil {
|
if err := os.Rename(tmpOutputPath, outputPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger.Debug("created video preview image: ", outputPath)
|
logger.Debug("created video preview image: ", outputPath)
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
type Performer struct {
|
type Performer struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Url string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Twitter string `json:"twitter,omitempty"`
|
Twitter string `json:"twitter,omitempty"`
|
||||||
Instagram string `json:"instagram,omitempty"`
|
Instagram string `json:"instagram,omitempty"`
|
||||||
Birthdate string `json:"birthdate,omitempty"`
|
Birthdate string `json:"birthdate,omitempty"`
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type SceneFile struct {
|
|||||||
type Scene struct {
|
type Scene struct {
|
||||||
Title string `json:"title,omitempty"`
|
Title string `json:"title,omitempty"`
|
||||||
Studio string `json:"studio,omitempty"`
|
Studio string `json:"studio,omitempty"`
|
||||||
Url string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Date string `json:"date,omitempty"`
|
Date string `json:"date,omitempty"`
|
||||||
Rating int `json:"rating,omitempty"`
|
Rating int `json:"rating,omitempty"`
|
||||||
Details string `json:"details,omitempty"`
|
Details string `json:"details,omitempty"`
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import (
|
|||||||
type ScrapedItem struct {
|
type ScrapedItem struct {
|
||||||
Title string `json:"title,omitempty"`
|
Title string `json:"title,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Url string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Date string `json:"date,omitempty"`
|
Date string `json:"date,omitempty"`
|
||||||
Rating string `json:"rating,omitempty"`
|
Rating string `json:"rating,omitempty"`
|
||||||
Tags string `json:"tags,omitempty"`
|
Tags string `json:"tags,omitempty"`
|
||||||
Models string `json:"models,omitempty"`
|
Models string `json:"models,omitempty"`
|
||||||
Episode int `json:"episode,omitempty"`
|
Episode int `json:"episode,omitempty"`
|
||||||
GalleryFilename string `json:"gallery_filename,omitempty"`
|
GalleryFilename string `json:"gallery_filename,omitempty"`
|
||||||
GalleryUrl string `json:"gallery_url,omitempty"`
|
GalleryURL string `json:"gallery_url,omitempty"`
|
||||||
VideoFilename string `json:"video_filename,omitempty"`
|
VideoFilename string `json:"video_filename,omitempty"`
|
||||||
VideoUrl string `json:"video_url,omitempty"`
|
VideoURL string `json:"video_url,omitempty"`
|
||||||
Studio string `json:"studio,omitempty"`
|
Studio string `json:"studio,omitempty"`
|
||||||
UpdatedAt RailsTime `json:"updated_at,omitempty"`
|
UpdatedAt RailsTime `json:"updated_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
type Studio struct {
|
type Studio struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Url string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
Image string `json:"image,omitempty"`
|
Image string `json:"image,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ func marshalToFile(filePath string, j interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(filePath, data, 0755); err != nil {
|
return ioutil.WriteFile(filePath, data, 0755)
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func encode(j interface{}) ([]byte, error) {
|
func encode(j interface{}) ([]byte, error) {
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *singleton) Scan() {
|
func (s *singleton) Scan() {
|
||||||
if s.Status != Idle { return }
|
if s.Status != Idle {
|
||||||
|
return
|
||||||
|
}
|
||||||
s.Status = Scan
|
s.Status = Scan
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -31,7 +33,9 @@ func (s *singleton) Scan() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleton) Import() {
|
func (s *singleton) Import() {
|
||||||
if s.Status != Idle { return }
|
if s.Status != Idle {
|
||||||
|
return
|
||||||
|
}
|
||||||
s.Status = Import
|
s.Status = Import
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -46,7 +50,9 @@ func (s *singleton) Import() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleton) Export() {
|
func (s *singleton) Export() {
|
||||||
if s.Status != Idle { return }
|
if s.Status != Idle {
|
||||||
|
return
|
||||||
|
}
|
||||||
s.Status = Export
|
s.Status = Export
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -61,7 +67,9 @@ func (s *singleton) Export() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcodes bool) {
|
func (s *singleton) Generate(sprites bool, previews bool, markers bool, transcodes bool) {
|
||||||
if s.Status != Idle { return }
|
if s.Status != Idle {
|
||||||
|
return
|
||||||
|
}
|
||||||
s.Status = Generate
|
s.Status = Generate
|
||||||
|
|
||||||
qb := models.NewSceneQueryBuilder()
|
qb := models.NewSceneQueryBuilder()
|
||||||
|
|||||||
@@ -32,9 +32,8 @@ func (sp *scenePaths) GetStreamPath(scenePath string, checksum string) string {
|
|||||||
transcodeExists, _ := utils.FileExists(transcodePath)
|
transcodeExists, _ := utils.FileExists(transcodePath)
|
||||||
if transcodeExists {
|
if transcodeExists {
|
||||||
return transcodePath
|
return transcodePath
|
||||||
} else {
|
|
||||||
return scenePath
|
|
||||||
}
|
}
|
||||||
|
return scenePath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *scenePaths) GetStreamPreviewPath(checksum string) string {
|
func (sp *scenePaths) GetStreamPreviewPath(checksum string) string {
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ func (t *ExportTask) ExportScenes(ctx context.Context) {
|
|||||||
if studioName != "" {
|
if studioName != "" {
|
||||||
newSceneJSON.Studio = studioName
|
newSceneJSON.Studio = studioName
|
||||||
}
|
}
|
||||||
if scene.Url.Valid {
|
if scene.URL.Valid {
|
||||||
newSceneJSON.Url = scene.Url.String
|
newSceneJSON.URL = scene.URL.String
|
||||||
}
|
}
|
||||||
if scene.Date.Valid {
|
if scene.Date.Valid {
|
||||||
newSceneJSON.Date = utils.GetYMDFromDatabaseDate(scene.Date.String)
|
newSceneJSON.Date = utils.GetYMDFromDatabaseDate(scene.Date.String)
|
||||||
@@ -213,8 +213,8 @@ func (t *ExportTask) ExportPerformers(ctx context.Context) {
|
|||||||
if performer.Name.Valid {
|
if performer.Name.Valid {
|
||||||
newPerformerJSON.Name = performer.Name.String
|
newPerformerJSON.Name = performer.Name.String
|
||||||
}
|
}
|
||||||
if performer.Url.Valid {
|
if performer.URL.Valid {
|
||||||
newPerformerJSON.Url = performer.Url.String
|
newPerformerJSON.URL = performer.URL.String
|
||||||
}
|
}
|
||||||
if performer.Birthdate.Valid {
|
if performer.Birthdate.Valid {
|
||||||
newPerformerJSON.Birthdate = utils.GetYMDFromDatabaseDate(performer.Birthdate.String)
|
newPerformerJSON.Birthdate = utils.GetYMDFromDatabaseDate(performer.Birthdate.String)
|
||||||
@@ -296,8 +296,8 @@ func (t *ExportTask) ExportStudios(ctx context.Context) {
|
|||||||
if studio.Name.Valid {
|
if studio.Name.Valid {
|
||||||
newStudioJSON.Name = studio.Name.String
|
newStudioJSON.Name = studio.Name.String
|
||||||
}
|
}
|
||||||
if studio.Url.Valid {
|
if studio.URL.Valid {
|
||||||
newStudioJSON.Url = studio.Url.String
|
newStudioJSON.URL = studio.URL.String
|
||||||
}
|
}
|
||||||
|
|
||||||
newStudioJSON.Image = utils.GetBase64StringFromData(studio.Image)
|
newStudioJSON.Image = utils.GetBase64StringFromData(studio.Image)
|
||||||
@@ -349,8 +349,8 @@ func (t *ExportTask) ExportScrapedItems(ctx context.Context) {
|
|||||||
if scrapedItem.Description.Valid {
|
if scrapedItem.Description.Valid {
|
||||||
newScrapedItemJSON.Description = scrapedItem.Description.String
|
newScrapedItemJSON.Description = scrapedItem.Description.String
|
||||||
}
|
}
|
||||||
if scrapedItem.Url.Valid {
|
if scrapedItem.URL.Valid {
|
||||||
newScrapedItemJSON.Url = scrapedItem.Url.String
|
newScrapedItemJSON.URL = scrapedItem.URL.String
|
||||||
}
|
}
|
||||||
if scrapedItem.Date.Valid {
|
if scrapedItem.Date.Valid {
|
||||||
newScrapedItemJSON.Date = utils.GetYMDFromDatabaseDate(scrapedItem.Date.String)
|
newScrapedItemJSON.Date = utils.GetYMDFromDatabaseDate(scrapedItem.Date.String)
|
||||||
@@ -370,14 +370,14 @@ func (t *ExportTask) ExportScrapedItems(ctx context.Context) {
|
|||||||
if scrapedItem.GalleryFilename.Valid {
|
if scrapedItem.GalleryFilename.Valid {
|
||||||
newScrapedItemJSON.GalleryFilename = scrapedItem.GalleryFilename.String
|
newScrapedItemJSON.GalleryFilename = scrapedItem.GalleryFilename.String
|
||||||
}
|
}
|
||||||
if scrapedItem.GalleryUrl.Valid {
|
if scrapedItem.GalleryURL.Valid {
|
||||||
newScrapedItemJSON.GalleryUrl = scrapedItem.GalleryUrl.String
|
newScrapedItemJSON.GalleryURL = scrapedItem.GalleryURL.String
|
||||||
}
|
}
|
||||||
if scrapedItem.VideoFilename.Valid {
|
if scrapedItem.VideoFilename.Valid {
|
||||||
newScrapedItemJSON.VideoFilename = scrapedItem.VideoFilename.String
|
newScrapedItemJSON.VideoFilename = scrapedItem.VideoFilename.String
|
||||||
}
|
}
|
||||||
if scrapedItem.VideoUrl.Valid {
|
if scrapedItem.VideoURL.Valid {
|
||||||
newScrapedItemJSON.VideoUrl = scrapedItem.VideoUrl.String
|
newScrapedItemJSON.VideoURL = scrapedItem.VideoURL.String
|
||||||
}
|
}
|
||||||
|
|
||||||
newScrapedItemJSON.Studio = studioName
|
newScrapedItemJSON.Studio = studioName
|
||||||
@@ -451,7 +451,7 @@ func getPrecision(num float64) int {
|
|||||||
p := 0
|
p := 0
|
||||||
for (math.Round(num*e) / e) != num {
|
for (math.Round(num*e) / e) != num {
|
||||||
e *= 10
|
e *= 10
|
||||||
p += 1
|
p++
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,9 @@ func (t *ImportTask) ImportPerformers(ctx context.Context) {
|
|||||||
logger.Errorf("[performers] failed to read json: %s", err.Error())
|
logger.Errorf("[performers] failed to read json: %s", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if mappingJSON.Checksum == "" || mappingJSON.Name == "" || performerJSON == nil { return }
|
if mappingJSON.Checksum == "" || mappingJSON.Name == "" || performerJSON == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
logger.Progressf("[performers] %d of %d", index, len(t.Mappings.Performers))
|
logger.Progressf("[performers] %d of %d", index, len(t.Mappings.Performers))
|
||||||
|
|
||||||
@@ -82,8 +84,8 @@ func (t *ImportTask) ImportPerformers(ctx context.Context) {
|
|||||||
if performerJSON.Name != "" {
|
if performerJSON.Name != "" {
|
||||||
newPerformer.Name = sql.NullString{String: performerJSON.Name, Valid: true}
|
newPerformer.Name = sql.NullString{String: performerJSON.Name, Valid: true}
|
||||||
}
|
}
|
||||||
if performerJSON.Url != "" {
|
if performerJSON.URL != "" {
|
||||||
newPerformer.Url = sql.NullString{ String: performerJSON.Url, Valid: true }
|
newPerformer.URL = sql.NullString{String: performerJSON.URL, Valid: true}
|
||||||
}
|
}
|
||||||
if performerJSON.Birthdate != "" {
|
if performerJSON.Birthdate != "" {
|
||||||
newPerformer.Birthdate = sql.NullString{String: performerJSON.Birthdate, Valid: true}
|
newPerformer.Birthdate = sql.NullString{String: performerJSON.Birthdate, Valid: true}
|
||||||
@@ -151,7 +153,9 @@ func (t *ImportTask) ImportStudios(ctx context.Context) {
|
|||||||
logger.Errorf("[studios] failed to read json: %s", err.Error())
|
logger.Errorf("[studios] failed to read json: %s", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if mappingJSON.Checksum == "" || mappingJSON.Name == "" || studioJSON == nil { return }
|
if mappingJSON.Checksum == "" || mappingJSON.Name == "" || studioJSON == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
logger.Progressf("[studios] %d of %d", index, len(t.Mappings.Studios))
|
logger.Progressf("[studios] %d of %d", index, len(t.Mappings.Studios))
|
||||||
|
|
||||||
@@ -169,7 +173,7 @@ func (t *ImportTask) ImportStudios(ctx context.Context) {
|
|||||||
Image: imageData,
|
Image: imageData,
|
||||||
Checksum: checksum,
|
Checksum: checksum,
|
||||||
Name: sql.NullString{String: studioJSON.Name, Valid: true},
|
Name: sql.NullString{String: studioJSON.Name, Valid: true},
|
||||||
Url: sql.NullString{ String: studioJSON.Url, Valid: true },
|
URL: sql.NullString{String: studioJSON.URL, Valid: true},
|
||||||
CreatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
CreatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
||||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
||||||
}
|
}
|
||||||
@@ -195,7 +199,9 @@ func (t *ImportTask) ImportGalleries(ctx context.Context) {
|
|||||||
|
|
||||||
for i, mappingJSON := range t.Mappings.Galleries {
|
for i, mappingJSON := range t.Mappings.Galleries {
|
||||||
index := i + 1
|
index := i + 1
|
||||||
if mappingJSON.Checksum == "" || mappingJSON.Path == "" { return }
|
if mappingJSON.Checksum == "" || mappingJSON.Path == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
logger.Progressf("[galleries] %d of %d", index, len(t.Mappings.Galleries))
|
logger.Progressf("[galleries] %d of %d", index, len(t.Mappings.Galleries))
|
||||||
|
|
||||||
@@ -254,7 +260,9 @@ func (t *ImportTask) ImportTags(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the tags from the markers if we have marker json
|
// Get the tags from the markers if we have marker json
|
||||||
if len(sceneJSON.Markers) == 0 { continue }
|
if len(sceneJSON.Markers) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, markerJSON := range sceneJSON.Markers {
|
for _, markerJSON := range sceneJSON.Markers {
|
||||||
if markerJSON.PrimaryTag != "" {
|
if markerJSON.PrimaryTag != "" {
|
||||||
tagNames = append(tagNames, markerJSON.PrimaryTag)
|
tagNames = append(tagNames, markerJSON.PrimaryTag)
|
||||||
@@ -308,16 +316,16 @@ func (t *ImportTask) ImportScrapedItems(ctx context.Context) {
|
|||||||
newScrapedItem := models.ScrapedItem{
|
newScrapedItem := models.ScrapedItem{
|
||||||
Title: sql.NullString{String: mappingJSON.Title, Valid: true},
|
Title: sql.NullString{String: mappingJSON.Title, Valid: true},
|
||||||
Description: sql.NullString{String: mappingJSON.Description, Valid: true},
|
Description: sql.NullString{String: mappingJSON.Description, Valid: true},
|
||||||
Url: sql.NullString{String: mappingJSON.Url, Valid: true},
|
URL: sql.NullString{String: mappingJSON.URL, Valid: true},
|
||||||
Date: sql.NullString{String: mappingJSON.Date, Valid: true},
|
Date: sql.NullString{String: mappingJSON.Date, Valid: true},
|
||||||
Rating: sql.NullString{String: mappingJSON.Rating, Valid: true},
|
Rating: sql.NullString{String: mappingJSON.Rating, Valid: true},
|
||||||
Tags: sql.NullString{String: mappingJSON.Tags, Valid: true},
|
Tags: sql.NullString{String: mappingJSON.Tags, Valid: true},
|
||||||
Models: sql.NullString{String: mappingJSON.Models, Valid: true},
|
Models: sql.NullString{String: mappingJSON.Models, Valid: true},
|
||||||
Episode: sql.NullInt64{Int64: int64(mappingJSON.Episode), Valid: true},
|
Episode: sql.NullInt64{Int64: int64(mappingJSON.Episode), Valid: true},
|
||||||
GalleryFilename: sql.NullString{String: mappingJSON.GalleryFilename, Valid: true},
|
GalleryFilename: sql.NullString{String: mappingJSON.GalleryFilename, Valid: true},
|
||||||
GalleryUrl: sql.NullString{String: mappingJSON.GalleryUrl, Valid: true},
|
GalleryURL: sql.NullString{String: mappingJSON.GalleryURL, Valid: true},
|
||||||
VideoFilename: sql.NullString{String: mappingJSON.VideoFilename, Valid: true},
|
VideoFilename: sql.NullString{String: mappingJSON.VideoFilename, Valid: true},
|
||||||
VideoUrl: sql.NullString{String: mappingJSON.VideoUrl, Valid: true},
|
VideoURL: sql.NullString{String: mappingJSON.VideoURL, Valid: true},
|
||||||
CreatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
CreatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
||||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: updatedAt},
|
UpdatedAt: models.SQLiteTimestamp{Timestamp: updatedAt},
|
||||||
}
|
}
|
||||||
@@ -332,7 +340,7 @@ func (t *ImportTask) ImportScrapedItems(ctx context.Context) {
|
|||||||
|
|
||||||
_, err = qb.Create(newScrapedItem, tx)
|
_, err = qb.Create(newScrapedItem, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("[scraped sites] <%s> failed to create: %s", newScrapedItem.Title, err.Error())
|
logger.Errorf("[scraped sites] <%s> failed to create: %s", newScrapedItem.Title.String, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,8 +388,8 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
|||||||
if sceneJSON.Details != "" {
|
if sceneJSON.Details != "" {
|
||||||
newScene.Details = sql.NullString{String: sceneJSON.Details, Valid: true}
|
newScene.Details = sql.NullString{String: sceneJSON.Details, Valid: true}
|
||||||
}
|
}
|
||||||
if sceneJSON.Url != "" {
|
if sceneJSON.URL != "" {
|
||||||
newScene.Url = sql.NullString{String: sceneJSON.Url, Valid: true}
|
newScene.URL = sql.NullString{String: sceneJSON.URL, Valid: true}
|
||||||
}
|
}
|
||||||
if sceneJSON.Date != "" {
|
if sceneJSON.Date != "" {
|
||||||
newScene.Date = sql.NullString{String: sceneJSON.Date, Valid: true}
|
newScene.Date = sql.NullString{String: sceneJSON.Date, Valid: true}
|
||||||
@@ -427,7 +435,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
|||||||
sqb := models.NewStudioQueryBuilder()
|
sqb := models.NewStudioQueryBuilder()
|
||||||
studio, err := sqb.FindByName(sceneJSON.Studio, tx)
|
studio, err := sqb.FindByName(sceneJSON.Studio, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("[scenes] studio <%s> does not exist: %s", sceneJSON.Studio, err)
|
logger.Warnf("[scenes] studio <%s> does not exist: %s", sceneJSON.Studio, err.Error())
|
||||||
} else {
|
} else {
|
||||||
newScene.StudioID = sql.NullInt64{Int64: int64(studio.ID), Valid: true}
|
newScene.StudioID = sql.NullInt64{Int64: int64(studio.ID), Valid: true}
|
||||||
}
|
}
|
||||||
@@ -451,7 +459,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
|||||||
gqb := models.NewGalleryQueryBuilder()
|
gqb := models.NewGalleryQueryBuilder()
|
||||||
gallery, err := gqb.FindByChecksum(sceneJSON.Gallery, tx)
|
gallery, err := gqb.FindByChecksum(sceneJSON.Gallery, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("[scenes] gallery <%s> does not exist: %s", sceneJSON.Gallery, err)
|
logger.Warnf("[scenes] gallery <%s> does not exist: %s", sceneJSON.Gallery, err.Error())
|
||||||
} else {
|
} else {
|
||||||
gallery.SceneID = sql.NullInt64{Int64: int64(scene.ID), Valid: true}
|
gallery.SceneID = sql.NullInt64{Int64: int64(scene.ID), Valid: true}
|
||||||
_, err := gqb.Update(*gallery, tx)
|
_, err := gqb.Update(*gallery, tx)
|
||||||
@@ -465,7 +473,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
|||||||
if len(sceneJSON.Performers) > 0 {
|
if len(sceneJSON.Performers) > 0 {
|
||||||
performers, err := t.getPerformers(sceneJSON.Performers, tx)
|
performers, err := t.getPerformers(sceneJSON.Performers, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("[scenes] <%s> failed to fetch performers: %s", scene.Checksum, err)
|
logger.Warnf("[scenes] <%s> failed to fetch performers: %s", scene.Checksum, err.Error())
|
||||||
} else {
|
} else {
|
||||||
var performerJoins []models.PerformersScenes
|
var performerJoins []models.PerformersScenes
|
||||||
for _, performer := range performers {
|
for _, performer := range performers {
|
||||||
@@ -485,7 +493,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
|||||||
if len(sceneJSON.Tags) > 0 {
|
if len(sceneJSON.Tags) > 0 {
|
||||||
tags, err := t.getTags(scene.Checksum, sceneJSON.Tags, tx)
|
tags, err := t.getTags(scene.Checksum, sceneJSON.Tags, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("[scenes] <%s> failed to fetch tags: %s", scene.Checksum, err)
|
logger.Warnf("[scenes] <%s> failed to fetch tags: %s", scene.Checksum, err.Error())
|
||||||
} else {
|
} else {
|
||||||
var tagJoins []models.ScenesTags
|
var tagJoins []models.ScenesTags
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
@@ -536,7 +544,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
|||||||
// Get the scene marker tags and create the joins
|
// Get the scene marker tags and create the joins
|
||||||
tags, err := t.getTags(scene.Checksum, marker.Tags, tx)
|
tags, err := t.getTags(scene.Checksum, marker.Tags, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("[scenes] <%s> failed to fetch scene marker tags: %s", scene.Checksum, err)
|
logger.Warnf("[scenes] <%s> failed to fetch scene marker tags: %s", scene.Checksum, err.Error())
|
||||||
} else {
|
} else {
|
||||||
var tagJoins []models.SceneMarkersTags
|
var tagJoins []models.SceneMarkersTags
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
|
|||||||
@@ -42,6 +42,6 @@ func (t *GenerateTranscodeTask) Start(wg *sync.WaitGroup) {
|
|||||||
logger.Errorf("[transcode] error generating transcode: %s", err.Error())
|
logger.Errorf("[transcode] error generating transcode: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Debug("[transcode] <%s> created transcode: ", t.Scene.Checksum)
|
logger.Debugf("[transcode] <%s> created transcode: %s", t.Scene.Checksum, outputPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ type Gallery struct {
|
|||||||
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gallery) GetFiles(baseUrl string) []GalleryFilesType {
|
func (g *Gallery) GetFiles(baseURL string) []GalleryFilesType {
|
||||||
var galleryFiles []GalleryFilesType
|
var galleryFiles []GalleryFilesType
|
||||||
filteredFiles, readCloser, err := g.listZipContents()
|
filteredFiles, readCloser, err := g.listZipContents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -33,9 +33,9 @@ func (g *Gallery) GetFiles(baseUrl string) []GalleryFilesType {
|
|||||||
}
|
}
|
||||||
defer readCloser.Close()
|
defer readCloser.Close()
|
||||||
|
|
||||||
builder := urlbuilders.NewGalleryURLBuilder(baseUrl, g.ID)
|
builder := urlbuilders.NewGalleryURLBuilder(baseURL, g.ID)
|
||||||
for i, file := range filteredFiles {
|
for i, file := range filteredFiles {
|
||||||
galleryURL := builder.GetGalleryImageUrl(i)
|
galleryURL := builder.GetGalleryImageURL(i)
|
||||||
galleryFile := GalleryFilesType{
|
galleryFile := GalleryFilesType{
|
||||||
Index: i,
|
Index: i,
|
||||||
Name: &file.Name,
|
Name: &file.Name,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ type Performer struct {
|
|||||||
Image []byte `db:"image" json:"image"`
|
Image []byte `db:"image" json:"image"`
|
||||||
Checksum string `db:"checksum" json:"checksum"`
|
Checksum string `db:"checksum" json:"checksum"`
|
||||||
Name sql.NullString `db:"name" json:"name"`
|
Name sql.NullString `db:"name" json:"name"`
|
||||||
Url sql.NullString `db:"url" json:"url"`
|
URL sql.NullString `db:"url" json:"url"`
|
||||||
Twitter sql.NullString `db:"twitter" json:"twitter"`
|
Twitter sql.NullString `db:"twitter" json:"twitter"`
|
||||||
Instagram sql.NullString `db:"instagram" json:"instagram"`
|
Instagram sql.NullString `db:"instagram" json:"instagram"`
|
||||||
Birthdate sql.NullString `db:"birthdate" json:"birthdate"` // TODO dates?
|
Birthdate sql.NullString `db:"birthdate" json:"birthdate"` // TODO dates?
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type Scene struct {
|
|||||||
Path string `db:"path" json:"path"`
|
Path string `db:"path" json:"path"`
|
||||||
Title sql.NullString `db:"title" json:"title"`
|
Title sql.NullString `db:"title" json:"title"`
|
||||||
Details sql.NullString `db:"details" json:"details"`
|
Details sql.NullString `db:"details" json:"details"`
|
||||||
Url sql.NullString `db:"url" json:"url"`
|
URL sql.NullString `db:"url" json:"url"`
|
||||||
Date sql.NullString `db:"date" json:"date"` // TODO dates?
|
Date sql.NullString `db:"date" json:"date"` // TODO dates?
|
||||||
Rating sql.NullInt64 `db:"rating" json:"rating"`
|
Rating sql.NullInt64 `db:"rating" json:"rating"`
|
||||||
Size sql.NullString `db:"size" json:"size"`
|
Size sql.NullString `db:"size" json:"size"`
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ type ScrapedItem struct {
|
|||||||
ID int `db:"id" json:"id"`
|
ID int `db:"id" json:"id"`
|
||||||
Title sql.NullString `db:"title" json:"title"`
|
Title sql.NullString `db:"title" json:"title"`
|
||||||
Description sql.NullString `db:"description" json:"description"`
|
Description sql.NullString `db:"description" json:"description"`
|
||||||
Url sql.NullString `db:"url" json:"url"`
|
URL sql.NullString `db:"url" json:"url"`
|
||||||
Date sql.NullString `db:"date" json:"date"` // TODO dates?
|
Date sql.NullString `db:"date" json:"date"` // TODO dates?
|
||||||
Rating sql.NullString `db:"rating" json:"rating"`
|
Rating sql.NullString `db:"rating" json:"rating"`
|
||||||
Tags sql.NullString `db:"tags" json:"tags"`
|
Tags sql.NullString `db:"tags" json:"tags"`
|
||||||
Models sql.NullString `db:"models" json:"models"`
|
Models sql.NullString `db:"models" json:"models"`
|
||||||
Episode sql.NullInt64 `db:"episode" json:"episode"`
|
Episode sql.NullInt64 `db:"episode" json:"episode"`
|
||||||
GalleryFilename sql.NullString `db:"gallery_filename" json:"gallery_filename"`
|
GalleryFilename sql.NullString `db:"gallery_filename" json:"gallery_filename"`
|
||||||
GalleryUrl sql.NullString `db:"gallery_url" json:"gallery_url"`
|
GalleryURL sql.NullString `db:"gallery_url" json:"gallery_url"`
|
||||||
VideoFilename sql.NullString `db:"video_filename" json:"video_filename"`
|
VideoFilename sql.NullString `db:"video_filename" json:"video_filename"`
|
||||||
VideoUrl sql.NullString `db:"video_url" json:"video_url"`
|
VideoURL sql.NullString `db:"video_url" json:"video_url"`
|
||||||
StudioID sql.NullInt64 `db:"studio_id,omitempty" json:"studio_id"`
|
StudioID sql.NullInt64 `db:"studio_id,omitempty" json:"studio_id"`
|
||||||
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
||||||
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ type Studio struct {
|
|||||||
Image []byte `db:"image" json:"image"`
|
Image []byte `db:"image" json:"image"`
|
||||||
Checksum string `db:"checksum" json:"checksum"`
|
Checksum string `db:"checksum" json:"checksum"`
|
||||||
Name sql.NullString `db:"name" json:"name"`
|
Name sql.NullString `db:"name" json:"name"`
|
||||||
Url sql.NullString `db:"url" json:"url"`
|
URL sql.NullString `db:"url" json:"url"`
|
||||||
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
||||||
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
type galleryQueryBuilder struct {}
|
type GalleryQueryBuilder struct{}
|
||||||
|
|
||||||
func NewGalleryQueryBuilder() galleryQueryBuilder {
|
func NewGalleryQueryBuilder() GalleryQueryBuilder {
|
||||||
return galleryQueryBuilder{}
|
return GalleryQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) Create(newGallery Gallery, tx *sqlx.Tx) (*Gallery, error) {
|
func (qb *GalleryQueryBuilder) Create(newGallery Gallery, tx *sqlx.Tx) (*Gallery, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
result, err := tx.NamedExec(
|
result, err := tx.NamedExec(
|
||||||
`INSERT INTO galleries (path, checksum, scene_id, created_at, updated_at)
|
`INSERT INTO galleries (path, checksum, scene_id, created_at, updated_at)
|
||||||
@@ -34,10 +34,10 @@ func (qb *galleryQueryBuilder) Create(newGallery Gallery, tx *sqlx.Tx) (*Gallery
|
|||||||
return &newGallery, nil
|
return &newGallery, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) Update(updatedGallery Gallery, tx *sqlx.Tx) (*Gallery, error) {
|
func (qb *GalleryQueryBuilder) Update(updatedGallery Gallery, tx *sqlx.Tx) (*Gallery, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
`UPDATE galleries SET `+SqlGenKeys(updatedGallery)+` WHERE galleries.id = :id`,
|
`UPDATE galleries SET `+SQLGenKeys(updatedGallery)+` WHERE galleries.id = :id`,
|
||||||
updatedGallery,
|
updatedGallery,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -50,45 +50,45 @@ func (qb *galleryQueryBuilder) Update(updatedGallery Gallery, tx *sqlx.Tx) (*Gal
|
|||||||
return &updatedGallery, nil
|
return &updatedGallery, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) Find(id int) (*Gallery, error) {
|
func (qb *GalleryQueryBuilder) Find(id int) (*Gallery, error) {
|
||||||
query := "SELECT * FROM galleries WHERE id = ? LIMIT 1"
|
query := "SELECT * FROM galleries WHERE id = ? LIMIT 1"
|
||||||
args := []interface{}{id}
|
args := []interface{}{id}
|
||||||
return qb.queryGallery(query, args, nil)
|
return qb.queryGallery(query, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) FindByChecksum(checksum string, tx *sqlx.Tx) (*Gallery, error) {
|
func (qb *GalleryQueryBuilder) FindByChecksum(checksum string, tx *sqlx.Tx) (*Gallery, error) {
|
||||||
query := "SELECT * FROM galleries WHERE checksum = ? LIMIT 1"
|
query := "SELECT * FROM galleries WHERE checksum = ? LIMIT 1"
|
||||||
args := []interface{}{checksum}
|
args := []interface{}{checksum}
|
||||||
return qb.queryGallery(query, args, tx)
|
return qb.queryGallery(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) FindByPath(path string) (*Gallery, error) {
|
func (qb *GalleryQueryBuilder) FindByPath(path string) (*Gallery, error) {
|
||||||
query := "SELECT * FROM galleries WHERE path = ? LIMIT 1"
|
query := "SELECT * FROM galleries WHERE path = ? LIMIT 1"
|
||||||
args := []interface{}{path}
|
args := []interface{}{path}
|
||||||
return qb.queryGallery(query, args, nil)
|
return qb.queryGallery(query, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) (*Gallery, error) {
|
func (qb *GalleryQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) (*Gallery, error) {
|
||||||
query := "SELECT galleries.* FROM galleries JOIN scenes ON scenes.id = galleries.scene_id WHERE scenes.id = ? LIMIT 1"
|
query := "SELECT galleries.* FROM galleries JOIN scenes ON scenes.id = galleries.scene_id WHERE scenes.id = ? LIMIT 1"
|
||||||
args := []interface{}{sceneID}
|
args := []interface{}{sceneID}
|
||||||
return qb.queryGallery(query, args, tx)
|
return qb.queryGallery(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) ValidGalleriesForScenePath(scenePath string) ([]Gallery, error) {
|
func (qb *GalleryQueryBuilder) ValidGalleriesForScenePath(scenePath string) ([]Gallery, error) {
|
||||||
sceneDirPath := filepath.Dir(scenePath)
|
sceneDirPath := filepath.Dir(scenePath)
|
||||||
query := "SELECT galleries.* FROM galleries WHERE galleries.scene_id IS NULL AND galleries.path LIKE '" + sceneDirPath + "%' ORDER BY path ASC"
|
query := "SELECT galleries.* FROM galleries WHERE galleries.scene_id IS NULL AND galleries.path LIKE '" + sceneDirPath + "%' ORDER BY path ASC"
|
||||||
return qb.queryGalleries(query, nil, nil)
|
return qb.queryGalleries(query, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) Count() (int, error) {
|
func (qb *GalleryQueryBuilder) Count() (int, error) {
|
||||||
return runCountQuery(buildCountQuery("SELECT galleries.id FROM galleries"), nil)
|
return runCountQuery(buildCountQuery("SELECT galleries.id FROM galleries"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) All() ([]Gallery, error) {
|
func (qb *GalleryQueryBuilder) All() ([]Gallery, error) {
|
||||||
return qb.queryGalleries(selectAll("galleries")+qb.getGallerySort(nil), nil, nil)
|
return qb.queryGalleries(selectAll("galleries")+qb.getGallerySort(nil), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) Query(findFilter *FindFilterType) ([]Gallery, int) {
|
func (qb *GalleryQueryBuilder) Query(findFilter *FindFilterType) ([]Gallery, int) {
|
||||||
if findFilter == nil {
|
if findFilter == nil {
|
||||||
findFilter = &FindFilterType{}
|
findFilter = &FindFilterType{}
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ func (qb *galleryQueryBuilder) Query(findFilter *FindFilterType) ([]Gallery, int
|
|||||||
return galleries, countResult
|
return galleries, countResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) getGallerySort(findFilter *FindFilterType) string {
|
func (qb *GalleryQueryBuilder) getGallerySort(findFilter *FindFilterType) string {
|
||||||
var sort string
|
var sort string
|
||||||
var direction string
|
var direction string
|
||||||
//if findFilter == nil { // TODO temp until title is removed from schema and UI
|
//if findFilter == nil { // TODO temp until title is removed from schema and UI
|
||||||
@@ -128,7 +128,7 @@ func (qb *galleryQueryBuilder) getGallerySort(findFilter *FindFilterType) string
|
|||||||
return getSort(sort, direction, "galleries")
|
return getSort(sort, direction, "galleries")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) queryGallery(query string, args []interface{}, tx *sqlx.Tx) (*Gallery, error) {
|
func (qb *GalleryQueryBuilder) queryGallery(query string, args []interface{}, tx *sqlx.Tx) (*Gallery, error) {
|
||||||
results, err := qb.queryGalleries(query, args, tx)
|
results, err := qb.queryGalleries(query, args, tx)
|
||||||
if err != nil || len(results) < 1 {
|
if err != nil || len(results) < 1 {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -136,7 +136,7 @@ func (qb *galleryQueryBuilder) queryGallery(query string, args []interface{}, tx
|
|||||||
return &results[0], nil
|
return &results[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *galleryQueryBuilder) queryGalleries(query string, args []interface{}, tx *sqlx.Tx) ([]Gallery, error) {
|
func (qb *GalleryQueryBuilder) queryGalleries(query string, args []interface{}, tx *sqlx.Tx) ([]Gallery, error) {
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
var err error
|
var err error
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package models
|
|||||||
|
|
||||||
import "github.com/jmoiron/sqlx"
|
import "github.com/jmoiron/sqlx"
|
||||||
|
|
||||||
type joinsQueryBuilder struct {}
|
type JoinsQueryBuilder struct{}
|
||||||
|
|
||||||
func NewJoinsQueryBuilder() joinsQueryBuilder {
|
func NewJoinsQueryBuilder() JoinsQueryBuilder {
|
||||||
return joinsQueryBuilder{}
|
return JoinsQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *joinsQueryBuilder) CreatePerformersScenes(newJoins []PerformersScenes, tx *sqlx.Tx) error {
|
func (qb *JoinsQueryBuilder) CreatePerformersScenes(newJoins []PerformersScenes, tx *sqlx.Tx) error {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
for _, join := range newJoins {
|
for _, join := range newJoins {
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
@@ -22,7 +22,7 @@ func (qb *joinsQueryBuilder) CreatePerformersScenes(newJoins []PerformersScenes,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *joinsQueryBuilder) UpdatePerformersScenes(sceneID int, updatedJoins []PerformersScenes, tx *sqlx.Tx) error {
|
func (qb *JoinsQueryBuilder) UpdatePerformersScenes(sceneID int, updatedJoins []PerformersScenes, tx *sqlx.Tx) error {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
|
|
||||||
// Delete the existing joins and then create new ones
|
// Delete the existing joins and then create new ones
|
||||||
@@ -33,7 +33,7 @@ func (qb *joinsQueryBuilder) UpdatePerformersScenes(sceneID int, updatedJoins []
|
|||||||
return qb.CreatePerformersScenes(updatedJoins, tx)
|
return qb.CreatePerformersScenes(updatedJoins, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *joinsQueryBuilder) CreateScenesTags(newJoins []ScenesTags, tx *sqlx.Tx) error {
|
func (qb *JoinsQueryBuilder) CreateScenesTags(newJoins []ScenesTags, tx *sqlx.Tx) error {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
for _, join := range newJoins {
|
for _, join := range newJoins {
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
@@ -47,7 +47,7 @@ func (qb *joinsQueryBuilder) CreateScenesTags(newJoins []ScenesTags, tx *sqlx.Tx
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *joinsQueryBuilder) UpdateScenesTags(sceneID int, updatedJoins []ScenesTags, tx *sqlx.Tx) error {
|
func (qb *JoinsQueryBuilder) UpdateScenesTags(sceneID int, updatedJoins []ScenesTags, tx *sqlx.Tx) error {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
|
|
||||||
// Delete the existing joins and then create new ones
|
// Delete the existing joins and then create new ones
|
||||||
@@ -58,7 +58,7 @@ func (qb *joinsQueryBuilder) UpdateScenesTags(sceneID int, updatedJoins []Scenes
|
|||||||
return qb.CreateScenesTags(updatedJoins, tx)
|
return qb.CreateScenesTags(updatedJoins, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *joinsQueryBuilder) CreateSceneMarkersTags(newJoins []SceneMarkersTags, tx *sqlx.Tx) error {
|
func (qb *JoinsQueryBuilder) CreateSceneMarkersTags(newJoins []SceneMarkersTags, tx *sqlx.Tx) error {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
for _, join := range newJoins {
|
for _, join := range newJoins {
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
@@ -72,7 +72,7 @@ func (qb *joinsQueryBuilder) CreateSceneMarkersTags(newJoins []SceneMarkersTags,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *joinsQueryBuilder) UpdateSceneMarkersTags(sceneMarkerID int, updatedJoins []SceneMarkersTags, tx *sqlx.Tx) error {
|
func (qb *JoinsQueryBuilder) UpdateSceneMarkersTags(sceneMarkerID int, updatedJoins []SceneMarkersTags, tx *sqlx.Tx) error {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
|
|
||||||
// Delete the existing joins and then create new ones
|
// Delete the existing joins and then create new ones
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"github.com/stashapp/stash/database"
|
"github.com/stashapp/stash/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type performerQueryBuilder struct {}
|
type PerformerQueryBuilder struct{}
|
||||||
|
|
||||||
func NewPerformerQueryBuilder() performerQueryBuilder {
|
func NewPerformerQueryBuilder() PerformerQueryBuilder {
|
||||||
return performerQueryBuilder{}
|
return PerformerQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) Create(newPerformer Performer, tx *sqlx.Tx) (*Performer, error) {
|
func (qb *PerformerQueryBuilder) Create(newPerformer Performer, tx *sqlx.Tx) (*Performer, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
result, err := tx.NamedExec(
|
result, err := tx.NamedExec(
|
||||||
`INSERT INTO performers (image, checksum, name, url, twitter, instagram, birthdate, ethnicity, country,
|
`INSERT INTO performers (image, checksum, name, url, twitter, instagram, birthdate, ethnicity, country,
|
||||||
@@ -38,10 +38,10 @@ func (qb *performerQueryBuilder) Create(newPerformer Performer, tx *sqlx.Tx) (*P
|
|||||||
return &newPerformer, nil
|
return &newPerformer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) Update(updatedPerformer Performer, tx *sqlx.Tx) (*Performer, error) {
|
func (qb *PerformerQueryBuilder) Update(updatedPerformer Performer, tx *sqlx.Tx) (*Performer, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
`UPDATE performers SET `+SqlGenKeys(updatedPerformer)+` WHERE performers.id = :id`,
|
`UPDATE performers SET `+SQLGenKeys(updatedPerformer)+` WHERE performers.id = :id`,
|
||||||
updatedPerformer,
|
updatedPerformer,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -54,7 +54,7 @@ func (qb *performerQueryBuilder) Update(updatedPerformer Performer, tx *sqlx.Tx)
|
|||||||
return &updatedPerformer, nil
|
return &updatedPerformer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) Find(id int) (*Performer, error) {
|
func (qb *PerformerQueryBuilder) Find(id int) (*Performer, error) {
|
||||||
query := "SELECT * FROM performers WHERE id = ? LIMIT 1"
|
query := "SELECT * FROM performers WHERE id = ? LIMIT 1"
|
||||||
args := []interface{}{id}
|
args := []interface{}{id}
|
||||||
results, err := qb.queryPerformers(query, args, nil)
|
results, err := qb.queryPerformers(query, args, nil)
|
||||||
@@ -64,7 +64,7 @@ func (qb *performerQueryBuilder) Find(id int) (*Performer, error) {
|
|||||||
return &results[0], nil
|
return &results[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]Performer, error) {
|
func (qb *PerformerQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]Performer, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT performers.* FROM performers
|
SELECT performers.* FROM performers
|
||||||
LEFT JOIN performers_scenes as scenes_join on scenes_join.performer_id = performers.id
|
LEFT JOIN performers_scenes as scenes_join on scenes_join.performer_id = performers.id
|
||||||
@@ -76,7 +76,7 @@ func (qb *performerQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]Perf
|
|||||||
return qb.queryPerformers(query, args, tx)
|
return qb.queryPerformers(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Performer, error) {
|
func (qb *PerformerQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Performer, error) {
|
||||||
query := "SELECT * FROM performers WHERE name IN " + getInBinding(len(names))
|
query := "SELECT * FROM performers WHERE name IN " + getInBinding(len(names))
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
@@ -85,15 +85,15 @@ func (qb *performerQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Per
|
|||||||
return qb.queryPerformers(query, args, tx)
|
return qb.queryPerformers(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) Count() (int, error) {
|
func (qb *PerformerQueryBuilder) Count() (int, error) {
|
||||||
return runCountQuery(buildCountQuery("SELECT performers.id FROM performers"), nil)
|
return runCountQuery(buildCountQuery("SELECT performers.id FROM performers"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) All() ([]Performer, error) {
|
func (qb *PerformerQueryBuilder) All() ([]Performer, error) {
|
||||||
return qb.queryPerformers(selectAll("performers")+qb.getPerformerSort(nil), nil, nil)
|
return qb.queryPerformers(selectAll("performers")+qb.getPerformerSort(nil), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) Query(performerFilter *PerformerFilterType, findFilter *FindFilterType) ([]Performer, int) {
|
func (qb *PerformerQueryBuilder) Query(performerFilter *PerformerFilterType, findFilter *FindFilterType) ([]Performer, int) {
|
||||||
if performerFilter == nil {
|
if performerFilter == nil {
|
||||||
performerFilter = &PerformerFilterType{}
|
performerFilter = &PerformerFilterType{}
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ func (qb *performerQueryBuilder) Query(performerFilter *PerformerFilterType, fin
|
|||||||
return performers, countResult
|
return performers, countResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) getPerformerSort(findFilter *FindFilterType) string {
|
func (qb *PerformerQueryBuilder) getPerformerSort(findFilter *FindFilterType) string {
|
||||||
var sort string
|
var sort string
|
||||||
var direction string
|
var direction string
|
||||||
if findFilter == nil {
|
if findFilter == nil {
|
||||||
@@ -148,7 +148,7 @@ func (qb *performerQueryBuilder) getPerformerSort(findFilter *FindFilterType) st
|
|||||||
return getSort(sort, direction, "performers")
|
return getSort(sort, direction, "performers")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *performerQueryBuilder) queryPerformers(query string, args []interface{}, tx *sqlx.Tx) ([]Performer, error) {
|
func (qb *PerformerQueryBuilder) queryPerformers(query string, args []interface{}, tx *sqlx.Tx) ([]Performer, error) {
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
var err error
|
var err error
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ WHERE tags.id = ?
|
|||||||
GROUP BY scenes.id
|
GROUP BY scenes.id
|
||||||
`
|
`
|
||||||
|
|
||||||
type sceneQueryBuilder struct{}
|
type SceneQueryBuilder struct{}
|
||||||
|
|
||||||
func NewSceneQueryBuilder() sceneQueryBuilder {
|
func NewSceneQueryBuilder() SceneQueryBuilder {
|
||||||
return sceneQueryBuilder{}
|
return SceneQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) Create(newScene Scene, tx *sqlx.Tx) (*Scene, error) {
|
func (qb *SceneQueryBuilder) Create(newScene Scene, tx *sqlx.Tx) (*Scene, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
result, err := tx.NamedExec(
|
result, err := tx.NamedExec(
|
||||||
`INSERT INTO scenes (checksum, path, title, details, url, date, rating, size, duration, video_codec,
|
`INSERT INTO scenes (checksum, path, title, details, url, date, rating, size, duration, video_codec,
|
||||||
@@ -60,10 +60,10 @@ func (qb *sceneQueryBuilder) Create(newScene Scene, tx *sqlx.Tx) (*Scene, error)
|
|||||||
return &newScene, nil
|
return &newScene, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) Update(updatedScene Scene, tx *sqlx.Tx) (*Scene, error) {
|
func (qb *SceneQueryBuilder) Update(updatedScene Scene, tx *sqlx.Tx) (*Scene, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
`UPDATE scenes SET `+SqlGenKeys(updatedScene)+` WHERE scenes.id = :id`,
|
`UPDATE scenes SET `+SQLGenKeys(updatedScene)+` WHERE scenes.id = :id`,
|
||||||
updatedScene,
|
updatedScene,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -76,54 +76,54 @@ func (qb *sceneQueryBuilder) Update(updatedScene Scene, tx *sqlx.Tx) (*Scene, er
|
|||||||
return &updatedScene, nil
|
return &updatedScene, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) Find(id int) (*Scene, error) {
|
func (qb *SceneQueryBuilder) Find(id int) (*Scene, error) {
|
||||||
query := "SELECT * FROM scenes WHERE id = ? LIMIT 1"
|
query := "SELECT * FROM scenes WHERE id = ? LIMIT 1"
|
||||||
args := []interface{}{id}
|
args := []interface{}{id}
|
||||||
return qb.queryScene(query, args, nil)
|
return qb.queryScene(query, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) FindByChecksum(checksum string) (*Scene, error) {
|
func (qb *SceneQueryBuilder) FindByChecksum(checksum string) (*Scene, error) {
|
||||||
query := "SELECT * FROM scenes WHERE checksum = ? LIMIT 1"
|
query := "SELECT * FROM scenes WHERE checksum = ? LIMIT 1"
|
||||||
args := []interface{}{checksum}
|
args := []interface{}{checksum}
|
||||||
return qb.queryScene(query, args, nil)
|
return qb.queryScene(query, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) FindByPath(path string) (*Scene, error) {
|
func (qb *SceneQueryBuilder) FindByPath(path string) (*Scene, error) {
|
||||||
query := "SELECT * FROM scenes WHERE path = ? LIMIT 1"
|
query := "SELECT * FROM scenes WHERE path = ? LIMIT 1"
|
||||||
args := []interface{}{path}
|
args := []interface{}{path}
|
||||||
return qb.queryScene(query, args, nil)
|
return qb.queryScene(query, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) FindByPerformerID(performerID int) ([]Scene, error) {
|
func (qb *SceneQueryBuilder) FindByPerformerID(performerID int) ([]Scene, error) {
|
||||||
args := []interface{}{performerID}
|
args := []interface{}{performerID}
|
||||||
return qb.queryScenes(scenesForPerformerQuery, args, nil)
|
return qb.queryScenes(scenesForPerformerQuery, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) CountByPerformerID(performerID int) (int, error) {
|
func (qb *SceneQueryBuilder) CountByPerformerID(performerID int) (int, error) {
|
||||||
args := []interface{}{performerID}
|
args := []interface{}{performerID}
|
||||||
return runCountQuery(buildCountQuery(scenesForPerformerQuery), args)
|
return runCountQuery(buildCountQuery(scenesForPerformerQuery), args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) FindByStudioID(studioID int) ([]Scene, error) {
|
func (qb *SceneQueryBuilder) FindByStudioID(studioID int) ([]Scene, error) {
|
||||||
args := []interface{}{studioID}
|
args := []interface{}{studioID}
|
||||||
return qb.queryScenes(scenesForStudioQuery, args, nil)
|
return qb.queryScenes(scenesForStudioQuery, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) Count() (int, error) {
|
func (qb *SceneQueryBuilder) Count() (int, error) {
|
||||||
return runCountQuery(buildCountQuery("SELECT scenes.id FROM scenes"), nil)
|
return runCountQuery(buildCountQuery("SELECT scenes.id FROM scenes"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) CountByStudioID(studioID int) (int, error) {
|
func (qb *SceneQueryBuilder) CountByStudioID(studioID int) (int, error) {
|
||||||
args := []interface{}{studioID}
|
args := []interface{}{studioID}
|
||||||
return runCountQuery(buildCountQuery(scenesForStudioQuery), args)
|
return runCountQuery(buildCountQuery(scenesForStudioQuery), args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) CountByTagID(tagID int) (int, error) {
|
func (qb *SceneQueryBuilder) CountByTagID(tagID int) (int, error) {
|
||||||
args := []interface{}{tagID}
|
args := []interface{}{tagID}
|
||||||
return runCountQuery(buildCountQuery(scenesForTagQuery), args)
|
return runCountQuery(buildCountQuery(scenesForTagQuery), args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) Wall(q *string) ([]Scene, error) {
|
func (qb *SceneQueryBuilder) Wall(q *string) ([]Scene, error) {
|
||||||
s := ""
|
s := ""
|
||||||
if q != nil {
|
if q != nil {
|
||||||
s = *q
|
s = *q
|
||||||
@@ -132,11 +132,11 @@ func (qb *sceneQueryBuilder) Wall(q *string) ([]Scene, error) {
|
|||||||
return qb.queryScenes(query, nil, nil)
|
return qb.queryScenes(query, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) All() ([]Scene, error) {
|
func (qb *SceneQueryBuilder) All() ([]Scene, error) {
|
||||||
return qb.queryScenes(selectAll("scenes")+qb.getSceneSort(nil), nil, nil)
|
return qb.queryScenes(selectAll("scenes")+qb.getSceneSort(nil), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *FindFilterType) ([]Scene, int) {
|
func (qb *SceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *FindFilterType) ([]Scene, int) {
|
||||||
if sceneFilter == nil {
|
if sceneFilter == nil {
|
||||||
sceneFilter = &SceneFilterType{}
|
sceneFilter = &SceneFilterType{}
|
||||||
}
|
}
|
||||||
@@ -209,8 +209,8 @@ func (qb *sceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tagsFilter := sceneFilter.Tags; len(tagsFilter) > 0 {
|
if tagsFilter := sceneFilter.Tags; len(tagsFilter) > 0 {
|
||||||
for _, tagId := range tagsFilter {
|
for _, tagID := range tagsFilter {
|
||||||
args = append(args, tagId)
|
args = append(args, tagID)
|
||||||
}
|
}
|
||||||
|
|
||||||
whereClauses = append(whereClauses, "tags.id IN "+getInBinding(len(tagsFilter)))
|
whereClauses = append(whereClauses, "tags.id IN "+getInBinding(len(tagsFilter)))
|
||||||
@@ -239,17 +239,16 @@ func (qb *sceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
|
|||||||
return scenes, countResult
|
return scenes, countResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) getSceneSort(findFilter *FindFilterType) string {
|
func (qb *SceneQueryBuilder) getSceneSort(findFilter *FindFilterType) string {
|
||||||
if findFilter == nil {
|
if findFilter == nil {
|
||||||
return " ORDER BY scenes.path, scenes.date ASC "
|
return " ORDER BY scenes.path, scenes.date ASC "
|
||||||
} else {
|
}
|
||||||
sort := findFilter.GetSort("title")
|
sort := findFilter.GetSort("title")
|
||||||
direction := findFilter.GetDirection()
|
direction := findFilter.GetDirection()
|
||||||
return getSort(sort, direction, "scenes")
|
return getSort(sort, direction, "scenes")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) queryScene(query string, args []interface{}, tx *sqlx.Tx) (*Scene, error) {
|
func (qb *SceneQueryBuilder) queryScene(query string, args []interface{}, tx *sqlx.Tx) (*Scene, error) {
|
||||||
results, err := qb.queryScenes(query, args, tx)
|
results, err := qb.queryScenes(query, args, tx)
|
||||||
if err != nil || len(results) < 1 {
|
if err != nil || len(results) < 1 {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -257,7 +256,7 @@ func (qb *sceneQueryBuilder) queryScene(query string, args []interface{}, tx *sq
|
|||||||
return &results[0], nil
|
return &results[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneQueryBuilder) queryScenes(query string, args []interface{}, tx *sqlx.Tx) ([]Scene, error) {
|
func (qb *SceneQueryBuilder) queryScenes(query string, args []interface{}, tx *sqlx.Tx) ([]Scene, error) {
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
var err error
|
var err error
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ WHERE tags.id = ?
|
|||||||
GROUP BY scene_markers.id
|
GROUP BY scene_markers.id
|
||||||
`
|
`
|
||||||
|
|
||||||
type sceneMarkerQueryBuilder struct {}
|
type SceneMarkerQueryBuilder struct{}
|
||||||
|
|
||||||
func NewSceneMarkerQueryBuilder() sceneMarkerQueryBuilder {
|
func NewSceneMarkerQueryBuilder() SceneMarkerQueryBuilder {
|
||||||
return sceneMarkerQueryBuilder{}
|
return SceneMarkerQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) Create(newSceneMarker SceneMarker, tx *sqlx.Tx) (*SceneMarker, error) {
|
func (qb *SceneMarkerQueryBuilder) Create(newSceneMarker SceneMarker, tx *sqlx.Tx) (*SceneMarker, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
result, err := tx.NamedExec(
|
result, err := tx.NamedExec(
|
||||||
`INSERT INTO scene_markers (title, seconds, primary_tag_id, scene_id, created_at, updated_at)
|
`INSERT INTO scene_markers (title, seconds, primary_tag_id, scene_id, created_at, updated_at)
|
||||||
@@ -43,10 +43,10 @@ func (qb *sceneMarkerQueryBuilder) Create(newSceneMarker SceneMarker, tx *sqlx.T
|
|||||||
return &newSceneMarker, nil
|
return &newSceneMarker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) Update(updatedSceneMarker SceneMarker, tx *sqlx.Tx) (*SceneMarker, error) {
|
func (qb *SceneMarkerQueryBuilder) Update(updatedSceneMarker SceneMarker, tx *sqlx.Tx) (*SceneMarker, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
`UPDATE scene_markers SET `+SqlGenKeys(updatedSceneMarker)+` WHERE scene_markers.id = :id`,
|
`UPDATE scene_markers SET `+SQLGenKeys(updatedSceneMarker)+` WHERE scene_markers.id = :id`,
|
||||||
updatedSceneMarker,
|
updatedSceneMarker,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -59,11 +59,11 @@ func (qb *sceneMarkerQueryBuilder) Update(updatedSceneMarker SceneMarker, tx *sq
|
|||||||
return &updatedSceneMarker, nil
|
return &updatedSceneMarker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) Destroy(id string, tx *sqlx.Tx) error {
|
func (qb *SceneMarkerQueryBuilder) Destroy(id string, tx *sqlx.Tx) error {
|
||||||
return executeDeleteQuery("scene_markers", id, tx)
|
return executeDeleteQuery("scene_markers", id, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) Find(id int) (*SceneMarker, error) {
|
func (qb *SceneMarkerQueryBuilder) Find(id int) (*SceneMarker, error) {
|
||||||
query := "SELECT * FROM scene_markers WHERE id = ? LIMIT 1"
|
query := "SELECT * FROM scene_markers WHERE id = ? LIMIT 1"
|
||||||
args := []interface{}{id}
|
args := []interface{}{id}
|
||||||
results, err := qb.querySceneMarkers(query, args, nil)
|
results, err := qb.querySceneMarkers(query, args, nil)
|
||||||
@@ -73,7 +73,7 @@ func (qb *sceneMarkerQueryBuilder) Find(id int) (*SceneMarker, error) {
|
|||||||
return &results[0], nil
|
return &results[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]SceneMarker, error) {
|
func (qb *SceneMarkerQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]SceneMarker, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT scene_markers.* FROM scene_markers
|
SELECT scene_markers.* FROM scene_markers
|
||||||
JOIN scenes ON scenes.id = scene_markers.scene_id
|
JOIN scenes ON scenes.id = scene_markers.scene_id
|
||||||
@@ -85,12 +85,12 @@ func (qb *sceneMarkerQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]Sc
|
|||||||
return qb.querySceneMarkers(query, args, tx)
|
return qb.querySceneMarkers(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) CountByTagID(tagID int) (int, error) {
|
func (qb *SceneMarkerQueryBuilder) CountByTagID(tagID int) (int, error) {
|
||||||
args := []interface{}{tagID}
|
args := []interface{}{tagID}
|
||||||
return runCountQuery(buildCountQuery(sceneMarkersForTagQuery), args)
|
return runCountQuery(buildCountQuery(sceneMarkersForTagQuery), args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) GetMarkerStrings(q *string, sort *string) ([]*MarkerStringsResultType, error) {
|
func (qb *SceneMarkerQueryBuilder) GetMarkerStrings(q *string, sort *string) ([]*MarkerStringsResultType, error) {
|
||||||
query := "SELECT count(*) as `count`, scene_markers.id as id, scene_markers.title as title FROM scene_markers"
|
query := "SELECT count(*) as `count`, scene_markers.id as id, scene_markers.title as title FROM scene_markers"
|
||||||
if q != nil {
|
if q != nil {
|
||||||
query = query + " WHERE title LIKE '%" + *q + "%'"
|
query = query + " WHERE title LIKE '%" + *q + "%'"
|
||||||
@@ -105,7 +105,7 @@ func (qb *sceneMarkerQueryBuilder) GetMarkerStrings(q *string, sort *string) ([]
|
|||||||
return qb.queryMarkerStringsResultType(query, args)
|
return qb.queryMarkerStringsResultType(query, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) Wall(q *string) ([]SceneMarker, error) {
|
func (qb *SceneMarkerQueryBuilder) Wall(q *string) ([]SceneMarker, error) {
|
||||||
s := ""
|
s := ""
|
||||||
if q != nil {
|
if q != nil {
|
||||||
s = *q
|
s = *q
|
||||||
@@ -114,7 +114,7 @@ func (qb *sceneMarkerQueryBuilder) Wall(q *string) ([]SceneMarker, error) {
|
|||||||
return qb.querySceneMarkers(query, nil, nil)
|
return qb.querySceneMarkers(query, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) Query(sceneMarkerFilter *SceneMarkerFilterType, findFilter *FindFilterType) ([]SceneMarker, int) {
|
func (qb *SceneMarkerQueryBuilder) Query(sceneMarkerFilter *SceneMarkerFilterType, findFilter *FindFilterType) ([]SceneMarker, int) {
|
||||||
if sceneMarkerFilter == nil {
|
if sceneMarkerFilter == nil {
|
||||||
sceneMarkerFilter = &SceneMarkerFilterType{}
|
sceneMarkerFilter = &SceneMarkerFilterType{}
|
||||||
}
|
}
|
||||||
@@ -195,13 +195,13 @@ func (qb *sceneMarkerQueryBuilder) Query(sceneMarkerFilter *SceneMarkerFilterTyp
|
|||||||
return sceneMarkers, countResult
|
return sceneMarkers, countResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) getSceneMarkerSort(findFilter *FindFilterType) string {
|
func (qb *SceneMarkerQueryBuilder) getSceneMarkerSort(findFilter *FindFilterType) string {
|
||||||
sort := findFilter.GetSort("title")
|
sort := findFilter.GetSort("title")
|
||||||
direction := findFilter.GetDirection()
|
direction := findFilter.GetDirection()
|
||||||
return getSort(sort, direction, "scene_markers")
|
return getSort(sort, direction, "scene_markers")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) querySceneMarkers(query string, args []interface{}, tx *sqlx.Tx) ([]SceneMarker, error) {
|
func (qb *SceneMarkerQueryBuilder) querySceneMarkers(query string, args []interface{}, tx *sqlx.Tx) ([]SceneMarker, error) {
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
var err error
|
var err error
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
@@ -231,7 +231,7 @@ func (qb *sceneMarkerQueryBuilder) querySceneMarkers(query string, args []interf
|
|||||||
return sceneMarkers, nil
|
return sceneMarkers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *sceneMarkerQueryBuilder) queryMarkerStringsResultType(query string, args []interface{}) ([]*MarkerStringsResultType, error) {
|
func (qb *SceneMarkerQueryBuilder) queryMarkerStringsResultType(query string, args []interface{}) ([]*MarkerStringsResultType, error) {
|
||||||
rows, err := database.DB.Queryx(query, args...)
|
rows, err := database.DB.Queryx(query, args...)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"github.com/stashapp/stash/database"
|
"github.com/stashapp/stash/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type scrapedItemQueryBuilder struct{}
|
type ScrapedItemQueryBuilder struct{}
|
||||||
|
|
||||||
func NewScrapedItemQueryBuilder() scrapedItemQueryBuilder {
|
func NewScrapedItemQueryBuilder() ScrapedItemQueryBuilder {
|
||||||
return scrapedItemQueryBuilder{}
|
return ScrapedItemQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *scrapedItemQueryBuilder) Create(newScrapedItem ScrapedItem, tx *sqlx.Tx) (*ScrapedItem, error) {
|
func (qb *ScrapedItemQueryBuilder) Create(newScrapedItem ScrapedItem, tx *sqlx.Tx) (*ScrapedItem, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
result, err := tx.NamedExec(
|
result, err := tx.NamedExec(
|
||||||
`INSERT INTO scraped_items (title, description, url, date, rating, tags, models, episode, gallery_filename,
|
`INSERT INTO scraped_items (title, description, url, date, rating, tags, models, episode, gallery_filename,
|
||||||
@@ -35,10 +35,10 @@ func (qb *scrapedItemQueryBuilder) Create(newScrapedItem ScrapedItem, tx *sqlx.T
|
|||||||
return &newScrapedItem, nil
|
return &newScrapedItem, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *scrapedItemQueryBuilder) Update(updatedScrapedItem ScrapedItem, tx *sqlx.Tx) (*ScrapedItem, error) {
|
func (qb *ScrapedItemQueryBuilder) Update(updatedScrapedItem ScrapedItem, tx *sqlx.Tx) (*ScrapedItem, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
`UPDATE scraped_items SET `+SqlGenKeys(updatedScrapedItem)+` WHERE scraped_items.id = :id`,
|
`UPDATE scraped_items SET `+SQLGenKeys(updatedScrapedItem)+` WHERE scraped_items.id = :id`,
|
||||||
updatedScrapedItem,
|
updatedScrapedItem,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -51,17 +51,17 @@ func (qb *scrapedItemQueryBuilder) Update(updatedScrapedItem ScrapedItem, tx *sq
|
|||||||
return &updatedScrapedItem, nil
|
return &updatedScrapedItem, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *scrapedItemQueryBuilder) Find(id int) (*ScrapedItem, error) {
|
func (qb *ScrapedItemQueryBuilder) Find(id int) (*ScrapedItem, error) {
|
||||||
query := "SELECT * FROM scraped_items WHERE id = ? LIMIT 1"
|
query := "SELECT * FROM scraped_items WHERE id = ? LIMIT 1"
|
||||||
args := []interface{}{id}
|
args := []interface{}{id}
|
||||||
return qb.queryScrapedItem(query, args, nil)
|
return qb.queryScrapedItem(query, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *scrapedItemQueryBuilder) All() ([]ScrapedItem, error) {
|
func (qb *ScrapedItemQueryBuilder) All() ([]ScrapedItem, error) {
|
||||||
return qb.queryScrapedItems(selectAll("scraped_items")+qb.getScrapedItemsSort(nil), nil, nil)
|
return qb.queryScrapedItems(selectAll("scraped_items")+qb.getScrapedItemsSort(nil), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *scrapedItemQueryBuilder) getScrapedItemsSort(findFilter *FindFilterType) string {
|
func (qb *ScrapedItemQueryBuilder) getScrapedItemsSort(findFilter *FindFilterType) string {
|
||||||
var sort string
|
var sort string
|
||||||
var direction string
|
var direction string
|
||||||
if findFilter == nil {
|
if findFilter == nil {
|
||||||
@@ -74,7 +74,7 @@ func (qb *scrapedItemQueryBuilder) getScrapedItemsSort(findFilter *FindFilterTyp
|
|||||||
return getSort(sort, direction, "scraped_items")
|
return getSort(sort, direction, "scraped_items")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *scrapedItemQueryBuilder) queryScrapedItem(query string, args []interface{}, tx *sqlx.Tx) (*ScrapedItem, error) {
|
func (qb *ScrapedItemQueryBuilder) queryScrapedItem(query string, args []interface{}, tx *sqlx.Tx) (*ScrapedItem, error) {
|
||||||
results, err := qb.queryScrapedItems(query, args, tx)
|
results, err := qb.queryScrapedItems(query, args, tx)
|
||||||
if err != nil || len(results) < 1 {
|
if err != nil || len(results) < 1 {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -82,7 +82,7 @@ func (qb *scrapedItemQueryBuilder) queryScrapedItem(query string, args []interfa
|
|||||||
return &results[0], nil
|
return &results[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *scrapedItemQueryBuilder) queryScrapedItems(query string, args []interface{}, tx *sqlx.Tx) ([]ScrapedItem, error) {
|
func (qb *ScrapedItemQueryBuilder) queryScrapedItems(query string, args []interface{}, tx *sqlx.Tx) ([]ScrapedItem, error) {
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
var err error
|
var err error
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ func ensureTx(tx *sqlx.Tx) {
|
|||||||
// sqlGenKeys is used for passing a struct and returning a string
|
// sqlGenKeys is used for passing a struct and returning a string
|
||||||
// of keys for non empty key:values. These keys are formated
|
// of keys for non empty key:values. These keys are formated
|
||||||
// keyname=:keyname with a comma seperating them
|
// keyname=:keyname with a comma seperating them
|
||||||
func SqlGenKeys(i interface{}) string {
|
func SQLGenKeys(i interface{}) string {
|
||||||
var query []string
|
var query []string
|
||||||
v := reflect.ValueOf(i)
|
v := reflect.ValueOf(i)
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"github.com/stashapp/stash/database"
|
"github.com/stashapp/stash/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type studioQueryBuilder struct {}
|
type StudioQueryBuilder struct{}
|
||||||
|
|
||||||
func NewStudioQueryBuilder() studioQueryBuilder {
|
func NewStudioQueryBuilder() StudioQueryBuilder {
|
||||||
return studioQueryBuilder{}
|
return StudioQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) Create(newStudio Studio, tx *sqlx.Tx) (*Studio, error) {
|
func (qb *StudioQueryBuilder) Create(newStudio Studio, tx *sqlx.Tx) (*Studio, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
result, err := tx.NamedExec(
|
result, err := tx.NamedExec(
|
||||||
`INSERT INTO studios (image, checksum, name, url, created_at, updated_at)
|
`INSERT INTO studios (image, checksum, name, url, created_at, updated_at)
|
||||||
@@ -34,10 +34,10 @@ func (qb *studioQueryBuilder) Create(newStudio Studio, tx *sqlx.Tx) (*Studio, er
|
|||||||
return &newStudio, nil
|
return &newStudio, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) Update(updatedStudio Studio, tx *sqlx.Tx) (*Studio, error) {
|
func (qb *StudioQueryBuilder) Update(updatedStudio Studio, tx *sqlx.Tx) (*Studio, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
`UPDATE studios SET `+SqlGenKeys(updatedStudio)+` WHERE studios.id = :id`,
|
`UPDATE studios SET `+SQLGenKeys(updatedStudio)+` WHERE studios.id = :id`,
|
||||||
updatedStudio,
|
updatedStudio,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -50,33 +50,33 @@ func (qb *studioQueryBuilder) Update(updatedStudio Studio, tx *sqlx.Tx) (*Studio
|
|||||||
return &updatedStudio, nil
|
return &updatedStudio, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) Find(id int, tx *sqlx.Tx) (*Studio, error) {
|
func (qb *StudioQueryBuilder) Find(id int, tx *sqlx.Tx) (*Studio, error) {
|
||||||
query := "SELECT * FROM studios WHERE id = ? LIMIT 1"
|
query := "SELECT * FROM studios WHERE id = ? LIMIT 1"
|
||||||
args := []interface{}{id}
|
args := []interface{}{id}
|
||||||
return qb.queryStudio(query, args, tx)
|
return qb.queryStudio(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) FindBySceneID(sceneID int) (*Studio, error) {
|
func (qb *StudioQueryBuilder) FindBySceneID(sceneID int) (*Studio, error) {
|
||||||
query := "SELECT studios.* FROM studios JOIN scenes ON studios.id = scenes.studio_id WHERE scenes.id = ? LIMIT 1"
|
query := "SELECT studios.* FROM studios JOIN scenes ON studios.id = scenes.studio_id WHERE scenes.id = ? LIMIT 1"
|
||||||
args := []interface{}{sceneID}
|
args := []interface{}{sceneID}
|
||||||
return qb.queryStudio(query, args, nil)
|
return qb.queryStudio(query, args, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) FindByName(name string, tx *sqlx.Tx) (*Studio, error) {
|
func (qb *StudioQueryBuilder) FindByName(name string, tx *sqlx.Tx) (*Studio, error) {
|
||||||
query := "SELECT * FROM studios WHERE name = ? LIMIT 1"
|
query := "SELECT * FROM studios WHERE name = ? LIMIT 1"
|
||||||
args := []interface{}{name}
|
args := []interface{}{name}
|
||||||
return qb.queryStudio(query, args, tx)
|
return qb.queryStudio(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) Count() (int, error) {
|
func (qb *StudioQueryBuilder) Count() (int, error) {
|
||||||
return runCountQuery(buildCountQuery("SELECT studios.id FROM studios"), nil)
|
return runCountQuery(buildCountQuery("SELECT studios.id FROM studios"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) All() ([]Studio, error) {
|
func (qb *StudioQueryBuilder) All() ([]Studio, error) {
|
||||||
return qb.queryStudios(selectAll("studios")+qb.getStudioSort(nil), nil, nil)
|
return qb.queryStudios(selectAll("studios")+qb.getStudioSort(nil), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) Query(findFilter *FindFilterType) ([]Studio, int) {
|
func (qb *StudioQueryBuilder) Query(findFilter *FindFilterType) ([]Studio, int) {
|
||||||
if findFilter == nil {
|
if findFilter == nil {
|
||||||
findFilter = &FindFilterType{}
|
findFilter = &FindFilterType{}
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ func (qb *studioQueryBuilder) Query(findFilter *FindFilterType) ([]Studio, int)
|
|||||||
return studios, countResult
|
return studios, countResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) getStudioSort(findFilter *FindFilterType) string {
|
func (qb *StudioQueryBuilder) getStudioSort(findFilter *FindFilterType) string {
|
||||||
var sort string
|
var sort string
|
||||||
var direction string
|
var direction string
|
||||||
if findFilter == nil {
|
if findFilter == nil {
|
||||||
@@ -116,7 +116,7 @@ func (qb *studioQueryBuilder) getStudioSort(findFilter *FindFilterType) string {
|
|||||||
return getSort(sort, direction, "studios")
|
return getSort(sort, direction, "studios")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) queryStudio(query string, args []interface{}, tx *sqlx.Tx) (*Studio, error) {
|
func (qb *StudioQueryBuilder) queryStudio(query string, args []interface{}, tx *sqlx.Tx) (*Studio, error) {
|
||||||
results, err := qb.queryStudios(query, args, tx)
|
results, err := qb.queryStudios(query, args, tx)
|
||||||
if err != nil || len(results) < 1 {
|
if err != nil || len(results) < 1 {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -124,7 +124,7 @@ func (qb *studioQueryBuilder) queryStudio(query string, args []interface{}, tx *
|
|||||||
return &results[0], nil
|
return &results[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *studioQueryBuilder) queryStudios(query string, args []interface{}, tx *sqlx.Tx) ([]Studio, error) {
|
func (qb *StudioQueryBuilder) queryStudios(query string, args []interface{}, tx *sqlx.Tx) ([]Studio, error) {
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
var err error
|
var err error
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"github.com/stashapp/stash/database"
|
"github.com/stashapp/stash/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tagQueryBuilder struct {}
|
type TagQueryBuilder struct{}
|
||||||
|
|
||||||
func NewTagQueryBuilder() tagQueryBuilder {
|
func NewTagQueryBuilder() TagQueryBuilder {
|
||||||
return tagQueryBuilder{}
|
return TagQueryBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) Create(newTag Tag, tx *sqlx.Tx) (*Tag, error) {
|
func (qb *TagQueryBuilder) Create(newTag Tag, tx *sqlx.Tx) (*Tag, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
result, err := tx.NamedExec(
|
result, err := tx.NamedExec(
|
||||||
`INSERT INTO tags (name, created_at, updated_at)
|
`INSERT INTO tags (name, created_at, updated_at)
|
||||||
@@ -34,9 +34,9 @@ func (qb *tagQueryBuilder) Create(newTag Tag, tx *sqlx.Tx) (*Tag, error) {
|
|||||||
return &newTag, nil
|
return &newTag, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) Update(updatedTag Tag, tx *sqlx.Tx) (*Tag, error) {
|
func (qb *TagQueryBuilder) Update(updatedTag Tag, tx *sqlx.Tx) (*Tag, error) {
|
||||||
ensureTx(tx)
|
ensureTx(tx)
|
||||||
query := `UPDATE tags SET `+SqlGenKeys(updatedTag)+` WHERE tags.id = :id`
|
query := `UPDATE tags SET ` + SQLGenKeys(updatedTag) + ` WHERE tags.id = :id`
|
||||||
_, err := tx.NamedExec(
|
_, err := tx.NamedExec(
|
||||||
query,
|
query,
|
||||||
updatedTag,
|
updatedTag,
|
||||||
@@ -51,17 +51,17 @@ func (qb *tagQueryBuilder) Update(updatedTag Tag, tx *sqlx.Tx) (*Tag, error) {
|
|||||||
return &updatedTag, nil
|
return &updatedTag, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) Destroy(id string, tx *sqlx.Tx) error {
|
func (qb *TagQueryBuilder) Destroy(id string, tx *sqlx.Tx) error {
|
||||||
return executeDeleteQuery("tags", id, tx)
|
return executeDeleteQuery("tags", id, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) Find(id int, tx *sqlx.Tx) (*Tag, error) {
|
func (qb *TagQueryBuilder) Find(id int, tx *sqlx.Tx) (*Tag, error) {
|
||||||
query := "SELECT * FROM tags WHERE id = ? LIMIT 1"
|
query := "SELECT * FROM tags WHERE id = ? LIMIT 1"
|
||||||
args := []interface{}{id}
|
args := []interface{}{id}
|
||||||
return qb.queryTag(query, args, tx)
|
return qb.queryTag(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]Tag, error) {
|
func (qb *TagQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]Tag, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT tags.* FROM tags
|
SELECT tags.* FROM tags
|
||||||
LEFT JOIN scenes_tags as scenes_join on scenes_join.tag_id = tags.id
|
LEFT JOIN scenes_tags as scenes_join on scenes_join.tag_id = tags.id
|
||||||
@@ -74,7 +74,7 @@ func (qb *tagQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]Tag, error
|
|||||||
return qb.queryTags(query, args, tx)
|
return qb.queryTags(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) FindBySceneMarkerID(sceneMarkerID int, tx *sqlx.Tx) ([]Tag, error) {
|
func (qb *TagQueryBuilder) FindBySceneMarkerID(sceneMarkerID int, tx *sqlx.Tx) ([]Tag, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT tags.* FROM tags
|
SELECT tags.* FROM tags
|
||||||
LEFT JOIN scene_markers_tags as scene_markers_join on scene_markers_join.tag_id = tags.id
|
LEFT JOIN scene_markers_tags as scene_markers_join on scene_markers_join.tag_id = tags.id
|
||||||
@@ -87,13 +87,13 @@ func (qb *tagQueryBuilder) FindBySceneMarkerID(sceneMarkerID int, tx *sqlx.Tx) (
|
|||||||
return qb.queryTags(query, args, tx)
|
return qb.queryTags(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) FindByName(name string, tx *sqlx.Tx) (*Tag, error) {
|
func (qb *TagQueryBuilder) FindByName(name string, tx *sqlx.Tx) (*Tag, error) {
|
||||||
query := "SELECT * FROM tags WHERE name = ? LIMIT 1"
|
query := "SELECT * FROM tags WHERE name = ? LIMIT 1"
|
||||||
args := []interface{}{name}
|
args := []interface{}{name}
|
||||||
return qb.queryTag(query, args, tx)
|
return qb.queryTag(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Tag, error) {
|
func (qb *TagQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Tag, error) {
|
||||||
query := "SELECT * FROM tags WHERE name IN " + getInBinding(len(names))
|
query := "SELECT * FROM tags WHERE name IN " + getInBinding(len(names))
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
@@ -102,15 +102,15 @@ func (qb *tagQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Tag, erro
|
|||||||
return qb.queryTags(query, args, tx)
|
return qb.queryTags(query, args, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) Count() (int, error) {
|
func (qb *TagQueryBuilder) Count() (int, error) {
|
||||||
return runCountQuery(buildCountQuery("SELECT tags.id FROM tags"), nil)
|
return runCountQuery(buildCountQuery("SELECT tags.id FROM tags"), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) All() ([]Tag, error) {
|
func (qb *TagQueryBuilder) All() ([]Tag, error) {
|
||||||
return qb.queryTags(selectAll("tags")+qb.getTagSort(nil), nil, nil)
|
return qb.queryTags(selectAll("tags")+qb.getTagSort(nil), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) getTagSort(findFilter *FindFilterType) string {
|
func (qb *TagQueryBuilder) getTagSort(findFilter *FindFilterType) string {
|
||||||
var sort string
|
var sort string
|
||||||
var direction string
|
var direction string
|
||||||
if findFilter == nil {
|
if findFilter == nil {
|
||||||
@@ -123,7 +123,7 @@ func (qb *tagQueryBuilder) getTagSort(findFilter *FindFilterType) string {
|
|||||||
return getSort(sort, direction, "tags")
|
return getSort(sort, direction, "tags")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) queryTag(query string, args []interface{}, tx *sqlx.Tx) (*Tag, error) {
|
func (qb *TagQueryBuilder) queryTag(query string, args []interface{}, tx *sqlx.Tx) (*Tag, error) {
|
||||||
results, err := qb.queryTags(query, args, tx)
|
results, err := qb.queryTags(query, args, tx)
|
||||||
if err != nil || len(results) < 1 {
|
if err != nil || len(results) < 1 {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -131,7 +131,7 @@ func (qb *tagQueryBuilder) queryTag(query string, args []interface{}, tx *sqlx.T
|
|||||||
return &results[0], nil
|
return &results[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *tagQueryBuilder) queryTags(query string, args []interface{}, tx *sqlx.Tx) ([]Tag, error) {
|
func (qb *TagQueryBuilder) queryTags(query string, args []interface{}, tx *sqlx.Tx) ([]Tag, error) {
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
var err error
|
var err error
|
||||||
if tx != nil {
|
if tx != nil {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
30
revive.toml
Normal file
30
revive.toml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
ignoreGeneratedHeader = false
|
||||||
|
severity = "error"
|
||||||
|
confidence = 0.8
|
||||||
|
errorCode = 1
|
||||||
|
warningCode = 1
|
||||||
|
|
||||||
|
#[rule.blank-imports]
|
||||||
|
[rule.context-as-argument]
|
||||||
|
[rule.context-keys-type]
|
||||||
|
[rule.dot-imports]
|
||||||
|
[rule.error-return]
|
||||||
|
[rule.error-strings]
|
||||||
|
[rule.error-naming]
|
||||||
|
#[rule.exported]
|
||||||
|
#[rule.if-return]
|
||||||
|
[rule.increment-decrement]
|
||||||
|
#[rule.var-naming]
|
||||||
|
[rule.var-declaration]
|
||||||
|
[rule.package-comments]
|
||||||
|
[rule.range]
|
||||||
|
[rule.receiver-naming]
|
||||||
|
[rule.time-naming]
|
||||||
|
#[rule.unexported-return]
|
||||||
|
#[rule.indent-error-flow]
|
||||||
|
[rule.errorf]
|
||||||
|
#[rule.empty-block]
|
||||||
|
[rule.superfluous-else]
|
||||||
|
#[rule.unused-parameter]
|
||||||
|
[rule.unreachable-code]
|
||||||
|
[rule.redefines-builtin-id]
|
||||||
@@ -151,16 +151,16 @@ func GetPerformer(performerName string) (*models.ScrapedPerformer, error) {
|
|||||||
twitterElement := bioDoc.Find(".twitter a")
|
twitterElement := bioDoc.Find(".twitter a")
|
||||||
twitterHref, _ := twitterElement.Attr("href")
|
twitterHref, _ := twitterElement.Attr("href")
|
||||||
if twitterHref != "" {
|
if twitterHref != "" {
|
||||||
twitterUrl, _ := url.Parse(twitterHref)
|
twitterURL, _ := url.Parse(twitterHref)
|
||||||
twitterHandle := strings.Replace(twitterUrl.Path, "/", "", -1)
|
twitterHandle := strings.Replace(twitterURL.Path, "/", "", -1)
|
||||||
result.Twitter = &twitterHandle
|
result.Twitter = &twitterHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
instaElement := bioDoc.Find(".instagram a")
|
instaElement := bioDoc.Find(".instagram a")
|
||||||
instaHref, _ := instaElement.Attr("href")
|
instaHref, _ := instaElement.Attr("href")
|
||||||
if instaHref != "" {
|
if instaHref != "" {
|
||||||
instaUrl, _ := url.Parse(instaHref)
|
instaURL, _ := url.Parse(instaHref)
|
||||||
instaHandle := strings.Replace(instaUrl.Path, "/", "", -1)
|
instaHandle := strings.Replace(instaURL.Path, "/", "", -1)
|
||||||
result.Instagram = &instaHandle
|
result.Instagram = &instaHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,10 +204,14 @@ func getIndexes(doc *goquery.Document) map[string]int {
|
|||||||
|
|
||||||
func getEthnicity(ethnicity string) string {
|
func getEthnicity(ethnicity string) string {
|
||||||
switch ethnicity {
|
switch ethnicity {
|
||||||
case "Caucasian": return "white"
|
case "Caucasian":
|
||||||
case "Black": return "black"
|
return "white"
|
||||||
case "Latin": return "hispanic"
|
case "Black":
|
||||||
case "Asian": return "asian"
|
return "black"
|
||||||
|
case "Latin":
|
||||||
|
return "hispanic"
|
||||||
|
case "Asian":
|
||||||
|
return "asian"
|
||||||
default:
|
default:
|
||||||
panic("unknown ethnicity")
|
panic("unknown ethnicity")
|
||||||
}
|
}
|
||||||
@@ -217,7 +221,7 @@ func paramValue(params *goquery.Selection, paramIndex int) string {
|
|||||||
i := paramIndex - 1
|
i := paramIndex - 1
|
||||||
if paramIndex == 0 {
|
if paramIndex == 0 {
|
||||||
return ""
|
return ""
|
||||||
} else {
|
}
|
||||||
node := params.Get(i).FirstChild
|
node := params.Get(i).FirstChild
|
||||||
content := trim(node.Data)
|
content := trim(node.Data)
|
||||||
if content != "" {
|
if content != "" {
|
||||||
@@ -226,7 +230,6 @@ func paramValue(params *goquery.Selection, paramIndex int) string {
|
|||||||
node = node.NextSibling
|
node = node.NextSibling
|
||||||
return trim(node.FirstChild.Data)
|
return trim(node.FirstChild.Data)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/20305966/why-does-strip-not-remove-the-leading-whitespace
|
// https://stackoverflow.com/questions/20305966/why-does-strip-not-remove-the-leading-whitespace
|
||||||
func trim(text string) string {
|
func trim(text string) string {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetVTTTime returns a timestamp appropriate for VTT files (hh:mm:ss)
|
||||||
func GetVTTTime(totalSeconds float64) (s string) {
|
func GetVTTTime(totalSeconds float64) (s string) {
|
||||||
totalSecondsString := strconv.FormatFloat(totalSeconds, 'f', -1, 64)
|
totalSecondsString := strconv.FormatFloat(totalSeconds, 'f', -1, 64)
|
||||||
secondsDuration, _ := time.ParseDuration(totalSecondsString + "s")
|
secondsDuration, _ := time.ParseDuration(totalSecondsString + "s")
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sometimes the \ isn't recognized as valid on windows
|
// FixWindowsPath replaces \ with / in the given path because sometimes the \ isn't recognized as valid on windows
|
||||||
func FixWindowsPath(str string) string {
|
func FixWindowsPath(str string) string {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return strings.Replace(str, "\\", "/", -1)
|
return strings.Replace(str, "\\", "/", -1)
|
||||||
} else {
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user