Skip to content

Commit 856ebd6

Browse files
authored
Add studio, tags, scene (#3)
* Add tags * Add studio * Add scenes support * Add integration test * Add gitattributes. Add test targets * Add DB interface and refactor * Add performer image * Replace checksums with fingerprints * Update dependencies * Make performers unique on name/disambiguation * Add first draft of README
1 parent 0f29cf0 commit 856ebd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4387
-499
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go.mod text eol=lf
2+
go.sum text eol=lf

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ generate:
2020
go generate
2121
packr2
2222

23+
.PHONY: test
24+
test:
25+
go test ./...
26+
27+
.PHONY: it
28+
it:
29+
go test -tags=integration ./...
30+
2331
# Runs gofmt -w on the project's source code, modifying any files that do not match its style.
2432
.PHONY: fmt
2533
fmt:

README.md

+97-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,98 @@
11
# stash-box
2-
Stash App's own OpenSource video indexing and Perceptual Hashing MetaData API
2+
3+
[![Discord](https://img.shields.io/discord/559159668438728723.svg?logo=discord)](https://discord.gg/2TsNFKt)
4+
5+
**stash-box is Stash App's own OpenSource video indexing and Perceptual Hashing MetaData API for porn.**
6+
7+
The intent of stash-box is to provide a collaborative, crowd-sourced database of porn metadata, in the same way as [MusicBrainz](https://musicbrainz.org/) does for music. The submission and editing of metadata is expected to follow the same principle as that of the MusicBrainz database. [See here](https://musicbrainz.org/doc/Editing_FAQ) for how MusicBrainz does it.
8+
9+
Currently, stash-box provides a graphql backend API only. There is no built in UI. The graphql playground can be accessed at `host:port/playground`. The graphql interface is at `host:port/graphql`.
10+
11+
# Docker install
12+
13+
TODO
14+
15+
# Bare-metal Install
16+
17+
Stash-box supports macOS, Windows, and Linux.
18+
19+
Releases TODO
20+
21+
## CLI
22+
23+
Stash-box provides some command line options. See what is currently available by running `stashdb --help`.
24+
25+
For example, to run stash locally on port 80 run it like this (OSX / Linux) `stashdb --host 127.0.0.1 --port 80`
26+
27+
## Configuration
28+
29+
Stash-box generates a configuration file in the current working directory when it is first started up. This configuration file is generated with the following defaults:
30+
- running on `0.0.0.0` port `9998`
31+
- sqlite3 database generated in the current working directory named `stashdb-go.sqlite`
32+
- generated read (`read_api_key`) and write (`modify_api_key`) API keys. These can be deleted to disable read/write authentication (all requests will be allowed without API key)
33+
34+
### API keys
35+
36+
These are a very basic authorization method. When set, the `ApiKey` header must be set to the correct value to read/write the data. The write API key allows reading and writing. The read API key allows only reading.
37+
38+
## SSL (HTTPS)
39+
40+
Stash-box supports HTTPS with some additional work. First you must generate a SSL certificate and key combo. Here is an example using openssl:
41+
42+
`openssl req -x509 -newkey rsa:4096 -sha256 -days 7300 -nodes -keyout stashdb.key -out stashdb.crt -extensions san -config <(echo "[req]"; echo distinguished_name=req; echo "[san]"; echo subjectAltName=DNS:stashdb.server,IP:127.0.0.1) -subj /CN=stashdb.server`
43+
44+
This command would need customizing for your environment. [This link](https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl) might be useful.
45+
46+
Once you have a certificate and key file name them `stashdb.crt` and `stashdb.key` and place them in the directory where stash-box is run from. Stash-box detects these and starts up using HTTPS rather than HTTP.
47+
48+
# FAQ
49+
50+
> I have a question not answered here.
51+
52+
Join the [Discord server](https://discord.gg/2TsNFKt).
53+
54+
# Development
55+
56+
## Install
57+
58+
* [Revive](https://github.com/mgechev/revive) - Configurable linter
59+
* Go Install: `go get github.com/mgechev/revive`
60+
* [Packr2](https://github.com/gobuffalo/packr/tree/v2.0.2/v2) - Static asset bundler
61+
* Go Install: `go get github.com/gobuffalo/packr/v2/[email protected]`
62+
* [Binary Download](https://github.com/gobuffalo/packr/releases)
63+
* [Yarn](https://yarnpkg.com/en/docs/install) - Yarn package manager
64+
65+
NOTE: You may need to run the `go get` commands outside the project directory to avoid modifying the projects module file.
66+
67+
## Environment
68+
69+
### macOS
70+
71+
TODO
72+
73+
### Windows
74+
75+
1. Download and install [Go for Windows](https://golang.org/dl/)
76+
2. Download and install [MingW](https://sourceforge.net/projects/mingw-w64/)
77+
3. Search for "advanced system settings" and open the system properties dialog.
78+
1. Click the `Environment Variables` button
79+
2. Add `GO111MODULE=on`
80+
3. Under system variables find the `Path`. Edit and add `C:\Program Files\mingw-w64\*\mingw64\bin` (replace * with the correct path).
81+
82+
## Commands
83+
84+
* `make generate` - Generate Go GraphQL and packr2 files. This should be run if the graphql schema or schema migration files have changed.
85+
* `make build` - Builds the binary
86+
* `make vet` - Run `go vet`
87+
* `make lint` - Run the linter
88+
* `make test` - Runs the unit tests
89+
* `make it` - Runs the unit and integration tests
90+
91+
## Building a release
92+
93+
1. Run `make generate` to create generated files
94+
2. Run `make build` to build the executable for your current platform
95+
96+
## Cross compiling
97+
98+
TODO

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/golang-migrate/migrate/v4 v4.3.1
1010
github.com/gorilla/websocket v1.4.0
1111
github.com/h2non/filetype v1.0.8
12-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
1312
github.com/jmoiron/sqlx v1.2.0
1413
github.com/mattn/go-sqlite3 v1.10.0
1514
github.com/pkg/errors v0.8.1

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ github.com/gobuffalo/packr v1.15.0/go.mod h1:t5gXzEhIviQwVlNx/+3SfS07GS+cZ2hn76W
243243
github.com/gobuffalo/packr v1.15.1/go.mod h1:IeqicJ7jm8182yrVmNbM6PR4g79SjN9tZLH8KduZZwE=
244244
github.com/gobuffalo/packr v1.19.0/go.mod h1:MstrNkfCQhd5o+Ct4IJ0skWlxN8emOq8DsoT1G98VIU=
245245
github.com/gobuffalo/packr v1.20.0/go.mod h1:JDytk1t2gP+my1ig7iI4NcVaXr886+N0ecUga6884zw=
246+
github.com/gobuffalo/packr v1.21.0 h1:p2ujcDJQp2QTiYWcI0ByHbr/gMoCouok6M0vXs/yTYQ=
246247
github.com/gobuffalo/packr v1.21.0/go.mod h1:H00jGfj1qFKxscFJSw8wcL4hpQtPe1PfU2wa6sg/SR0=
247248
github.com/gobuffalo/packr/v2 v2.0.0-rc.8/go.mod h1:y60QCdzwuMwO2R49fdQhsjCPv7tLQFR0ayzxxla9zes=
248249
github.com/gobuffalo/packr/v2 v2.0.0-rc.9/go.mod h1:fQqADRfZpEsgkc7c/K7aMew3n4aF1Kji7+lIZeR98Fc=

gqlgen.yml

+6
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ struct_tag: gqlgen
1616
models:
1717
Performer:
1818
model: github.com/stashapp/stashdb/pkg/models.Performer
19+
Tag:
20+
model: github.com/stashapp/stashdb/pkg/models.Tag
21+
Studio:
22+
model: github.com/stashapp/stashdb/pkg/models.Studio
23+
Scene:
24+
model: github.com/stashapp/stashdb/pkg/models.Scene
1925

graphql/schema/schema.graphql

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ type Query {
2929

3030
#### Scenes ####
3131

32-
# ids and checksums should be unique
33-
"""Find a scene by ID or checksum"""
34-
findScene(id: ID, checksum: String): Scene
32+
# ids should be unique
33+
"""Find a scene by ID"""
34+
findScene(id: ID!): Scene
35+
36+
"""Finds a scene by an algorithm-specific checksum"""
37+
findSceneByFingerprint(fingerprint: FingerprintInput!): [Scene!]!
3538

3639
queryScenes(scene_filter: SceneFilterType, filter: QuerySpec): QueryScenesResultType!
3740

graphql/schema/types/performer.graphql

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ input PerformerCreateInput {
109109
career_end_year: Int
110110
tattoos: [BodyModificationInput!]
111111
piercings: [BodyModificationInput!]
112+
"""Should be base64 encoded"""
113+
image: String
112114
}
113115

114116
input PerformerUpdateInput {
@@ -130,6 +132,8 @@ input PerformerUpdateInput {
130132
career_end_year: Int
131133
tattoos: [BodyModificationInput!]
132134
piercings: [BodyModificationInput!]
135+
"""Should be base64 encoded"""
136+
image: String
133137
}
134138

135139
input PerformerDestroyInput {
@@ -154,6 +158,8 @@ input PerformerEditDetailsInput {
154158
career_end_year: Int
155159
tattoos: [BodyModificationInput!]
156160
piercings: [BodyModificationInput!]
161+
"""Should be base64 encoded"""
162+
image: String
157163
}
158164

159165
input PerformerEditInput {

graphql/schema/types/scene.graphql

+20-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ input PerformerAppearanceInput {
1010
as: String
1111
}
1212

13+
enum FingerprintAlgorithm {
14+
MD5
15+
}
16+
17+
type Fingerprint {
18+
hash: String!
19+
algorithm: FingerprintAlgorithm!
20+
}
21+
22+
input FingerprintInput {
23+
hash: String!
24+
algorithm: FingerprintAlgorithm!
25+
}
26+
1327
type Scene {
1428
id: ID!
1529
title: String
@@ -20,7 +34,7 @@ type Scene {
2034
studio: Studio
2135
tags: [Tag!]!
2236
performers: [PerformerAppearance!]!
23-
checksums: [String!]!
37+
fingerprints: [Fingerprint!]!
2438
}
2539

2640
input SceneCreateInput {
@@ -31,7 +45,7 @@ input SceneCreateInput {
3145
studio_id: ID
3246
performers: [PerformerAppearanceInput!]
3347
tag_ids: [ID!]
34-
checksums: [String!]!
48+
fingerprints: [FingerprintInput!]!
3549
}
3650

3751
input SceneUpdateInput {
@@ -43,6 +57,7 @@ input SceneUpdateInput {
4357
studio_id: ID
4458
performers: [PerformerAppearanceInput!]
4559
tag_ids: [ID!]
60+
fingerprints: [FingerprintInput!]
4661
}
4762

4863
input SceneDestroyInput {
@@ -57,7 +72,7 @@ input SceneEditDetailsInput {
5772
studio_id: ID
5873
performers: [PerformerAppearanceInput!]
5974
tag_ids: [ID!]
60-
checksums: [String!]
75+
fingerprints: [FingerprintInput!]
6176
}
6277

6378
input SceneEditInput {
@@ -82,6 +97,8 @@ type SceneEdit {
8297
removed_performers: [PerformerAppearance!]
8398
added_tags: [Tag!]
8499
removed_tags: [Tag!]
100+
added_fingerprints: [Fingerprint!]
101+
removed_fingerprints: [Fingerprint!]
85102
}
86103

87104
type QueryScenesResultType {

graphql/schema/types/studio.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ input StudioCreateInput {
1515

1616
input StudioUpdateInput {
1717
id: ID!
18-
name: String!
18+
name: String
1919
urls: [URLInput!]
2020
parent_id: ID
2121
child_studio_ids: [ID!]

pkg/api/context_keys.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package api
2+
3+
// https://stackoverflow.com/questions/40891345/fix-should-not-use-basic-type-string-as-key-in-context-withvalue-golint
4+
5+
type key int
6+
7+
const (
8+
performerKey key = 1
9+
sceneKey key = 2
10+
studioKey key = 3
11+
)

0 commit comments

Comments
 (0)