Compare commits

...

192 Commits

Author SHA1 Message Date
WithoutPants
9f335b8ea2 Add 0.2.1 changelog (#607) 2020-06-10 10:53:49 +10:00
WithoutPants
d168df1ad6 Fix max loop duration not working (#604) 2020-06-10 10:15:02 +10:00
peolic
ef8cba804f Fix sanitizeURL (#599) 2020-06-10 10:13:57 +10:00
WithoutPants
bd5ee9ba6b Merge pull request #597 from stashapp/develop
Merge 0.2 to master
2020-06-06 14:59:07 +10:00
WithoutPants
caef648659 Update changelog for 0.2 release (#582) 2020-06-06 14:38:19 +10:00
bnkai
f255104951 Upgrade bmatcuk/doublestar to 1.3.1 (#586) 2020-06-03 11:46:12 +10:00
InfiniteTF
dcf7233e38 Add polyfill for number unit formatting (#589) 2020-06-02 10:19:27 +10:00
bnkai
b89956de25 freeones scraper fixes/tweaking (#584) 2020-06-02 09:45:37 +10:00
InfiniteTF
d1e6858c11 Remove German language option (#590) 2020-06-02 09:37:13 +10:00
bnkai
dc5efb9e31 Unit testing for performers,studios,movies FindByName/s (#581) 2020-05-27 10:48:45 +10:00
WithoutPants
1110e9c311 Fix date rendering for missing date values (#580)
* Fix date rendering when missing date value
* Move scene studio overlay within scene card
2020-05-27 09:34:46 +10:00
InfiniteTF
4ec6d62e01 Selectable wall preview type (#510)
* Add optional image preview generation
* Add setting for video preview encoding preset
2020-05-27 09:33:49 +10:00
InfiniteTF
197918d13c Localize dates and numbers (#574) 2020-05-25 15:49:13 +10:00
bnkai
ccd75731b7 Change scrape matching (studio, movies, tag, performers) to case insensitive (#556)
* Change scrape matching (studio, movies, tag, performers) to case insensitive
* * fix collate order
* * make filename parser findbyname calls case insensitive
* * add unit testing for Tags GetFindbyName/s
2020-05-24 16:19:22 +10:00
InfiniteTF
32fce9ac6f Speed up tag count queries (#570)
* Speed up tag count queries
* Add test for marker CountByTagID

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2020-05-24 16:18:02 +10:00
WithoutPants
95a6d3ea2f Fix sceneTags filter selection (#564) 2020-05-20 22:47:16 +10:00
WithoutPants
1a31ca3e33 Set performers/tags/studios in parser (#563) 2020-05-20 22:47:01 +10:00
InfiniteTF
5c68c70216 Encode pasted images to jpegs (#560) 2020-05-20 22:46:38 +10:00
WithoutPants
ec420df871 Add debug logging for xpath scraping (#555)
* Add debug logging for xpath scraping
* Add logging for processing scene members
2020-05-20 22:46:00 +10:00
WithoutPants
ad374dc7f5 Include stash version in bug report template 2020-05-20 14:41:02 +10:00
WithoutPants
05488d59c3 Find scrapers in subdirectories (#554) 2020-05-19 08:44:33 +10:00
InfiniteTF
5450fe8e9a Changelog (#531) 2020-05-19 08:37:56 +10:00
bnkai
0fc57ce1e0 Fix xpath comments text (#550) 2020-05-18 12:26:20 +10:00
WithoutPants
46746e6848 Fix redirect loops in login, migrate and setup pages (#549)
* Fix redirect loop when setup and migrate required
* Fix redirect loop between setup and login
2020-05-18 08:55:01 +10:00
WithoutPants
215c4e3bde Change builtin freeones scraper to community yml (#542) 2020-05-15 20:10:20 +10:00
WithoutPants
50530ae85d Fix setting release notes for development build 2020-05-15 16:52:03 +10:00
WithoutPants
7fd9428cbb Fix stash directory with spaces (#541) 2020-05-15 09:12:17 +10:00
WithoutPants
93d6cc43c5 Add details to is missing filter (#533) 2020-05-15 09:11:28 +10:00
bnkai
d74a303c00 Fix 0 undefined library size on empty db (#535) 2020-05-14 10:44:13 +10:00
WithoutPants
fde02425ab Make auto tagger matching more flexible (#534) 2020-05-13 17:32:39 +10:00
WithoutPants
41c6d9e681 Revert preview generation change 2020-05-13 17:23:23 +10:00
bnkai
4829b4b214 Fix edge case preview generation, tweak preview generation preset (#528) 2020-05-11 17:24:52 +10:00
bnkai
bd45daacf3 Add a cache for gallery thumbnails (#496) 2020-05-11 17:20:08 +10:00
InfiniteTF
8ba76783b0 Query optimizations (#478)
* Remove slow and largely pointless groupbys
* Change scene.query to use querybuilder
2020-05-11 15:19:11 +10:00
InfiniteTF
328db57d6c Overhaul look and feel of folder select (#527) 2020-05-09 13:08:00 +10:00
InfiniteTF
e9c68897d7 Add is-missing tags filter (#526) 2020-05-09 12:21:08 +10:00
InfiniteTF
0d9dcdd1e9 Add title to flags, and alias for Slovakia (#519) 2020-05-09 10:38:11 +10:00
InfiniteTF
df2d2c2d09 Upgrade javascript libraries (#516)
* Bump react-bootstrap
* Bump library versions and clean up hooks
* Bump intl libraries
* Fix image pasting
2020-05-08 12:06:07 +10:00
WithoutPants
99f88b8d73 Querybuilder integration tests (#513)
* Vet fixes
* Change low resolution to < 480
2020-05-04 17:02:49 +10:00
bnkai
0b50e83dbf freeones scraper tweaks (#509) 2020-05-04 14:11:49 +10:00
InfiniteTF
a4edd21072 Add flags for performer countries (#508) 2020-05-03 18:15:24 +10:00
InfiniteTF
2c85aeedf4 Set movies studioId on create mutation (#511) 2020-05-03 08:54:02 +10:00
bnkai
0e01177440 Merge pull request #515 from stashapp/revert-514-travis_body
Revert "travis fix"
2020-05-03 00:23:04 +03:00
bnkai
db716d2e17 Revert "travis fix" 2020-05-03 00:22:11 +03:00
bnkai
5370870598 Merge pull request #514 from bnkai/travis_body
Travis release date fix
2020-05-03 00:03:00 +03:00
bnkai
461127c8c4 travis fix 2020-05-02 23:28:35 +03:00
WithoutPants
2166caf322 Update xpath dependency (#507) 2020-04-30 08:32:33 +10:00
WithoutPants
3d22d5a742 Refactor build (#493)
* Add lint/format checks to build
* Make travis get full repo to get tags
* Run packr2 once in cross-compile
* Fix quotes in package.json
* Fix linting issues
* Formatting
* Fix vet issue
* Fix go lint issues
* Show start of each platform compilation
* Add validate target
* Set gitattributes for go fmt and mod vendor
* Fix tag name
* Add fmt-ui target
2020-04-29 12:13:08 +10:00
InfiniteTF
a0306bfbd2 Remove hotkeys and fix tag selection (#505)
* Remove broken scene player hotkeys
* Disable closing tag select menu after a select
2020-04-29 09:55:34 +10:00
bnkai
52a1059380 Make image extension check in zip files case insensitive (#501) 2020-04-29 09:24:01 +10:00
FleetingOrchard
1513617f95 Add index/total count to end of pagination buttons (#490) 2020-04-29 08:28:57 +10:00
bnkai
f933a28e5a Fix yarn extract error due to "library size" (#494) 2020-04-26 16:49:55 +10:00
WithoutPants
309f7047b0 Add parser support for 3-letter month (#500) 2020-04-26 16:29:53 +10:00
bnkai
5e84c0922d Add random male performer image (#491)
* Add random male performer image during performer creation if gender is male
2020-04-25 09:54:42 +10:00
WithoutPants
5923917e6c Clean missing galleries (#489)
* Clean missing galleries
* Refactor matchFile
2020-04-25 09:32:55 +10:00
FleetingOrchard
8a4d853a5d Add "reshuffle button" when sortby is random (#497) 2020-04-24 14:30:41 +10:00
bnkai
29336d1ee0 Move image with cover.jpg in name to first place in Galleries (#477) 2020-04-24 12:53:18 +10:00
bnkai
9b1518beae Export performance optimization (#475)
* recreate metadata path if needed, before exporting data
2020-04-24 12:52:21 +10:00
WithoutPants
ba09bfa64a Include scene o-counter in import/export (#488)
* Include o-counter in import/export
* Fix scene card o-counter display
2020-04-23 09:14:58 +10:00
WithoutPants
eee7adfb85 Add Studio to movie and fix movie schema (#458)
* Add movie migration
* Update server and UI code for type changes
* Add studio to movies
* Movie blobs to end
* Document movie duration
* Add filtering on movie studio
2020-04-22 11:22:14 +10:00
InfiniteTF
f21e04dcbc Fix navbar height (#481) 2020-04-21 09:30:15 +10:00
WithoutPants
7e747fd8a9 Restore movie/studio data on edit cancel (#476) 2020-04-20 12:46:55 +10:00
WithoutPants
359e80f364 Don't error in IsStreamable resolver (#482) 2020-04-20 12:42:56 +10:00
InfiniteTF
2a3c9742cc Add slim endpoints for entities to speed up filters (#460)
* Move performers image column to end of table
* Remove redundant index
2020-04-19 12:03:51 +10:00
f1delio
7ef0000744 Update README.md (#474)
Added Customization section with links toward Custom CSS snippets, CSS Tweaks, and Plex Theme.
2020-04-18 09:47:40 +10:00
bnkai
e2f66a3492 Fix editing movie name (#470) 2020-04-15 08:36:16 +10:00
InfiniteTF
7cd682e59c Fix log population (#459) 2020-04-13 11:49:23 +10:00
InfiniteTF
a5a264dcc2 Fix tag creation (#461) 2020-04-13 11:45:45 +10:00
bnkai
424e62a226 Fix studio edit name (#465) 2020-04-13 11:42:02 +10:00
WithoutPants
849a5261a3 Include gender in performer scraper results (#448)
* Fix scraper gender
* Set scraped gender in the UI
* Match gender on enum or case insensitive string
2020-04-11 13:26:53 +10:00
WithoutPants
6764c1f545 Performer and Movie UI fixes and improvements (#447)
* Improve gender display
* Sanitise performer URLs
* Refactor editable text into separate module
* Make movie duration DurationInput
* Fix clearing sometimes not firing onChange
* Set movie duration as string
* Fix TextUtil.fileSize
* Improve scene URL
2020-04-11 13:23:31 +10:00
WithoutPants
aef31c8b50 Don't redirect login to migrate page (#453) 2020-04-10 08:41:09 +10:00
WithoutPants
2ab45848a5 Prefer modified performer image over scraped one (#449) 2020-04-10 08:40:45 +10:00
WithoutPants
91d842ed47 Delete marker preview on marker change or delete (#446) 2020-04-10 08:39:41 +10:00
bnkai
d5617307f1 Add detection of container/video_codec/audio_codec compatibility for live file streaming or transcoding (#384)
* add forceMKV, forceHEVC config options
* drop audio stream instead of trying to transcode for ffmpeg unsupported/unknown audio codecs
2020-04-10 08:38:34 +10:00
Anon247
dc37a3045b Added various missing filters to performer page (#438) 2020-04-08 14:21:05 +10:00
WithoutPants
15e7756d33 Replace basic auth with cookie authentication (#440)
* Add logout functionality and button
* Make session age configurable
2020-04-08 12:51:12 +10:00
WithoutPants
b3e8d1e8dd Add scene rating to scene filename parser (#432)
* Fix scene parser display issues in 2.5
* Dropdown menu presentation improvements
* Fix refresh on parser apply
* Ignore line endings on scss files
2020-04-05 07:59:57 +10:00
bnkai
18dc5e85fa Don't run travis for the latest_develop tag (#439) 2020-04-04 09:27:49 +11:00
bnkai
8a6fff61ae Enable sorting for galleries (#437) 2020-04-03 14:40:37 +11:00
bnkai
e58c311ddd Add library size to main stats page (#427) 2020-04-03 13:44:17 +11:00
InfiniteTF
66cb7f4928 Update prettier to v2.0.1 and enable for SCSS (#420) 2020-04-03 10:29:33 +11:00
Anon247
ad7bfb8dbf Fix to filter on movies from performer filter to movie filter (#435) 2020-04-03 10:28:15 +11:00
InfiniteTF
0f622c84f4 Add SVG studio image support, and studio image caching (#418)
* Support SVGs for studio images and add ETAGs
* Add SVG to studio image input
* Update content sniffing
2020-04-03 09:11:48 +11:00
InfiniteTF
aee9df966b Cut over to v2.5 UI (#433)
* Cut over to v2.5 UI
* Use node 12 in travis
* Remove unnecessary `nvm use`
* Update docker file
2020-04-03 08:46:23 +11:00
ueaslsef
10b6d4b579 [Feature] Add image count to gallery list (#429)
* Add imagecount to gallery list
* Port to 2.5
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2020-04-02 08:27:33 +11:00
WithoutPants
82201e23e0 Make ethnicity freetext and fix freeones ethnicity panic (#431)
* Make ethnicity free text

* Fix panic in freeones scraper for other ethnicity
2020-04-02 08:25:39 +11:00
Anon247
0bbb2bd1d0 Fix to allow scene to be removed when attached to a movie (#421) 2020-04-01 12:07:43 +11:00
InfiniteTF
2a8e5d5b9b UI fixes (#419) 2020-04-01 11:08:01 +11:00
dependabot[bot]
777cd96759 Bump acorn from 5.7.3 to 5.7.4 in /ui/v2 (#399)
Bumps [acorn](https://github.com/acornjs/acorn) from 5.7.3 to 5.7.4.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/5.7.3...5.7.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-01 09:57:38 +11:00
hiddenpants255
494b794228 Add gender support for performer (#371)
Co-authored-by: HiddenPants255 <>
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2020-04-01 09:36:38 +11:00
WithoutPants
d886012d74 Add modes for performer/tag for bulk scene editing (#412) 2020-03-23 08:16:11 +11:00
bnkai
acb7260824 Backup database if a migration is needed (#415)
* Confirm before migrating database

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2020-03-23 08:07:15 +11:00
WithoutPants
abf2b49803 Configurable scraper user agent string (#409)
* Add debug scrape option.

Co-authored-by: HiddenPants255 <>
2020-03-21 08:55:15 +11:00
WithoutPants
ff495361d9 Port Movies UI to v2.5 (#397)
* Ignore generated-graphql.tsx in 2.5
* Make movie name mandatory
* Port #395 fix to v2.5
* Differentiate front/back image browse buttons
* Move URL, Synopsis to separate rows
* Fix unknown query params crashing UI
2020-03-21 08:21:49 +11:00
WithoutPants
5aa6dec8dc Fix random sort not changing seed (#411) 2020-03-21 08:07:46 +11:00
bnkai
9dacad70a1 Autoassociate galleries to scenes when scanning (#405) 2020-03-19 12:36:00 +11:00
WithoutPants
1a6374fae9 Fix error when viewing scenes related to objects with illegal characters in name (#395)
* Fix gitattributes for v2.5
2020-03-14 08:06:55 +11:00
WithoutPants
6f5f3112e1 Fix marker time setting in v2.5 UI (#396) 2020-03-13 19:58:13 +11:00
WithoutPants
3de6955a9e Generate cover image (#376)
* Make mutating metadata ops mutation
* Implement scene generate screenshot
* Remove fetch policy on metadata mutations
* Port UI changes to v2.5
* Set generated image in database
2020-03-12 08:34:04 +11:00
WithoutPants
34d829338d Add image scraping support (#370)
* Add sub-scraper functionality
* Add scraping of performer image
* Add scene cover image scraping
* Port UI changes to v2.5
* Fix v2.5 dialog suggest color
* Don't convert eol of UI to support pretty
2020-03-11 11:41:55 +11:00
caustico
5fb8bbf768 Movies Section (#338)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2020-03-10 14:28:15 +11:00
InfiniteTF
b3fab3cfef Make mobile menu behavior more consistent, and stats styles responsive (#391) 2020-03-08 12:55:42 +11:00
WithoutPants
cb594f0e43 Fix various issues with v2.5 UI (#390)
* Fix navbar collapse breakpoint
* Fix list filter colors and height
* Make styling similar to v2
* Fix scene card zoom and orientation
* Keep p tag even without details
* Fix custom css
* Default settings tab to tasks
* Fix flickering progress bar. Fix percentage.
* Fix unsetting studio
* Fix scene gallery select
* Don't hide edit on small devices
* Fix log dropdown style
* Use monospace for custom css input
2020-03-06 20:02:02 +11:00
WithoutPants
088ddc9df4 Add new v2.5 UI (#357) 2020-03-05 10:15:02 +11:00
Infinite
c875515730 Fix localForage infinite loop, set base font-size to 14px, and tweak
styles
2020-03-04 09:21:30 +01:00
InfiniteTF
c8a56aea40 Update browser cache when images are updated (#389) 2020-03-03 10:33:41 +11:00
InfiniteTF
41f7a46ac1 Fix performer height filter error (#388)
* Fix performer height filter error
* Make all performer columns qualified

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2020-03-03 10:30:29 +11:00
InfiniteTF
80a8d2de97 Use parameter binding for all queries (#387) 2020-03-03 09:18:14 +11:00
Infinite
2fac50ba3e Formatting and list hook fix 2020-03-01 21:30:40 +01:00
Infinite
85936edb9c Fix list filter default values and error state 2020-03-01 21:04:38 +01:00
Infinite
429df84479 Update stats page #366 2020-03-01 21:04:38 +01:00
Infinite
93c7ad7559 Make performer image position top #358 2020-03-01 21:04:38 +01:00
Infinite
5b6a3a7732 Fix scene edit page for smaller screens 2020-03-01 21:04:38 +01:00
Infinite
dba4b350a0 Fix scene list view 2020-03-01 21:04:38 +01:00
Infinite
ac4f4972b6 Correct scene card truncation 2020-03-01 21:04:38 +01:00
Infinite
8672c4437e Navbar key 2020-03-01 21:04:38 +01:00
Infinite
6d71663f99 Fix whitespace 2020-03-01 21:04:37 +01:00
Infinite
195158db8b Fix performer scrape menu layout 2020-03-01 21:04:37 +01:00
Infinite
857b2cc78d Lint + prettier 2020-03-01 21:04:37 +01:00
Infinite
960d5c7000 Switch to hamburger menu for phones 2020-03-01 21:04:37 +01:00
Infinite
49354d571b Small fixes 2020-03-01 21:04:37 +01:00
Infinite
6f07380628 Fix list hook state 2020-03-01 21:04:37 +01:00
Infinite
151d69632e Refactor list hook filter storag 2020-03-01 21:04:37 +01:00
Infinite
6df25a2c5e Fix toast styles 2020-03-01 21:04:37 +01:00
Infinite
750759e4bf Prettier 2020-03-01 21:04:37 +01:00
Infinite
8fe6eb0d77 Update jwplayer 2020-03-01 21:04:37 +01:00
Infinite
cdadb66d85 Remove or exempt all uses of 'any
* Refactored LocalForage
* Refactored SceneFilenameParser
2020-03-01 21:04:37 +01:00
Infinite
a60c89ceb1 Fix localForage initialization when stored config is undefined 2020-03-01 21:04:37 +01:00
Infinite
a43cae43c0 Prettier 2020-03-01 21:04:37 +01:00
Infinite
a7df23c54d Fix 2020-03-01 21:04:37 +01:00
Infinite
3a0420b79e Change i18n to just use single language setting 2020-03-01 21:04:37 +01:00
Infinite
e6d9d385a7 Add O-counter (#334) 2020-03-01 21:04:37 +01:00
Infinite
f23247d9c8 Delete swp 2020-03-01 21:04:37 +01:00
Infinite
a5036ebe5f Prevent flashing when filter is updated 2020-03-01 21:04:37 +01:00
Infinite
4e5c65f90d Maintain filter parameters in session (#326) 2020-03-01 21:04:37 +01:00
Infinite
690596aa34 Refactor list filter query functionality 2020-03-01 21:04:37 +01:00
Infinite
0fdde7726b i18n 2020-03-01 21:04:37 +01:00
Infinite
fb5a49e58c Add Xpath post processing and performer name query (#333) 2020-03-01 21:04:36 +01:00
Infinite
3bbcc65521 Accept random seed from UI for random sorting (#328) 2020-03-01 21:04:36 +01:00
Infinite
79f69b4d61 Allow path separator in scene filename parser pattern (#327) 2020-03-01 21:04:36 +01:00
Infinite
c33639d824 Rename component folders, and prune styles 2020-03-01 21:04:36 +01:00
Infinite
fd560c2147 Switch back to CRA 2020-03-01 21:04:36 +01:00
Infinite
49a6076500 Style changes 2020-03-01 21:04:36 +01:00
Infinite
4a32f90382 Styles 2020-03-01 21:04:36 +01:00
Infinite
c1ce6d539d Prettier 2020-03-01 21:04:35 +01:00
Infinite
3f9f32c356 Responsive styles for portrait orientation phones 2020-03-01 21:04:35 +01:00
Infinite
1ccf8d1586 Changes 2020-03-01 21:04:35 +01:00
Infinite
247ad0a470 Style fixes 2020-03-01 21:04:35 +01:00
Infinite
ac3d03715f Styling 2020-03-01 21:04:35 +01:00
Infinite
3fa3f61d93 Styling 2020-03-01 21:04:35 +01:00
Infinite
c2544fee98 Prettier 2020-03-01 21:04:35 +01:00
Infinite
e1a1914d16 Fixes 2020-03-01 21:04:35 +01:00
Infinite
d1ffc0be0a Optimization 2020-03-01 21:04:35 +01:00
Infinite
1928f09dcf Eject create-react-app 2020-03-01 21:04:35 +01:00
Infinite
95bedc77fe Styling 2020-03-01 21:04:34 +01:00
Infinite
71251ee6a8 Add useful links to about page (#322) 2020-03-01 21:04:34 +01:00
Infinite
498491e82d Fix react warnings (#317) 2020-03-01 21:04:34 +01:00
Infinite
71dd939806 Add scene duration filter (#313) 2020-03-01 21:04:34 +01:00
Infinite
dda36f6b09 Add check version functionality (#296) 2020-03-01 21:04:34 +01:00
Infinite
63cc97d199 Add scenes tab to performer page (#280) 2020-03-01 21:04:33 +01:00
Infinite
dcfd445040 Library updates 2020-03-01 21:04:33 +01:00
Infinite
111d5dd7c5 Fixes 2020-03-01 21:04:33 +01:00
Infinite
244c8ff234 Prettier 2020-03-01 21:04:32 +01:00
Infinite
9827647122 Linting update 2020-03-01 21:04:32 +01:00
Infinite
c83e0898f9 Linting config 2020-03-01 21:04:32 +01:00
Infinite
c31205c47f Linting 2020-03-01 21:04:31 +01:00
Infinite
0cb61d14be Remove final react-router props 2020-03-01 21:04:31 +01:00
Infinite
0e717d6aae Fixes 2020-03-01 21:04:31 +01:00
Infinite
129dcecdef Blueprint removed 2020-03-01 21:04:31 +01:00
Infinite
e18e67b512 Toast 2020-03-01 21:04:31 +01:00
Infinite
cb1fa323e4 Changes 2020-03-01 21:04:30 +01:00
Infinite
f50cb45ca5 Changes 2020-03-01 21:04:30 +01:00
Infinite
4d44deff64 WIP 2020-03-01 21:04:30 +01:00
Infinite
716c33fc8e Use parameter binding for all queries 2020-02-29 16:18:59 +01:00
WithoutPants
97ab40595e Merge master back to develop 2020-02-25 12:43:42 +11:00
bnkai
6578cfb843 Fix version check for v0.1.0+ (#382)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2020-02-25 11:59:08 +11:00
WithoutPants
acc8a126d0 Fix travis tagged build (#379)
* Fix tagged master build on travis
* Remove branches section
2020-02-24 17:05:08 +11:00
WithoutPants
71ca30e8f4 Merge pull request #378 from stashapp/develop
Merge develop to master for 0.1 release
2020-02-24 15:52:45 +11:00
WithoutPants
691a8c23c0 Dockerfiles for production, develop and build (#364)
* Separate develop and production dockerfiles
* Add build docker file
* Fix curl http2 framing error
* updated MAINTAINER
* Add README for build dockerfile
* Remove stash user from docker files

Co-authored-by: Leopere <1068374+Leopere@users.noreply.github.com>
2020-02-24 11:40:56 +11:00
WithoutPants
8d57629af3 Fix scene selection not working (#373) 2020-02-19 07:56:46 +11:00
WithoutPants
bf49a23df8 Fix panic when version check times out (#374) 2020-02-19 07:56:24 +11:00
twotobinary
776727140f fix(middleware): set baseURL to external host if provided (#369) 2020-02-17 14:01:02 +11:00
WithoutPants
df3d3d24f5 Update stats page (#366)
* Remove notes. Make stats like old version
* Make font size responsive
2020-02-14 08:15:05 +11:00
Leopere
aa8bfaf407 [Feature] Adding Feature.md/BugFix.md Pull Request Template. (#343)
* Adding Feature.md Pull Request Template.

* Create BugFix.md Pull Request Tempalte

* Create CONTRIBUTING.md

* Disabled Librepay since we've decided properly on OpenCollective
2020-02-12 21:07:51 -05:00
bnkai
df890dca79 Fix database locked on image cover too big bug (#359) (#360) 2020-02-13 11:57:17 +11:00
WithoutPants
ae5aa6a6ec Change performer position to top (#358) 2020-02-11 08:29:06 +11:00
WithoutPants
c99ba68181 Fix URL update not reflected in list hook (#350)
* Fix URL update not reflected in list hook

* Maintain query prefs on tag click
2020-02-08 14:54:41 +11:00
WithoutPants
1d9913d268 Revert "Make performer image contain (#355)"
This reverts commit 40de2caa95.
2020-02-08 14:46:37 +11:00
WithoutPants
40de2caa95 Make performer image contain (#355) 2020-02-07 21:42:22 -05:00
WithoutPants
254d6978d0 Fix branch condition in travis 2020-02-07 06:57:44 +11:00
WithoutPants
3c1eeb3d47 Prepare for 0.1.0 release (#345)
* Tag develop builds as latest. Version in makefile
* Rename latest to latest_develop
* Update GetLatestVersion
* Separate master and develop releases
* Add release date back into development version
* Remove unused code
* Two minute limit per file to upload to transfer.sh
2020-02-07 06:39:08 +11:00
885 changed files with 107504 additions and 105850 deletions

6
.gitattributes vendored
View File

@@ -1,2 +1,6 @@
go.mod text eol=lf
go.sum text eol=lf
go.sum text eol=lf
*.go text eol=lf
vendor/** -text
ui/v2.5/**/*.ts* text eol=lf
ui/v2.5/**/*.scss text eol=lf

2
.github/FUNDING.yml vendored
View File

@@ -6,7 +6,7 @@ open_collective: stashapp
# ko_fi: # Replace with a single Ko-fi username
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: StashApp
# liberapay: StashApp
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@@ -23,6 +23,8 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem please ensure that your screenshots are SFW or at least appropriately censored.
**Stash Version: (from Settings -> About):**
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]

18
.github/PULL_REQUEST_TEMPLATE/BugFix.md vendored Normal file
View File

@@ -0,0 +1,18 @@
---
name: Bug Fix
about: Add a bug fix this project!
title: "[Bug Fix] Short Form Title (50 chars or less.)"
labels: bug
assignees: 'WithoutPants, bnkai, Leopere'
---
<!-- Please make sure to read https://github.com/stashapp/stash/docs/CONTRIBUTING.md and check that you understand and have followed it as best as possible -->
<!-- Explain what your bugfix seeks to remedy in a short paragraph. -->
# Scope
<!-- Declare any issues by typing `fixes #1` or `closes #1` for example so that the automation can kick in when this is merged -->
## Closes/Fixes Issues
<!-- What have you tested specifically and what possible impacts/areas there are that may need retesting by others. -->
## Other testing QA Notes

View File

@@ -0,0 +1,17 @@
---
name: Feature Addition
about: Add a feature to this project!
title: "[Feature] Short Form Title (50 chars or less.)"
labels: enhancement
assignees: 'WithoutPants, bnkai, Leopere'
---
<!-- Please make sure to read https://github.com/stashapp/stash/docs/CONTRIBUTING.md and check that you understand and have followed it as best as possible
Explain what your feature does in a short paragraph. -->
# Scope
<!-- Declare any issues by typing `fixes #1` or `closes #1` for example so that the automation can kick in when this is merged -->
## Closes/Fixes Issues
<!-- What have you tested specifically and what possible impacts/areas there are that may need retesting by others. -->
## Other testing QA Notes

1
.gitignore vendored
View File

@@ -21,6 +21,7 @@
# GraphQL generated output
pkg/models/generated_*.go
ui/v2/src/core/generated-*.tsx
ui/v2.5/src/core/generated-*.tsx
# packr generated files
*-packr.go

7
.idea/go.iml generated
View File

@@ -4,11 +4,10 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/certs" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/ui/v1/dist" />
<excludeFolder url="file://$MODULE_DIR$/ui/v2/build" />
<excludeFolder url="file://$MODULE_DIR$/ui/v2/node_modules" />
<excludeFolder url="file://$MODULE_DIR$/ui/v2.5/build" />
<excludeFolder url="file://$MODULE_DIR$/ui/v2.5/node_modules" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
</module>

View File

@@ -1,4 +1,8 @@
if: tag != latest_develop # dont build for the latest_develop tagged version
dist: xenial
git:
depth: false
language: go
go:
- 1.11.x
@@ -9,42 +13,64 @@ env:
- GO111MODULE=on
before_install:
- echo -e "machine github.com\n login $CI_USER_TOKEN" > ~/.netrc
- travis_retry yarn --cwd ui/v2 install --frozen-lockfile
- nvm install 12
- travis_retry yarn --cwd ui/v2.5 install --frozen-lockfile
- make generate
- CI=false yarn --cwd ui/v2 build # TODO: Fix warnings
- CI=false yarn --cwd ui/v2.5 build-ci
#- go get -v github.com/mgechev/revive
script:
# left lint off to avoid getting extra dependency
#- make lint
#- make vet
- make it
- make fmt-check vet it
after_success:
- if [ "$TRAVIS_BRANCH" = "develop" ]; then export TAG_SUFFIX="_dev"; elif [ "$TRAVIS_BRANCH" != "master" ]; then export TAG_SUFFIX="_$TRAVIS_BRANCH"; fi
- export STASH_VERSION="v0.0.0-alpha${TAG_SUFFIX}"
- docker pull stashapp/compiler:develop
- sh ./scripts/cross-compile.sh ${STASH_VERSION}
- sh ./scripts/cross-compile.sh
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sh ./scripts/upload-pull-request.sh; fi'
before_deploy:
- if [ "$TRAVIS_BRANCH" = "develop" ]; then export TAG_SUFFIX="_dev"; fi
- git tag -f ${STASH_VERSION}
- git push -f --tags
# push the latest tag when on the develop branch
- if [ "$TRAVIS_BRANCH" = "develop" ]; then git tag -f latest_develop; git push -f --tags; fi
- export RELEASE_DATE=$(date +'%Y-%m-%d %H:%M:%S %Z')
- export STASH_VERSION=$(git describe --tags --exclude latest_develop)
# set TRAVIS_TAG explcitly to the version so that it doesn't pick up latest_develop
- if [ "$TRAVIS_BRANCH" = "master"]; then export TRAVIS_TAG=${STASH_VERSION}; fi
deploy:
provider: releases
api_key:
secure: tGJ2q62CfPdayid2qEtW2aGRhMgCl3lBXYYQqp3eH0vFgIIf6cs7IDX7YC/x3XKMEQ/iMLZmtCXZvSTqNrD6Sk7MSnt30GIs+4uxIZDnnd8mV5X3K4n4gjD+NAORc4DrQBvUGrYMKJsR5gtkH0nu6diWb1o1If7OiJEuCPRhrmQYcza7NUdABnA9Z2wn2RNUV9Ga33WUCqLMEU5GtNBlfQPiP/khCQrqn/ocR6wUjYut3J6YagzqH4wsfJi3glHyWtowcNIw1LZi5zFxHD/bRBT4Tln7yypkjWNq9eQILA6i6kRUGf7ggyTx26/k8n4tnu+QD0vVh4EcjlThpU/LGyUXzKrrxjRwaDZnM0oYxg5AfHcBuAiAdo0eWnV3lEWRfTJMIVb9MPf4qDmzR4RREfB5OXOxwq3ODeCcJE8sTIMD/wBPZrlqS/QrRpND2gn2X4snkVukN9t9F4CMTFMtVSzFV7TDJW5E5Lq6VEExulteQhs6kcK9NRPNAaLgRQAw7X9kVWfDtiGUP+fE2i8F9Bo8bm7sOT5O5VPMPykx3EgeNg1IqIgMTCsMlhMJT4xBJoQUgmd2wWyf3Ryw+P+sFgdb5Sd7+lFgJBjMUUoOxMxAOiEgdFvCXcr+/Udyz2RdtetU1/6VzXzLPcKOw0wubZeBkISqu7o9gpfdMP9Eq00=
file:
- dist/stash-osx
- dist/stash-win.exe
- dist/stash-linux
- dist/stash-pi
skip_cleanup: true
overwrite: true
body: ${RELEASE_DATE}
on:
repo: stashapp/stash
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(master|develop)$
branches:
only:
- master
- develop
# latest develop release
- provider: releases
# use the v2 release provider for proper release note setting
edge: true
api_key:
secure: tGJ2q62CfPdayid2qEtW2aGRhMgCl3lBXYYQqp3eH0vFgIIf6cs7IDX7YC/x3XKMEQ/iMLZmtCXZvSTqNrD6Sk7MSnt30GIs+4uxIZDnnd8mV5X3K4n4gjD+NAORc4DrQBvUGrYMKJsR5gtkH0nu6diWb1o1If7OiJEuCPRhrmQYcza7NUdABnA9Z2wn2RNUV9Ga33WUCqLMEU5GtNBlfQPiP/khCQrqn/ocR6wUjYut3J6YagzqH4wsfJi3glHyWtowcNIw1LZi5zFxHD/bRBT4Tln7yypkjWNq9eQILA6i6kRUGf7ggyTx26/k8n4tnu+QD0vVh4EcjlThpU/LGyUXzKrrxjRwaDZnM0oYxg5AfHcBuAiAdo0eWnV3lEWRfTJMIVb9MPf4qDmzR4RREfB5OXOxwq3ODeCcJE8sTIMD/wBPZrlqS/QrRpND2gn2X4snkVukN9t9F4CMTFMtVSzFV7TDJW5E5Lq6VEExulteQhs6kcK9NRPNAaLgRQAw7X9kVWfDtiGUP+fE2i8F9Bo8bm7sOT5O5VPMPykx3EgeNg1IqIgMTCsMlhMJT4xBJoQUgmd2wWyf3Ryw+P+sFgdb5Sd7+lFgJBjMUUoOxMxAOiEgdFvCXcr+/Udyz2RdtetU1/6VzXzLPcKOw0wubZeBkISqu7o9gpfdMP9Eq00=
file:
- dist/stash-osx
- dist/stash-win.exe
- dist/stash-linux
- dist/stash-pi
skip_cleanup: true
overwrite: true
name: "${STASH_VERSION}: Latest development build"
release_notes: "**${RELEASE_DATE}**\n This is always the latest committed version on the develop branch. Use as your own risk!"
prerelease: true
on:
repo: stashapp/stash
branch: develop
# official master release - only build when tagged
- provider: releases
api_key:
secure: tGJ2q62CfPdayid2qEtW2aGRhMgCl3lBXYYQqp3eH0vFgIIf6cs7IDX7YC/x3XKMEQ/iMLZmtCXZvSTqNrD6Sk7MSnt30GIs+4uxIZDnnd8mV5X3K4n4gjD+NAORc4DrQBvUGrYMKJsR5gtkH0nu6diWb1o1If7OiJEuCPRhrmQYcza7NUdABnA9Z2wn2RNUV9Ga33WUCqLMEU5GtNBlfQPiP/khCQrqn/ocR6wUjYut3J6YagzqH4wsfJi3glHyWtowcNIw1LZi5zFxHD/bRBT4Tln7yypkjWNq9eQILA6i6kRUGf7ggyTx26/k8n4tnu+QD0vVh4EcjlThpU/LGyUXzKrrxjRwaDZnM0oYxg5AfHcBuAiAdo0eWnV3lEWRfTJMIVb9MPf4qDmzR4RREfB5OXOxwq3ODeCcJE8sTIMD/wBPZrlqS/QrRpND2gn2X4snkVukN9t9F4CMTFMtVSzFV7TDJW5E5Lq6VEExulteQhs6kcK9NRPNAaLgRQAw7X9kVWfDtiGUP+fE2i8F9Bo8bm7sOT5O5VPMPykx3EgeNg1IqIgMTCsMlhMJT4xBJoQUgmd2wWyf3Ryw+P+sFgdb5Sd7+lFgJBjMUUoOxMxAOiEgdFvCXcr+/Udyz2RdtetU1/6VzXzLPcKOw0wubZeBkISqu7o9gpfdMP9Eq00=
file:
- dist/stash-osx
- dist/stash-win.exe
- dist/stash-linux
- dist/stash-pi
# make the release a draft so the maintainers can confirm before releasing
draft: true
skip_cleanup: true
overwrite: true
# don't write the body. To be done manually for now. In future we might
# want to generate the changelog or get it from a file
name: ${STASH_VERSION}
on:
repo: stashapp/stash
tags: true
# make sure we don't release using the latest_develop tag
condition: $TRAVIS_TAG != latest_develop

View File

@@ -8,7 +8,8 @@ release: generate ui build
build:
$(eval DATE := $(shell go run scripts/getDate.go))
$(eval GITHASH := $(shell git rev-parse --short HEAD))
$(SET) CGO_ENABLED=1 $(SEPARATOR) go build -mod=vendor -v -ldflags "-X 'github.com/stashapp/stash/pkg/api.buildstamp=$(DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)'"
$(eval STASH_VERSION := $(shell git describe --tags --exclude latest_develop))
$(SET) CGO_ENABLED=1 $(SEPARATOR) go build -mod=vendor -v -ldflags "-X 'github.com/stashapp/stash/pkg/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$(DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)'"
install:
packr2 install
@@ -20,13 +21,18 @@ clean:
.PHONY: generate
generate:
go generate -mod=vendor
cd ui/v2 && yarn run gqlgen
cd ui/v2.5 && yarn run gqlgen
# Runs gofmt -w on the project's source code, modifying any files that do not match its style.
.PHONY: fmt
fmt:
go fmt ./...
# Ensures that changed files have had gofmt run on them
.PHONY: fmt-check
fmt-check:
sh ./scripts/check-gofmt.sh
# Runs go vet on the project's source code.
.PHONY: vet
vet:
@@ -46,7 +52,31 @@ test:
it:
go test -mod=vendor -tags=integration ./...
# installs UI dependencies. Run when first cloning repository, or if UI
# dependencies have changed
.PHONY: pre-ui
pre-ui:
cd ui/v2.5 && yarn install --frozen-lockfile
.PHONY: ui
ui:
cd ui/v2 && yarn build
cd ui/v2.5 && yarn build
packr2
fmt-ui:
cd ui/v2.5 && yarn format
# runs tests and checks on the UI and builds it
.PHONY: ui-validate
ui-validate:
cd ui/v2.5 && yarn run validate
# just repacks the packr files - use when updating migrations and packed files without
# rebuilding the UI
.PHONY: packr
packr:
packr2
# runs all of the tests and checks required for a PR to be accepted
.PHONY: validate
validate: ui-validate fmt-check vet lint it

View File

@@ -69,7 +69,7 @@ Join the [Discord server](https://discord.gg/2TsNFKt).
* Go Install: `go get github.com/gobuffalo/packr/v2/packr2@v2.0.2`
* [Binary Download](https://github.com/gobuffalo/packr/releases)
* [Yarn](https://yarnpkg.com/en/docs/install) - Yarn package manager
* Run `yarn install --frozen-lockfile` in the `stash/ui/v2` folder (before running make generate for first time).
* Run `yarn install --frozen-lockfile` in the `stash/ui/v2.5` folder (before running make generate for first time).
NOTE: You may need to run the `go get` commands outside the project directory to avoid modifying the projects module file.
@@ -92,11 +92,18 @@ NOTE: The `make` command in Windows will be `mingw32-make` with MingW.
## Commands
* `make generate` - Generate Go GraphQL and packr2 files
* `make generate` - Generate Go and UI GraphQL files
* `make build` - Builds the binary (make sure to build the UI as well... see below)
* `make ui` - Builds the frontend
* `make pre-ui` - Installs the UI dependencies. Only needs to be run once before building the UI for the first time, or if the dependencies are updated
* `make fmt-ui` - Formats the UI source code.
* `make ui` - Builds the frontend and the packr2 files
* `make packr` - Generate packr2 files (sub-target of `ui`. Use to regenerate packr2 files without rebuilding UI)
* `make vet` - Run `go vet`
* `make lint` - Run the linter
* `make fmt` - Run `go fmt`
* `make fmt-check` - Ensure changed files are formatted correctly
* `make it` - Run the unit and integration tests
* `make validate` - Run all of the tests and checks required to submit a PR
## Building a release
@@ -111,3 +118,10 @@ where the app can be cross-compiled. This process is kicked off by CI via the `
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 stashappdev/compiler:latest /bin/bash`
## Customization
You can make Stash interface fit your desired style with [Custom CSS snippets](https://github.com/stashapp/stash/wiki/Custom-CSS-snippets) and [CSS Tweaks](https://github.com/stashapp/stash/wiki/CSS-Tweaks).
[Stash Plex Theme](https://github.com/stashapp/stash/wiki/Stash-Plex-Theme) is a community created theme inspired by popular Plex Interface.

View File

@@ -0,0 +1,55 @@
# this dockerfile must be built from the top-level stash directory
# ie from top=level stash:
# docker build -t stash/build -f docker/build/x86_64/Dockerfile .
FROM golang:1.11.13 as compiler
RUN apt-get update && apt-get install -y apt-transport-https
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && \
apt-get install -y nodejs yarn xz-utils --no-install-recommends || exit 1; \
rm -rf /var/lib/apt/lists/*;
ENV PACKR2_VERSION=2.0.2
ENV PACKR2_SHA=f95ff4c96d7a28813220df030ad91700b8464fe292ab3e1dc9582305c2a338d2
ENV PACKR2_DOWNLOAD_FILE=packr_${PACKR2_VERSION}_linux_amd64.tar.gz
ENV PACKR2_DOWNLOAD_URL=https://github.com/gobuffalo/packr/releases/download/v${PACKR2_VERSION}/${PACKR2_DOWNLOAD_FILE}
WORKDIR /
RUN wget ${PACKR2_DOWNLOAD_URL}; \
echo "$PACKR2_SHA $PACKR2_DOWNLOAD_FILE" | sha256sum -c - || exit 1; \
tar -xzf $PACKR2_DOWNLOAD_FILE -C /usr/bin/ packr2; \
rm $PACKR2_DOWNLOAD_FILE;
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN wget -O /ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
tar xf /ffmpeg.tar.xz && \
rm ffmpeg.tar.xz && \
mv /ffmpeg*/ /ffmpeg/
# copy the ui yarn stuff so that it doesn't get rebuilt every time
COPY ./ui/v2.5/package.json ./ui/v2.5/yarn.lock /stash/ui/v2.5/
WORKDIR /stash
RUN yarn --cwd ui/v2.5 install --frozen-lockfile
COPY . /stash/
ENV GO111MODULE=on
RUN make generate
RUN make ui
RUN make build
FROM ubuntu:19.10 as app
RUN apt-get update && apt-get -y install ca-certificates
COPY --from=compiler /stash/stash /ffmpeg/ffmpeg /ffmpeg/ffprobe /usr/bin/
EXPOSE 9999
CMD ["stash"]

View File

@@ -0,0 +1,67 @@
# Introduction
This dockerfile is used to build a stash docker container using the current source code.
# Building the docker container
From the top-level directory (should contain `main.go` file):
```
docker build -t stash/build -f ./docker/build/x86_64/Dockerfile .
```
# Running the docker container
## Using docker-compose
See the `README.md` file in `docker/production` for instructions on how to get docker-compose if needed.
The `stash/build` container can be run with the `docker-compose.yml` file in `docker/production` by changing the `image` value to be `stash/build`. See the instructions in `docker/production` for how to run docker-compose.
## Using `docker run`
After building the container:
```
docker run \
-e STASH_STASH=/data/ \
-e STASH_METADATA=/metadata/ \
-e STASH_CACHE=/cache/ \
-e STASH_GENERATED=/generated/ \
-v <path to config dir>:/root/.stash \
-v <path to media>:/data \
-v <path to metadata>:/metadata \
-v <path to cache>:/cache \
-v <path to generated>:/generated \
-p 9999:9999 \
stash/build:latest
```
Change the `<xxx>` to the appropriate paths. Note that the `<path to media>` directory should be separate from the cache, generated and metadata directories. It is recommended to have the cache, generated and metadata directories in the same parent directory, for example:
```
/stash
/config
/metadata
/generated
/cache
/media
```
Using this example directory structure, the above command would be:
```
docker run \
-e STASH_STASH=/data/ \
-e STASH_METADATA=/metadata/ \
-e STASH_CACHE=/cache/ \
-e STASH_GENERATED=/generated/ \
-v /stash/config:/root/.stash \
-v /media:/data \
-v /stash/metadata:/metadata \
-v /stash/cache:/cache \
-v /stash/generated:/generated \
-p 9999:9999 \
stash/build:latest
```

View File

@@ -0,0 +1,21 @@
FROM ubuntu:18.04 as prep
LABEL MAINTAINER="https://discord.gg/Uz29ny"
RUN apt-get update && \
apt-get -y install curl xz-utils && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*
WORKDIR /
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -L -o /stash $(curl -s https://api.github.com/repos/stashapp/stash/releases/tags/latest_develop | awk '/browser_download_url/ && /stash-linux/' | sed -e 's/.*: "\(.*\)"/\1/') && \
chmod +x /stash && \
curl --http1.1 -o /ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
tar xf /ffmpeg.tar.xz && \
rm ffmpeg.tar.xz && \
mv /ffmpeg*/ /ffmpeg/
FROM ubuntu:18.04 as app
RUN apt-get update && apt-get -y install ca-certificates
COPY --from=prep /stash /ffmpeg/ffmpeg /ffmpeg/ffprobe /usr/bin/
EXPOSE 9999
CMD ["stash"]

View File

@@ -7,17 +7,15 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
WORKDIR /
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN curl -L -o /stash $(curl -s https://api.github.com/repos/stashapp/stash/releases | grep -F 'stash-linux' | grep download | head -n 1 | cut -d'"' -f4) && \
RUN curl -L -o /stash $(curl -s https://api.github.com/repos/stashapp/stash/releases/latest | awk '/browser_download_url/ && /stash-linux/' | sed -e 's/.*: "\(.*\)"/\1/') && \
chmod +x /stash && \
curl -o /ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
curl --http1.1 -o /ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \
tar xf /ffmpeg.tar.xz && \
rm ffmpeg.tar.xz && \
mv /ffmpeg*/ /ffmpeg/
FROM ubuntu:18.04 as app
RUN apt-get update && \
apt-get -y install ca-certificates && \
adduser stash --gecos GECOS --shell /bin/bash --disabled-password --home /home/stash
RUN apt-get update && apt-get -y install ca-certificates
COPY --from=prep /stash /ffmpeg/ffmpeg /ffmpeg/ffprobe /usr/bin/
EXPOSE 9999
CMD ["stash"]

14
docs/CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,14 @@
## Technical Debt
Please be sure to consider how heavily your contribution impacts the maintainability of the project long term, sometimes less is more. We don't want to merge collossal pull requests with hundreds of dependencies by a driveby contributor.
## Contributor Checklist
Please make sure that you've considered the following before you submit your Pull Requests as ready for merging.
* I've run Code linters and [gofmt](https://golang.org/cmd/gofmt/) to make sure that my code is readable.
* I have read through formerly submitted [pull requests](https://github.com/stashapp/stash/pulls) and [git issues](https://github.com/stashapp/stash/issues) to make sure that this contribution is required and isn't a duplicate. Also, so that I can manage to close any git Issues needing closed relating to this feature submission.
* I commented adequately on my code with the expectation in mind that anyone else should be able to look at this code I've submitted and know exactly what's happening and what the expectations are.
### Legal Agreements
* I acknowledge that if applicable to me, submitting and subsequent acceptance of this Pull Request I, the code contributor of this Pull Request, agree and acknowledge my understanding that the new code license has now been updated to [AGPL](/LICENSE.md). I agree that all code before this Pull Request, which I've previously submitted, is now to be re-licensed under the new license AGPL and no longer the former MIT license.
**In case you were unable to follow any of the above include an explanation as to why not in your Pull Request.**

17
go.mod
View File

@@ -2,29 +2,30 @@ module github.com/stashapp/stash
require (
github.com/99designs/gqlgen v0.9.0
github.com/PuerkitoBio/goquery v1.5.0
github.com/antchfx/htmlquery v1.2.0
github.com/antchfx/xpath v1.1.2 // indirect
github.com/bmatcuk/doublestar v1.1.5
github.com/antchfx/htmlquery v1.2.3
github.com/bmatcuk/doublestar v1.3.1
github.com/disintegration/imaging v1.6.0
github.com/go-chi/chi v4.0.2+incompatible
github.com/gobuffalo/packr/v2 v2.0.2
github.com/golang-migrate/migrate/v4 v4.3.1
github.com/gorilla/sessions v1.2.0
github.com/gorilla/websocket v1.4.0
github.com/h2non/filetype v1.0.8
// this is required for generate
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/jmoiron/sqlx v1.2.0
github.com/mattn/go-sqlite3 v1.10.0
github.com/json-iterator/go v1.1.9
github.com/mattn/go-sqlite3 v1.13.0
github.com/rs/cors v1.6.0
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.5.1
github.com/vektah/gqlparser v1.1.2
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2 // indirect
golang.org/x/net v0.0.0-20190522155817-f3200d17e092
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd
gopkg.in/yaml.v2 v2.2.2
)

40
go.sum
View File

@@ -16,8 +16,6 @@ github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk=
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/agnivade/levenshtein v1.0.1 h1:3oJU7J3FGFmyhn8KHjmVaZCN5hxTr7GxgRue+sxIXdQ=
@@ -27,13 +25,11 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antchfx/htmlquery v1.2.0 h1:oKShnsGlnOHX6t4uj5OHgLKkABcJoqnXpqnscoi9Lpw=
github.com/antchfx/htmlquery v1.2.0/go.mod h1:MS9yksVSQXls00iXkiMqXr0J+umL/AmxXKuP28SUJM8=
github.com/antchfx/xpath v1.1.2 h1:YziPrtM0gEJBnhdUGxYcIVYXZ8FXbtbovxOi+UW/yWQ=
github.com/antchfx/xpath v1.1.2/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
github.com/antchfx/htmlquery v1.2.3 h1:sP3NFDneHx2stfNXCKbhHFo8XgNjCACnU/4AO5gWz6M=
github.com/antchfx/htmlquery v1.2.3/go.mod h1:B0ABL+F5irhhMWg54ymEZinzMSi0Kt3I2if0BLYa3V0=
github.com/antchfx/xpath v1.1.6 h1:6sVh6hB5T6phw1pFpHRQ+C4bd8sNI+O58flqtg7h0R0=
github.com/antchfx/xpath v1.1.6/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
@@ -41,8 +37,8 @@ github.com/aws/aws-sdk-go v1.17.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bmatcuk/doublestar v1.1.5 h1:2bNwBOmhyFEFcoB3tGvTD5xanq+4kyOZlB8wFYbMjkk=
github.com/bmatcuk/doublestar v1.1.5/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/bmatcuk/doublestar v1.3.1 h1:rT8rxDPsavp9G+4ZULzqhhUSaI/OPsTZNG88Z3i0xvY=
github.com/bmatcuk/doublestar v1.3.1/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
@@ -81,6 +77,7 @@ github.com/docker/docker v0.7.3-0.20190108045446-77df18c24acf/go.mod h1:eEKB0N0r
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v0.0.0-20180713052910-9f541cc9db5d/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
@@ -325,6 +322,8 @@ github.com/golang-migrate/migrate/v4 v4.3.1/go.mod h1:mJ89KBgbXmM3P49BqOxRL3riNF
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
@@ -340,6 +339,7 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
@@ -352,9 +352,12 @@ github.com/gorilla/mux v1.6.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/pat v0.0.0-20180118222023-199c85a7f6d1/go.mod h1:YeAe0gNeiNT5hoiZRI4yiOky6jVdNvfO2N6Kav/HmxY=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.1.2/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
github.com/gorilla/sessions v1.1.3/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
@@ -383,6 +386,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ=
github.com/jackc/pgx v3.2.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o=
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0/go.mod h1:IiEW3SEiiErVyFdH8NTuWjSifiEQKUoyK3LNqr2kCHU=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
@@ -391,6 +396,8 @@ github.com/joho/godotenv v1.2.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
@@ -445,6 +452,8 @@ github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.13.0 h1:LnJI81JidiW9r7pS/hXe6cFeO5EXNq7KbfvoJLRI69c=
github.com/mattn/go-sqlite3 v1.13.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
@@ -453,6 +462,10 @@ github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047/go.mod h1:F
github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mongodb/mongo-go-driver v0.3.0/go.mod h1:NK/HWDIIZkaYsnYa0hmtP443T5ELr0KDecmIioVuuyU=
github.com/monoculum/formam v0.0.0-20180901015400-4e68be1d79ba/go.mod h1:RKgILGEJq24YyJ2ban8EO0RUVSJlF1pGsEvoLEACr/Q=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -574,6 +587,8 @@ github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -633,7 +648,6 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180816102801-aaf60122140d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -660,6 +674,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -703,6 +719,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190426135247-a129542de9ae h1:mQLHiymj/JXKnnjc62tb7nD5pZLs940/sXJu+Xp3DBA=
golang.org/x/sys v0.0.0-20190426135247-a129542de9ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@@ -26,6 +26,8 @@ models:
model: github.com/stashapp/stash/pkg/models.ScrapedItem
Studio:
model: github.com/stashapp/stash/pkg/models.Studio
Movie:
model: github.com/stashapp/stash/pkg/models.Movie
Tag:
model: github.com/stashapp/stash/pkg/models.Tag
ScrapedPerformer:
@@ -36,6 +38,8 @@ models:
model: github.com/stashapp/stash/pkg/models.ScrapedScenePerformer
ScrapedSceneStudio:
model: github.com/stashapp/stash/pkg/models.ScrapedSceneStudio
ScrapedSceneMovie:
model: github.com/stashapp/stash/pkg/models.ScrapedSceneMovie
ScrapedSceneTag:
model: github.com/stashapp/stash/pkg/models.ScrapedSceneTag
SceneFileType:

View File

@@ -2,25 +2,32 @@ fragment ConfigGeneralData on ConfigGeneralResult {
stashes
databasePath
generatedPath
cachePath
maxTranscodeSize
maxStreamingTranscodeSize
forceMkv
forceHevc
username
password
maxSessionAge
logFile
logOut
logLevel
logAccess
excludes
scraperUserAgent
}
fragment ConfigInterfaceData on ConfigInterfaceResult {
soundOnPreview
wallShowTitle
wallPlayback
maximumLoopDuration
autostartVideo
showStudioAsText
css
cssEnabled
language
}
fragment ConfigData on ConfigResult {

View File

@@ -0,0 +1,5 @@
fragment SlimMovieData on Movie {
id
name
front_image_path
}

View File

@@ -0,0 +1,20 @@
fragment MovieData on Movie {
id
checksum
name
aliases
duration
date
rating
director
studio {
...StudioData
}
synopsis
url
front_image_path
back_image_path
scene_count
}

View File

@@ -1,5 +1,6 @@
fragment SlimPerformerData on Performer {
id
name
gender
image_path
}

View File

@@ -3,6 +3,7 @@ fragment PerformerData on Performer {
checksum
name
url
gender
twitter
instagram
birthdate

View File

@@ -47,6 +47,15 @@ fragment SlimSceneData on Scene {
image_path
}
movies {
movie {
id
name
front_image_path
}
scene_index
}
tags {
id
name

View File

@@ -42,6 +42,13 @@ fragment SceneData on Scene {
studio {
...StudioData
}
movies {
movie {
...MovieData
}
scene_index
}
tags {
...TagData

View File

@@ -1,5 +1,27 @@
fragment ScrapedPerformerData on ScrapedPerformer {
name
gender
url
twitter
instagram
birthdate
ethnicity
country
eye_color
height
measurements
fake_tits
career_length
tattoos
piercings
aliases
image
}
fragment ScrapedScenePerformerData on ScrapedScenePerformer {
id
name
gender
url
twitter
instagram
@@ -16,23 +38,27 @@ fragment ScrapedPerformerData on ScrapedPerformer {
aliases
}
fragment ScrapedScenePerformerData on ScrapedScenePerformer {
fragment ScrapedMovieData on ScrapedMovie {
name
aliases
duration
date
rating
director
url
synopsis
}
fragment ScrapedSceneMovieData on ScrapedSceneMovie {
id
name
url
twitter
instagram
birthdate
ethnicity
country
eye_color
height
measurements
fake_tits
career_length
tattoos
piercings
aliases
duration
date
rating
director
url
synopsis
}
fragment ScrapedSceneStudioData on ScrapedSceneStudio {
@@ -51,6 +77,7 @@ fragment ScrapedSceneData on ScrapedScene {
details
url
date
image
file {
size
@@ -74,4 +101,8 @@ fragment ScrapedSceneData on ScrapedScene {
performers {
...ScrapedScenePerformerData
}
movies {
...ScrapedSceneMovieData
}
}

View File

@@ -0,0 +1,27 @@
mutation MetadataImport {
metadataImport
}
mutation MetadataExport {
metadataExport
}
mutation MetadataScan($input: ScanMetadataInput!) {
metadataScan(input: $input)
}
mutation MetadataGenerate($input: GenerateMetadataInput!) {
metadataGenerate(input: $input)
}
mutation MetadataAutoTag($input: AutoTagMetadataInput!) {
metadataAutoTag(input: $input)
}
mutation MetadataClean {
metadataClean
}
mutation StopJob {
stopJob
}

View File

@@ -0,0 +1,40 @@
mutation MovieCreate(
$name: String!,
$aliases: String,
$duration: Int,
$date: String,
$rating: Int,
$studio_id: ID,
$director: String,
$synopsis: String,
$url: String,
$front_image: String,
$back_image: String) {
movieCreate(input: { name: $name, aliases: $aliases, duration: $duration, date: $date, rating: $rating, studio_id: $studio_id, director: $director, synopsis: $synopsis, url: $url, front_image: $front_image, back_image: $back_image }) {
...MovieData
}
}
mutation MovieUpdate(
$id: ID!
$name: String,
$aliases: String,
$duration: Int,
$date: String,
$rating: Int,
$studio_id: ID,
$director: String,
$synopsis: String,
$url: String,
$front_image: String,
$back_image: String) {
movieUpdate(input: { id: $id, name: $name, aliases: $aliases, duration: $duration, date: $date, rating: $rating, studio_id: $studio_id, director: $director, synopsis: $synopsis, url: $url, front_image: $front_image, back_image: $back_image }) {
...MovieData
}
}
mutation MovieDestroy($id: ID!) {
movieDestroy(input: { id: $id })
}

View File

@@ -1,6 +1,7 @@
mutation PerformerCreate(
$name: String,
$url: String,
$gender: GenderEnum,
$birthdate: String,
$ethnicity: String,
$country: String,
@@ -20,6 +21,7 @@ mutation PerformerCreate(
performerCreate(input: {
name: $name,
url: $url,
gender: $gender,
birthdate: $birthdate,
ethnicity: $ethnicity,
country: $country,
@@ -44,6 +46,7 @@ mutation PerformerUpdate(
$id: ID!,
$name: String,
$url: String,
$gender: GenderEnum,
$birthdate: String,
$ethnicity: String,
$country: String,
@@ -64,6 +67,7 @@ mutation PerformerUpdate(
id: $id,
name: $name,
url: $url,
gender: $gender,
birthdate: $birthdate,
ethnicity: $ethnicity,
country: $country,

View File

@@ -8,6 +8,7 @@ mutation SceneUpdate(
$studio_id: ID,
$gallery_id: ID,
$performer_ids: [ID!] = [],
$movies: [SceneMovieInput!] = [],
$tag_ids: [ID!] = [],
$cover_image: String) {
@@ -21,6 +22,7 @@ mutation SceneUpdate(
studio_id: $studio_id,
gallery_id: $gallery_id,
performer_ids: $performer_ids,
movies: $movies,
tag_ids: $tag_ids,
cover_image: $cover_image
}) {
@@ -37,8 +39,8 @@ mutation BulkSceneUpdate(
$rating: Int,
$studio_id: ID,
$gallery_id: ID,
$performer_ids: [ID!],
$tag_ids: [ID!]) {
$performer_ids: BulkUpdateIds,
$tag_ids: BulkUpdateIds) {
bulkSceneUpdate(input: {
ids: $ids,
@@ -76,4 +78,8 @@ mutation SceneResetO($id: ID!) {
mutation SceneDestroy($id: ID!, $delete_file: Boolean, $delete_generated : Boolean) {
sceneDestroy(input: {id: $id, delete_file: $delete_file, delete_generated: $delete_generated})
}
}
mutation SceneGenerateScreenshot($id: ID!, $at: Float) {
sceneGenerateScreenshot(id: $id, at: $at)
}

View File

@@ -19,19 +19,24 @@ query AllTags {
}
query AllPerformersForFilter {
allPerformers {
allPerformersSlim {
...SlimPerformerData
}
}
query AllStudiosForFilter {
allStudios {
allStudiosSlim {
...SlimStudioData
}
}
query AllMoviesForFilter {
allMoviesSlim {
...SlimMovieData
}
}
query AllTagsForFilter {
allTags {
allTagsSlim {
id
name
}
@@ -47,9 +52,11 @@ query ValidGalleriesForScene($scene_id: ID!) {
query Stats {
stats {
scene_count,
scene_size_count,
gallery_count,
performer_count,
studio_count,
movie_count,
tag_count
}
}

View File

@@ -0,0 +1,14 @@
query FindMovies($filter: FindFilterType, $movie_filter: MovieFilterType) {
findMovies(filter: $filter, movie_filter: $movie_filter) {
count
movies {
...MovieData
}
}
}
query FindMovie($id: ID!) {
findMovie(id: $id) {
...MovieData
}
}

View File

@@ -46,6 +46,9 @@ query ParseSceneFilenames($filter: FindFilterType!, $config: SceneParserInput!)
rating
studio_id
gallery_id
movies {
movie_id
}
performer_ids
tag_ids
}

View File

@@ -4,6 +4,10 @@ query Configuration {
}
}
query Directories($path: String) {
directories(path: $path)
}
query Directory($path: String) {
directory(path: $path) {
path
parent
directories
}
}

View File

@@ -1,27 +1,3 @@
query MetadataImport {
metadataImport
}
query MetadataExport {
metadataExport
}
query MetadataScan($input: ScanMetadataInput!) {
metadataScan(input: $input)
}
query MetadataGenerate($input: GenerateMetadataInput!) {
metadataGenerate(input: $input)
}
query MetadataAutoTag($input: AutoTagMetadataInput!) {
metadataAutoTag(input: $input)
}
query MetadataClean {
metadataClean
}
query JobStatus {
jobStatus {
progress
@@ -29,7 +5,3 @@ query JobStatus {
message
}
}
query StopJob {
stopJob
}

View File

@@ -22,6 +22,11 @@ type Query {
"""A function which queries Studio objects"""
findStudios(filter: FindFilterType): FindStudiosResultType!
"""Find a movie by ID"""
findMovie(id: ID!): Movie
"""A function which queries Movie objects"""
findMovies(movie_filter: MovieFilterType, filter: FindFilterType): FindMoviesResultType!
findGallery(id: ID!): Gallery
findGalleries(filter: FindFilterType): FindGalleriesResultType!
@@ -68,32 +73,26 @@ type Query {
"""Returns the current, complete configuration"""
configuration: ConfigResult!
"""Returns an array of paths for the given path"""
directories(path: String): [String!]!
directory(path: String): Directory!
# Metadata
"""Start an import. Returns the job ID"""
metadataImport: String!
"""Start an export. Returns the job ID"""
metadataExport: String!
"""Start a scan. Returns the job ID"""
metadataScan(input: ScanMetadataInput!): String!
"""Start generating content. Returns the job ID"""
metadataGenerate(input: GenerateMetadataInput!): String!
"""Start auto-tagging. Returns the job ID"""
metadataAutoTag(input: AutoTagMetadataInput!): String!
"""Clean metadata. Returns the job ID"""
metadataClean: String!
jobStatus: MetadataUpdateStatus!
stopJob: Boolean!
# Get everything
allPerformers: [Performer!]!
allStudios: [Studio!]!
allMovies: [Movie!]!
allTags: [Tag!]!
# Get everything with minimal metadata
allPerformersSlim: [Performer!]!
allStudiosSlim: [Studio!]!
allMoviesSlim: [Movie!]!
allTagsSlim: [Tag!]!
# Version
version: Version!
@@ -114,6 +113,9 @@ type Mutation {
"""Resets the o-counter for a scene to 0. Returns the new value"""
sceneResetO(id: ID!): Int!
"""Generates screenshot at specified time in seconds. Leave empty to generate default screenshot"""
sceneGenerateScreenshot(id: ID!, at: Float): String!
sceneMarkerCreate(input: SceneMarkerCreateInput!): SceneMarker
sceneMarkerUpdate(input: SceneMarkerUpdateInput!): SceneMarker
sceneMarkerDestroy(id: ID!): Boolean!
@@ -126,6 +128,10 @@ type Mutation {
studioUpdate(input: StudioUpdateInput!): Studio
studioDestroy(input: StudioDestroyInput!): Boolean!
movieCreate(input: MovieCreateInput!): Movie
movieUpdate(input: MovieUpdateInput!): Movie
movieDestroy(input: MovieDestroyInput!): Boolean!
tagCreate(input: TagCreateInput!): Tag
tagUpdate(input: TagUpdateInput!): Tag
tagDestroy(input: TagDestroyInput!): Boolean!
@@ -133,6 +139,21 @@ type Mutation {
"""Change general configuration options"""
configureGeneral(input: ConfigGeneralInput!): ConfigGeneralResult!
configureInterface(input: ConfigInterfaceInput!): ConfigInterfaceResult!
"""Start an import. Returns the job ID"""
metadataImport: String!
"""Start an export. Returns the job ID"""
metadataExport: String!
"""Start a scan. Returns the job ID"""
metadataScan(input: ScanMetadataInput!): String!
"""Start generating content. Returns the job ID"""
metadataGenerate(input: GenerateMetadataInput!): String!
"""Start auto-tagging. Returns the job ID"""
metadataAutoTag(input: AutoTagMetadataInput!): String!
"""Clean metadata. Returns the job ID"""
metadataClean: String!
stopJob: Boolean!
}
type Subscription {

View File

@@ -14,14 +14,22 @@ input ConfigGeneralInput {
databasePath: String
"""Path to generated files"""
generatedPath: String
"""Path to cache"""
cachePath: String
"""Max generated transcode size"""
maxTranscodeSize: StreamingResolutionEnum
"""Max streaming transcode size"""
maxStreamingTranscodeSize: StreamingResolutionEnum
"""Force MKV as supported format"""
forceMkv: Boolean!
"""Force HEVC as a supported codec"""
forceHevc: Boolean!
"""Username"""
username: String
"""Password"""
password: String
"""Maximum session cookie age"""
maxSessionAge: Int
"""Name of the log file"""
logFile: String
"""Whether to also output to stderr"""
@@ -32,6 +40,8 @@ input ConfigGeneralInput {
logAccess: Boolean!
"""Array of file regexp to exclude from Scan"""
excludes: [String!]
"""Scraper user agent string"""
scraperUserAgent: String
}
type ConfigGeneralResult {
@@ -41,14 +51,22 @@ type ConfigGeneralResult {
databasePath: String!
"""Path to generated files"""
generatedPath: String!
"""Max generated transcode size"""
"""Path to cache"""
cachePath: String!
"""Max generated transcode size"""
maxTranscodeSize: StreamingResolutionEnum
"""Max streaming transcode size"""
maxStreamingTranscodeSize: StreamingResolutionEnum
"""Force MKV as supported format"""
forceMkv: Boolean!
"""Force HEVC as a supported codec"""
forceHevc: Boolean!
"""Username"""
username: String!
"""Password"""
password: String!
"""Maximum session cookie age"""
maxSessionAge: Int!
"""Name of the log file"""
logFile: String
"""Whether to also output to stderr"""
@@ -59,6 +77,8 @@ type ConfigGeneralResult {
logAccess: Boolean!
"""Array of file regexp to exclude from Scan"""
excludes: [String!]!
"""Scraper user agent string"""
scraperUserAgent: String
}
input ConfigInterfaceInput {
@@ -66,6 +86,8 @@ input ConfigInterfaceInput {
soundOnPreview: Boolean
"""Show title and tags in wall view"""
wallShowTitle: Boolean
"""Wall playback type"""
wallPlayback: String
"""Maximum duration (in seconds) in which a scene video will loop in the scene player"""
maximumLoopDuration: Int
"""If true, video will autostart on load in the scene player"""
@@ -75,6 +97,7 @@ input ConfigInterfaceInput {
"""Custom CSS"""
css: String
cssEnabled: Boolean
language: String
}
type ConfigInterfaceResult {
@@ -82,6 +105,8 @@ type ConfigInterfaceResult {
soundOnPreview: Boolean
"""Show title and tags in wall view"""
wallShowTitle: Boolean
"""Wall playback type"""
wallPlayback: String
"""Maximum duration (in seconds) in which a scene video will loop in the scene player"""
maximumLoopDuration: Int
"""If true, video will autostart on load in the scene player"""
@@ -91,6 +116,8 @@ type ConfigInterfaceResult {
"""Custom CSS"""
css: String
cssEnabled: Boolean
"""Interface language"""
language: String
}
"""All configuration settings"""
@@ -98,3 +125,10 @@ type ConfigResult {
general: ConfigGeneralResult!
interface: ConfigInterfaceResult!
}
"""Directory structure of a path"""
type Directory {
path: String!
parent: String
directories: [String!]!
}

View File

@@ -46,6 +46,10 @@ input PerformerFilterType {
piercings: StringCriterionInput
"""Filter by aliases"""
aliases: StringCriterionInput
"""Filter by gender"""
gender: GenderCriterionInput
"""Filter to only include performers missing this property"""
is_missing: String
}
input SceneMarkerFilterType {
@@ -74,12 +78,19 @@ input SceneFilterType {
is_missing: String
"""Filter to only include scenes with this studio"""
studios: MultiCriterionInput
"""Filter to only include scenes with this movie"""
movies: MultiCriterionInput
"""Filter to only include scenes with these tags"""
tags: MultiCriterionInput
"""Filter to only include scenes with these performers"""
performers: MultiCriterionInput
}
input MovieFilterType {
"""Filter to only include movies with this studio"""
studios: MultiCriterionInput
}
enum CriterionModifier {
"""="""
EQUALS,
@@ -112,4 +123,9 @@ input IntCriterionInput {
input MultiCriterionInput {
value: [ID!]
modifier: CriterionModifier!
}
input GenderCriterionInput {
value: GenderEnum
modifier: CriterionModifier!
}

View File

@@ -1,8 +1,12 @@
input GenerateMetadataInput {
sprites: Boolean!
previews: Boolean!
previewPreset: PreviewPreset
imagePreviews: Boolean!
markers: Boolean!
transcodes: Boolean!
"""gallery thumbnails for cache usage"""
thumbnails: Boolean!
}
input ScanMetadataInput {
@@ -20,6 +24,16 @@ input AutoTagMetadataInput {
type MetadataUpdateStatus {
progress: Float!
status: String!
status: String!
message: String!
}
}
enum PreviewPreset {
"X264_ULTRAFAST", ultrafast
"X264_VERYFAST", veryfast
"X264_FAST", fast
"X264_MEDIUM", medium
"X264_SLOW", slow
"X264_SLOWER", slower
"X264_VERYSLOW", veryslow
}

View File

@@ -0,0 +1,59 @@
type Movie {
id: ID!
checksum: String!
name: String!
aliases: String
"""Duration in seconds"""
duration: Int
date: String
rating: Int
studio: Studio
director: String
synopsis: String
url: String
front_image_path: String # Resolver
back_image_path: String # Resolver
scene_count: Int # Resolver
}
input MovieCreateInput {
name: String!
aliases: String
"""Duration in seconds"""
duration: Int
date: String
rating: Int
studio_id: ID
director: String
synopsis: String
url: String
"""This should be base64 encoded"""
front_image: String
back_image: String
}
input MovieUpdateInput {
id: ID!
name: String
aliases: String
duration: Int
date: String
rating: Int
studio_id: ID
director: String
synopsis: String
url: String
"""This should be base64 encoded"""
front_image: String
back_image: String
}
input MovieDestroyInput {
id: ID!
}
type FindMoviesResultType {
count: Int!
movies: [Movie!]!
}

View File

@@ -1,8 +1,17 @@
enum GenderEnum {
MALE
FEMALE
TRANSGENDER_MALE
TRANSGENDER_FEMALE
INTERSEX
}
type Performer {
id: ID!
checksum: String!
name: String
url: String
gender: GenderEnum
twitter: String
instagram: String
birthdate: String
@@ -26,6 +35,7 @@ type Performer {
input PerformerCreateInput {
name: String
url: String
gender: GenderEnum
birthdate: String
ethnicity: String
country: String
@@ -48,6 +58,7 @@ input PerformerUpdateInput {
id: ID!
name: String
url: String
gender: GenderEnum
birthdate: String
ethnicity: String
country: String

View File

@@ -18,6 +18,11 @@ type ScenePathsType {
chapters_vtt: String # Resolver
}
type SceneMovie {
movie: Movie!
scene_index: Int
}
type Scene {
id: ID!
checksum: String!
@@ -36,10 +41,16 @@ type Scene {
scene_markers: [SceneMarker!]!
gallery: Gallery
studio: Studio
movies: [SceneMovie!]!
tags: [Tag!]!
performers: [Performer!]!
}
input SceneMovieInput {
movie_id: ID!
scene_index: Int
}
input SceneUpdateInput {
clientMutationId: String
id: ID!
@@ -51,11 +62,23 @@ input SceneUpdateInput {
studio_id: ID
gallery_id: ID
performer_ids: [ID!]
movies: [SceneMovieInput!]
tag_ids: [ID!]
"""This should be base64 encoded"""
cover_image: String
}
enum BulkUpdateIdMode {
SET
ADD
REMOVE
}
input BulkUpdateIds {
ids: [ID!]
mode: BulkUpdateIdMode!
}
input BulkSceneUpdateInput {
clientMutationId: String
ids: [ID!]
@@ -66,8 +89,8 @@ input BulkSceneUpdateInput {
rating: Int
studio_id: ID
gallery_id: ID
performer_ids: [ID!]
tag_ids: [ID!]
performer_ids: BulkUpdateIds
tag_ids: BulkUpdateIds
}
input SceneDestroyInput {
@@ -87,6 +110,11 @@ input SceneParserInput {
capitalizeTitle: Boolean
}
type SceneMovieID {
movie_id: ID!
scene_index: String
}
type SceneParserResult {
scene: Scene!
title: String
@@ -97,6 +125,7 @@ type SceneParserResult {
studio_id: ID
gallery_id: ID
performer_ids: [ID!]
movies: [SceneMovieID!]
tag_ids: [ID!]
}

View File

@@ -0,0 +1,22 @@
"""A movie from a scraping operation..."""
type ScrapedMovie {
name: String
aliases: String
duration: String
date: String
rating: String
director: String
url: String
synopsis: String
}
input ScrapedMovieInput {
name: String
aliases: String
duration: String
date: String
rating: String
director: String
url: String
synopsis: String
}

View File

@@ -1,6 +1,7 @@
"""A performer from a scraping operation..."""
type ScrapedPerformer {
name: String
gender: String
url: String
twitter: String
instagram: String
@@ -15,10 +16,14 @@ type ScrapedPerformer {
tattoos: String
piercings: String
aliases: String
"""This should be base64 encoded"""
image: String
}
input ScrapedPerformerInput {
name: String
gender: String
url: String
twitter: String
instagram: String
@@ -33,4 +38,6 @@ input ScrapedPerformerInput {
tattoos: String
piercings: String
aliases: String
# not including image for the input
}

View File

@@ -27,6 +27,7 @@ type ScrapedScenePerformer {
"""Set if performer matched"""
id: ID
name: String!
gender: String
url: String
twitter: String
instagram: String
@@ -43,6 +44,19 @@ type ScrapedScenePerformer {
aliases: String
}
type ScrapedSceneMovie {
"""Set if movie matched"""
id: ID
name: String!
aliases: String
duration: String
date: String
rating: String
director: String
synopsis: String
url: String
}
type ScrapedSceneStudio {
"""Set if studio matched"""
id: ID
@@ -62,9 +76,13 @@ type ScrapedScene {
url: String
date: String
"""This should be base64 encoded"""
image: String
file: SceneFileType # Resolver
studio: ScrapedSceneStudio
tags: [ScrapedSceneTag!]
performers: [ScrapedScenePerformer!]
movies: [ScrapedSceneMovie!]
}

View File

@@ -1,7 +1,9 @@
type StatsResultType {
scene_count: Int!
scene_size_count: String!
gallery_count: Int!
performer_count: Int!
studio_count: Int!
movie_count: Int!
tag_count: Int!
}
}

72
pkg/api/cache_thumbs.go Normal file
View File

@@ -0,0 +1,72 @@
package api
import (
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager/paths"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"io/ioutil"
)
type thumbBuffer struct {
path string
dir string
data []byte
}
func newCacheThumb(dir string, path string, data []byte) *thumbBuffer {
t := thumbBuffer{dir: dir, path: path, data: data}
return &t
}
var writeChan chan *thumbBuffer
var touchChan chan *string
func startThumbCache() { // TODO add extra wait, close chan code if/when stash gets a stop mode
writeChan = make(chan *thumbBuffer, 20)
go thumbnailCacheWriter()
}
//serialize file writes to avoid race conditions
func thumbnailCacheWriter() {
for thumb := range writeChan {
exists, _ := utils.FileExists(thumb.path)
if !exists {
err := utils.WriteFile(thumb.path, thumb.data)
if err != nil {
logger.Errorf("Write error for thumbnail %s: %s ", thumb.path, err)
}
}
}
}
// get thumbnail from cache, otherwise create it and store to cache
func cacheGthumb(gallery *models.Gallery, index int, width int) []byte {
thumbPath := paths.GetGthumbPath(gallery.Checksum, index, width)
exists, _ := utils.FileExists(thumbPath)
if exists { // if thumbnail exists in cache return that
content, err := ioutil.ReadFile(thumbPath)
if err == nil {
return content
} else {
logger.Errorf("Read Error for file %s : %s", thumbPath, err)
}
}
data := gallery.GetThumbnail(index, width)
thumbDir := paths.GetGthumbDir(gallery.Checksum)
t := newCacheThumb(thumbDir, thumbPath, data)
writeChan <- t // write the file to cache
return data
}
// create all thumbs for a given gallery
func CreateGthumbs(gallery *models.Gallery) {
count := gallery.ImageCount()
for i := 0; i < count; i++ {
cacheGthumb(gallery, i, models.DefaultGthumbWidth)
}
}

View File

@@ -2,18 +2,26 @@ package api
import (
"encoding/json"
"errors"
"fmt"
"github.com/stashapp/stash/pkg/logger"
"io/ioutil"
"net/http"
"regexp"
"runtime"
"time"
"github.com/stashapp/stash/pkg/logger"
)
//we use the github REST V3 API as no login is required
const apiURL string = "https://api.github.com/repos/stashapp/stash/tags"
const apiReleases string = "https://api.github.com/repos/stashapp/stash/releases"
const apiTags string = "https://api.github.com/repos/stashapp/stash/tags"
const apiAcceptHeader string = "application/vnd.github.v3+json"
const developmentTag string = "latest_develop"
// ErrNoVersion indicates that no version information has been embedded in the
// stash binary
var ErrNoVersion = errors.New("no stash version")
var stashReleases = func() map[string]string {
return map[string]string{
@@ -24,17 +32,6 @@ var stashReleases = func() map[string]string {
}
}
type githubTagResponse struct {
Name string
Zipball_url string
Tarball_url string
Commit struct {
Sha string
Url string
}
Node_id string
}
type githubReleasesResponse struct {
Url string
Assets_url string
@@ -93,74 +90,118 @@ type githubAsset struct {
Browser_download_url string
}
//gets latest version (git commit hash) from github API
//the repo's tags are used to find the latest version
//of the "master" or "develop" branch
type githubTagResponse struct {
Name string
Zipball_url string
Tarball_url string
Commit struct {
Sha string
Url string
}
Node_id string
}
func makeGithubRequest(url string, output interface{}) error {
client := &http.Client{
Timeout: 3 * time.Second,
}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Accept", apiAcceptHeader) // gh api recommendation , send header with api version
response, err := client.Do(req)
if err != nil {
return fmt.Errorf("Github API request failed: %s", err)
}
if response.StatusCode != http.StatusOK {
return fmt.Errorf("Github API request failed: %s", response.Status)
}
defer response.Body.Close()
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return fmt.Errorf("Github API read response failed: %s", err)
}
err = json.Unmarshal(data, output)
if err != nil {
return fmt.Errorf("Unmarshalling Github API response failed: %s", err)
}
return nil
}
// GetLatestVersion gets latest version (git commit hash) from github API
// If running a build from the "master" branch, then the latest full release
// is used, otherwise it uses the release that is tagged with "latest_develop"
// which is the latest pre-release build.
func GetLatestVersion(shortHash bool) (latestVersion string, latestRelease string, err error) {
platform := fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
wantedRelease := stashReleases()[platform]
branch, _, _ := GetVersion()
if branch == "" {
return "", "", fmt.Errorf("Stash doesn't have a version. Version check not supported.")
version, _, _ := GetVersion()
if version == "" {
return "", "", ErrNoVersion
}
client := &http.Client{
Timeout: 3 * time.Second,
// if the version is suffixed with -x-xxxx, then we are running a development build
usePreRelease := false
re := regexp.MustCompile(`-\d+-g\w+$`)
if re.MatchString(version) {
usePreRelease = true
}
req, _ := http.NewRequest("GET", apiReleases, nil)
url := apiReleases
if !usePreRelease {
// just get the latest full release
url += "/latest"
} else {
// get the release tagged with the development tag
url += "/tags/" + developmentTag
}
req.Header.Add("Accept", apiAcceptHeader) // gh api recommendation , send header with api version
response, err := client.Do(req)
input := make([]githubReleasesResponse, 0)
release := githubReleasesResponse{}
err = makeGithubRequest(url, &release)
if err != nil {
return "", "", fmt.Errorf("Github API request failed: %s", err)
} else {
return "", "", err
}
defer response.Body.Close()
if release.Prerelease == usePreRelease {
latestVersion = getReleaseHash(release, shortHash, usePreRelease)
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", "", fmt.Errorf("Github API read response failed: %s", err)
} else {
err = json.Unmarshal(data, &input)
if err != nil {
return "", "", fmt.Errorf("Unmarshalling Github API response failed: %s", err)
} else {
for _, ghApi := range input {
if ghApi.Tag_name == branch {
if shortHash {
latestVersion = ghApi.Target_commitish[0:7] //shorthash is first 7 digits of git commit hash
} else {
latestVersion = ghApi.Target_commitish
}
if wantedRelease != "" {
for _, asset := range ghApi.Assets {
if asset.Name == wantedRelease {
latestRelease = asset.Browser_download_url
break
}
}
}
break
}
if wantedRelease != "" {
for _, asset := range release.Assets {
if asset.Name == wantedRelease {
latestRelease = asset.Browser_download_url
break
}
}
}
if latestVersion == "" {
return "", "", fmt.Errorf("No version found for \"%s\"", branch)
}
}
if latestVersion == "" {
return "", "", fmt.Errorf("No version found for \"%s\"", version)
}
return latestVersion, latestRelease, nil
}
func getReleaseHash(release githubReleasesResponse, shortHash bool, usePreRelease bool) string {
// the /latest API call doesn't return the hash in target_commitish
// also add sanity check in case Target_commitish is not 40 characters
if !usePreRelease || len(release.Target_commitish) != 40 {
return getShaFromTags(shortHash, release.Tag_name)
}
if shortHash {
return release.Target_commitish[0:7] //shorthash is first 7 digits of git commit hash
}
return release.Target_commitish
}
func printLatestVersion() {
@@ -175,5 +216,32 @@ func printLatestVersion() {
logger.Infof("New version: (%s) available.", latest)
}
}
}
// get sha from the github api tags endpoint
// returns the sha1 hash/shorthash or "" if something's wrong
func getShaFromTags(shortHash bool, name string) string {
url := apiTags
tags := []githubTagResponse{}
err := makeGithubRequest(url, &tags)
if err != nil {
logger.Errorf("Github Tags Api %v", err)
return ""
}
for _, tag := range tags {
if tag.Name == name {
if len(tag.Commit.Sha) != 40 {
return ""
}
if shortHash {
return tag.Commit.Sha[0:7] //shorthash is first 7 digits of git commit hash
}
return tag.Commit.Sha
}
}
return ""
}

View File

@@ -9,4 +9,6 @@ const (
performerKey key = 1
sceneKey key = 2
studioKey key = 3
movieKey key = 4
ContextUser key = 5
)

View File

@@ -2,18 +2,31 @@ package api
import (
"math/rand"
"strings"
"github.com/gobuffalo/packr/v2"
)
var performerBox *packr.Box
var performerBoxMale *packr.Box
func initialiseImages() {
performerBox = packr.New("Performer Box", "../../static/performer")
performerBoxMale = packr.New("Male Performer Box", "../../static/performer_male")
}
func getRandomPerformerImage() ([]byte, error) {
imageFiles := performerBox.List()
func getRandomPerformerImage(gender string) ([]byte, error) {
var box *packr.Box
switch strings.ToUpper(gender) {
case "FEMALE":
box = performerBox
case "MALE":
box = performerBoxMale
default:
box = performerBox
}
imageFiles := box.List()
index := rand.Intn(len(imageFiles))
return performerBox.Find(imageFiles[index])
return box.Find(imageFiles[index])
}

92
pkg/api/migrate.go Normal file
View File

@@ -0,0 +1,92 @@
package api
import (
"fmt"
"html/template"
"net/http"
"os"
"github.com/stashapp/stash/pkg/database"
"github.com/stashapp/stash/pkg/logger"
)
type migrateData struct {
ExistingVersion uint
MigrateVersion uint
BackupPath string
}
func getMigrateData() migrateData {
return migrateData{
ExistingVersion: database.Version(),
MigrateVersion: database.AppSchemaVersion(),
BackupPath: database.DatabaseBackupPath(),
}
}
func getMigrateHandler(w http.ResponseWriter, r *http.Request) {
if !database.NeedsMigration() {
http.Redirect(w, r, "/", 301)
return
}
data, _ := setupUIBox.Find("migrate.html")
templ, err := template.New("Migrate").Parse(string(data))
if err != nil {
http.Error(w, fmt.Sprintf("error: %s", err), 500)
return
}
err = templ.Execute(w, getMigrateData())
if err != nil {
http.Error(w, fmt.Sprintf("error: %s", err), 500)
}
}
func doMigrateHandler(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
http.Error(w, fmt.Sprintf("error: %s", err), 500)
}
formBackupPath := r.Form.Get("backuppath")
// always backup so that we can roll back to the previous version if
// migration fails
backupPath := formBackupPath
if formBackupPath == "" {
backupPath = database.DatabaseBackupPath()
}
// perform database backup
if err = database.Backup(backupPath); err != nil {
http.Error(w, fmt.Sprintf("error backing up database: %s", err), 500)
return
}
err = database.RunMigrations()
if err != nil {
errStr := fmt.Sprintf("error performing migration: %s", err)
// roll back to the backed up version
restoreErr := database.RestoreFromBackup(backupPath)
if restoreErr != nil {
errStr = fmt.Sprintf("ERROR: unable to restore database from backup after migration failure: %s\n%s", restoreErr.Error(), errStr)
} else {
errStr = "An error occurred migrating the database to the latest schema version. The backup database file was automatically renamed to restore the database.\n" + errStr
}
http.Error(w, errStr, 500)
return
}
// if no backup path was provided, then delete the created backup
if formBackupPath == "" {
err = os.Remove(backupPath)
if err != nil {
logger.Warnf("error removing unwanted database backup (%s): %s", backupPath, err.Error())
}
}
http.Redirect(w, r, "/", 301)
}

View File

@@ -33,6 +33,9 @@ func (r *Resolver) SceneMarker() models.SceneMarkerResolver {
func (r *Resolver) Studio() models.StudioResolver {
return &studioResolver{r}
}
func (r *Resolver) Movie() models.MovieResolver {
return &movieResolver{r}
}
func (r *Resolver) Subscription() models.SubscriptionResolver {
return &subscriptionResolver{r}
}
@@ -49,6 +52,7 @@ type performerResolver struct{ *Resolver }
type sceneResolver struct{ *Resolver }
type sceneMarkerResolver struct{ *Resolver }
type studioResolver struct{ *Resolver }
type movieResolver struct{ *Resolver }
type tagResolver struct{ *Resolver }
func (r *queryResolver) MarkerWall(ctx context.Context, q *string) ([]*models.SceneMarker, error) {
@@ -89,19 +93,24 @@ func (r *queryResolver) ValidGalleriesForScene(ctx context.Context, scene_id *st
func (r *queryResolver) Stats(ctx context.Context) (*models.StatsResultType, error) {
scenesQB := models.NewSceneQueryBuilder()
scenesCount, _ := scenesQB.Count()
scenesSizeCount, _ := scenesQB.SizeCount()
galleryQB := models.NewGalleryQueryBuilder()
galleryCount, _ := galleryQB.Count()
performersQB := models.NewPerformerQueryBuilder()
performersCount, _ := performersQB.Count()
studiosQB := models.NewStudioQueryBuilder()
studiosCount, _ := studiosQB.Count()
moviesQB := models.NewMovieQueryBuilder()
moviesCount, _ := moviesQB.Count()
tagsQB := models.NewTagQueryBuilder()
tagsCount, _ := tagsQB.Count()
return &models.StatsResultType{
SceneCount: scenesCount,
SceneSizeCount: scenesSizeCount,
GalleryCount: galleryCount,
PerformerCount: performersCount,
StudioCount: studiosCount,
MovieCount: moviesCount,
TagCount: tagsCount,
}, nil
}

View File

@@ -0,0 +1,95 @@
package api
import (
"context"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
func (r *movieResolver) Name(ctx context.Context, obj *models.Movie) (string, error) {
if obj.Name.Valid {
return obj.Name.String, nil
}
return "", nil
}
func (r *movieResolver) URL(ctx context.Context, obj *models.Movie) (*string, error) {
if obj.URL.Valid {
return &obj.URL.String, nil
}
return nil, nil
}
func (r *movieResolver) Aliases(ctx context.Context, obj *models.Movie) (*string, error) {
if obj.Aliases.Valid {
return &obj.Aliases.String, nil
}
return nil, nil
}
func (r *movieResolver) Duration(ctx context.Context, obj *models.Movie) (*int, error) {
if obj.Duration.Valid {
rating := int(obj.Duration.Int64)
return &rating, nil
}
return nil, nil
}
func (r *movieResolver) Date(ctx context.Context, obj *models.Movie) (*string, error) {
if obj.Date.Valid {
result := utils.GetYMDFromDatabaseDate(obj.Date.String)
return &result, nil
}
return nil, nil
}
func (r *movieResolver) Rating(ctx context.Context, obj *models.Movie) (*int, error) {
if obj.Rating.Valid {
rating := int(obj.Rating.Int64)
return &rating, nil
}
return nil, nil
}
func (r *movieResolver) Studio(ctx context.Context, obj *models.Movie) (*models.Studio, error) {
qb := models.NewStudioQueryBuilder()
if obj.StudioID.Valid {
return qb.Find(int(obj.StudioID.Int64), nil)
}
return nil, nil
}
func (r *movieResolver) Director(ctx context.Context, obj *models.Movie) (*string, error) {
if obj.Director.Valid {
return &obj.Director.String, nil
}
return nil, nil
}
func (r *movieResolver) Synopsis(ctx context.Context, obj *models.Movie) (*string, error) {
if obj.Synopsis.Valid {
return &obj.Synopsis.String, nil
}
return nil, nil
}
func (r *movieResolver) FrontImagePath(ctx context.Context, obj *models.Movie) (*string, error) {
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
frontimagePath := urlbuilders.NewMovieURLBuilder(baseURL, obj.ID).GetMovieFrontImageURL()
return &frontimagePath, nil
}
func (r *movieResolver) BackImagePath(ctx context.Context, obj *models.Movie) (*string, error) {
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
backimagePath := urlbuilders.NewMovieURLBuilder(baseURL, obj.ID).GetMovieBackImageURL()
return &backimagePath, nil
}
func (r *movieResolver) SceneCount(ctx context.Context, obj *models.Movie) (*int, error) {
qb := models.NewSceneQueryBuilder()
res, err := qb.CountByMovieID(obj.ID)
return &res, err
}

View File

@@ -2,6 +2,7 @@ package api
import (
"context"
"github.com/stashapp/stash/pkg/api/urlbuilders"
"github.com/stashapp/stash/pkg/models"
)
@@ -20,6 +21,19 @@ func (r *performerResolver) URL(ctx context.Context, obj *models.Performer) (*st
return nil, nil
}
func (r *performerResolver) Gender(ctx context.Context, obj *models.Performer) (*models.GenderEnum, error) {
var ret models.GenderEnum
if obj.Gender.Valid {
ret = models.GenderEnum(obj.Gender.String)
if ret.IsValid() {
return &ret, nil
}
}
return nil, nil
}
func (r *performerResolver) Twitter(ctx context.Context, obj *models.Performer) (*string, error) {
if obj.Twitter.Valid {
return &obj.Twitter.String, nil

View File

@@ -82,7 +82,9 @@ func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (*models.S
}
func (r *sceneResolver) IsStreamable(ctx context.Context, obj *models.Scene) (bool, error) {
return manager.IsStreamable(obj)
// ignore error
ret, _ := manager.IsStreamable(obj)
return ret, nil
}
func (r *sceneResolver) SceneMarkers(ctx context.Context, obj *models.Scene) ([]*models.SceneMarker, error) {
@@ -100,6 +102,38 @@ func (r *sceneResolver) Studio(ctx context.Context, obj *models.Scene) (*models.
return qb.FindBySceneID(obj.ID)
}
func (r *sceneResolver) Movies(ctx context.Context, obj *models.Scene) ([]*models.SceneMovie, error) {
joinQB := models.NewJoinsQueryBuilder()
qb := models.NewMovieQueryBuilder()
sceneMovies, err := joinQB.GetSceneMovies(obj.ID, nil)
if err != nil {
return nil, err
}
var ret []*models.SceneMovie
for _, sm := range sceneMovies {
movie, err := qb.Find(sm.MovieID, nil)
if err != nil {
return nil, err
}
sceneIdx := sm.SceneIndex
sceneMovie := &models.SceneMovie{
Movie: movie,
}
if sceneIdx.Valid {
var idx int
idx = int(sceneIdx.Int64)
sceneMovie.SceneIndex = &idx
}
ret = append(ret, sceneMovie)
}
return ret, nil
}
func (r *sceneResolver) Tags(ctx context.Context, obj *models.Scene) ([]*models.Tag, error) {
qb := models.NewTagQueryBuilder()
return qb.FindBySceneID(obj.ID, nil)

View File

@@ -38,6 +38,13 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.Co
config.Set(config.Generated, input.GeneratedPath)
}
if input.CachePath != nil {
if err := utils.EnsureDir(*input.CachePath); err != nil {
return makeConfigGeneralResult(), err
}
config.Set(config.Cache, input.CachePath)
}
if input.MaxTranscodeSize != nil {
config.Set(config.MaxTranscodeSize, input.MaxTranscodeSize.String())
}
@@ -45,6 +52,8 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.Co
if input.MaxStreamingTranscodeSize != nil {
config.Set(config.MaxStreamingTranscodeSize, input.MaxStreamingTranscodeSize.String())
}
config.Set(config.ForceMKV, input.ForceMkv)
config.Set(config.ForceHEVC, input.ForceHevc)
if input.Username != nil {
config.Set(config.Username, input.Username)
@@ -60,6 +69,10 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.Co
}
}
if input.MaxSessionAge != nil {
config.Set(config.MaxSessionAge, *input.MaxSessionAge)
}
if input.LogFile != nil {
config.Set(config.LogFile, input.LogFile)
}
@@ -76,6 +89,10 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.Co
config.Set(config.Exclude, input.Excludes)
}
if input.ScraperUserAgent != nil {
config.Set(config.ScraperUserAgent, input.ScraperUserAgent)
}
if err := config.Write(); err != nil {
return makeConfigGeneralResult(), err
}
@@ -94,6 +111,10 @@ func (r *mutationResolver) ConfigureInterface(ctx context.Context, input models.
config.Set(config.WallShowTitle, *input.WallShowTitle)
}
if input.WallPlayback != nil {
config.Set(config.WallPlayback, *input.WallPlayback)
}
if input.MaximumLoopDuration != nil {
config.Set(config.MaximumLoopDuration, *input.MaximumLoopDuration)
}
@@ -106,6 +127,10 @@ func (r *mutationResolver) ConfigureInterface(ctx context.Context, input models.
config.Set(config.ShowStudioAsText, *input.ShowStudioAsText)
}
if input.Language != nil {
config.Set(config.Language, *input.Language)
}
css := ""
if input.CSS != nil {

View File

@@ -0,0 +1,53 @@
package api
import (
"context"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
)
func (r *mutationResolver) MetadataScan(ctx context.Context, input models.ScanMetadataInput) (string, error) {
manager.GetInstance().Scan(input.UseFileMetadata)
return "todo", nil
}
func (r *mutationResolver) MetadataImport(ctx context.Context) (string, error) {
manager.GetInstance().Import()
return "todo", nil
}
func (r *mutationResolver) MetadataExport(ctx context.Context) (string, error) {
manager.GetInstance().Export()
return "todo", nil
}
func (r *mutationResolver) MetadataGenerate(ctx context.Context, input models.GenerateMetadataInput) (string, error) {
manager.GetInstance().Generate(input.Sprites, input.Previews, input.PreviewPreset, input.ImagePreviews, input.Markers, input.Transcodes, input.Thumbnails)
return "todo", nil
}
func (r *mutationResolver) MetadataAutoTag(ctx context.Context, input models.AutoTagMetadataInput) (string, error) {
manager.GetInstance().AutoTag(input.Performers, input.Studios, input.Tags)
return "todo", nil
}
func (r *mutationResolver) MetadataClean(ctx context.Context) (string, error) {
manager.GetInstance().Clean()
return "todo", nil
}
func (r *mutationResolver) JobStatus(ctx context.Context) (*models.MetadataUpdateStatus, error) {
status := manager.GetInstance().Status
ret := models.MetadataUpdateStatus{
Progress: status.Progress,
Status: status.Status.String(),
Message: "",
}
return &ret, nil
}
func (r *mutationResolver) StopJob(ctx context.Context) (bool, error) {
return manager.GetInstance().Status.Stop(), nil
}

View File

@@ -0,0 +1,199 @@
package api
import (
"context"
"database/sql"
"strconv"
"time"
"github.com/stashapp/stash/pkg/database"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
func (r *mutationResolver) MovieCreate(ctx context.Context, input models.MovieCreateInput) (*models.Movie, error) {
// generate checksum from movie name rather than image
checksum := utils.MD5FromString(input.Name)
var frontimageData []byte
var backimageData []byte
var err error
if input.FrontImage == nil {
input.FrontImage = &models.DefaultMovieImage
}
if input.BackImage == nil {
input.BackImage = &models.DefaultMovieImage
}
// Process the base 64 encoded image string
_, frontimageData, err = utils.ProcessBase64Image(*input.FrontImage)
if err != nil {
return nil, err
}
// Process the base 64 encoded image string
_, backimageData, err = utils.ProcessBase64Image(*input.BackImage)
if err != nil {
return nil, err
}
// Populate a new movie from the input
currentTime := time.Now()
newMovie := models.Movie{
BackImage: backimageData,
FrontImage: frontimageData,
Checksum: checksum,
Name: sql.NullString{String: input.Name, Valid: true},
CreatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
}
if input.Aliases != nil {
newMovie.Aliases = sql.NullString{String: *input.Aliases, Valid: true}
}
if input.Duration != nil {
duration := int64(*input.Duration)
newMovie.Duration = sql.NullInt64{Int64: duration, Valid: true}
}
if input.Date != nil {
newMovie.Date = models.SQLiteDate{String: *input.Date, Valid: true}
}
if input.Rating != nil {
rating := int64(*input.Rating)
newMovie.Rating = sql.NullInt64{Int64: rating, Valid: true}
}
if input.StudioID != nil {
studioID, _ := strconv.ParseInt(*input.StudioID, 10, 64)
newMovie.StudioID = sql.NullInt64{Int64: studioID, Valid: true}
}
if input.Director != nil {
newMovie.Director = sql.NullString{String: *input.Director, Valid: true}
}
if input.Synopsis != nil {
newMovie.Synopsis = sql.NullString{String: *input.Synopsis, Valid: true}
}
if input.URL != nil {
newMovie.URL = sql.NullString{String: *input.URL, Valid: true}
}
// Start the transaction and save the movie
tx := database.DB.MustBeginTx(ctx, nil)
qb := models.NewMovieQueryBuilder()
movie, err := qb.Create(newMovie, tx)
if err != nil {
_ = tx.Rollback()
return nil, err
}
// Commit
if err := tx.Commit(); err != nil {
return nil, err
}
return movie, nil
}
func (r *mutationResolver) MovieUpdate(ctx context.Context, input models.MovieUpdateInput) (*models.Movie, error) {
// Populate movie from the input
movieID, _ := strconv.Atoi(input.ID)
updatedMovie := models.MoviePartial{
ID: movieID,
UpdatedAt: &models.SQLiteTimestamp{Timestamp: time.Now()},
}
if input.FrontImage != nil {
_, frontimageData, err := utils.ProcessBase64Image(*input.FrontImage)
if err != nil {
return nil, err
}
updatedMovie.FrontImage = &frontimageData
}
if input.BackImage != nil {
_, backimageData, err := utils.ProcessBase64Image(*input.BackImage)
if err != nil {
return nil, err
}
updatedMovie.BackImage = &backimageData
}
if input.Name != nil {
// generate checksum from movie name rather than image
checksum := utils.MD5FromString(*input.Name)
updatedMovie.Name = &sql.NullString{String: *input.Name, Valid: true}
updatedMovie.Checksum = &checksum
}
if input.Aliases != nil {
updatedMovie.Aliases = &sql.NullString{String: *input.Aliases, Valid: true}
}
if input.Duration != nil {
duration := int64(*input.Duration)
updatedMovie.Duration = &sql.NullInt64{Int64: duration, Valid: true}
}
if input.Date != nil {
updatedMovie.Date = &models.SQLiteDate{String: *input.Date, Valid: true}
}
if input.Rating != nil {
rating := int64(*input.Rating)
updatedMovie.Rating = &sql.NullInt64{Int64: rating, Valid: true}
} else {
// rating must be nullable
updatedMovie.Rating = &sql.NullInt64{Valid: false}
}
if input.StudioID != nil {
studioID, _ := strconv.ParseInt(*input.StudioID, 10, 64)
updatedMovie.StudioID = &sql.NullInt64{Int64: studioID, Valid: true}
} else {
// studio must be nullable
updatedMovie.StudioID = &sql.NullInt64{Valid: false}
}
if input.Director != nil {
updatedMovie.Director = &sql.NullString{String: *input.Director, Valid: true}
}
if input.Synopsis != nil {
updatedMovie.Synopsis = &sql.NullString{String: *input.Synopsis, Valid: true}
}
if input.URL != nil {
updatedMovie.URL = &sql.NullString{String: *input.URL, Valid: true}
}
// Start the transaction and save the movie
tx := database.DB.MustBeginTx(ctx, nil)
qb := models.NewMovieQueryBuilder()
movie, err := qb.Update(updatedMovie, tx)
if err != nil {
_ = tx.Rollback()
return nil, err
}
// Commit
if err := tx.Commit(); err != nil {
return nil, err
}
return movie, nil
}
func (r *mutationResolver) MovieDestroy(ctx context.Context, input models.MovieDestroyInput) (bool, error) {
qb := models.NewMovieQueryBuilder()
tx := database.DB.MustBeginTx(ctx, nil)
if err := qb.Destroy(input.ID, tx); err != nil {
_ = tx.Rollback()
return false, err
}
if err := tx.Commit(); err != nil {
return false, err
}
return true, nil
}

View File

@@ -19,7 +19,11 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per
var err error
if input.Image == nil {
imageData, err = getRandomPerformerImage()
gender := ""
if input.Gender != nil {
gender = input.Gender.String()
}
imageData, err = getRandomPerformerImage(gender)
} else {
_, imageData, err = utils.ProcessBase64Image(*input.Image)
}
@@ -42,6 +46,9 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per
if input.URL != nil {
newPerformer.URL = sql.NullString{String: *input.URL, Valid: true}
}
if input.Gender != nil {
newPerformer.Gender = sql.NullString{String: input.Gender.String(), Valid: true}
}
if input.Birthdate != nil {
newPerformer.Birthdate = models.SQLiteDate{String: *input.Birthdate, Valid: true}
}
@@ -128,6 +135,9 @@ func (r *mutationResolver) PerformerUpdate(ctx context.Context, input models.Per
if input.URL != nil {
updatedPerformer.URL = sql.NullString{String: *input.URL, Valid: true}
}
if input.Gender != nil {
updatedPerformer.Gender = sql.NullString{String: input.Gender.String(), Valid: true}
}
if input.Birthdate != nil {
updatedPerformer.Birthdate = models.SQLiteDate{String: *input.Birthdate, Valid: true}
}

View File

@@ -147,6 +147,31 @@ func (r *mutationResolver) sceneUpdate(input models.SceneUpdateInput, tx *sqlx.T
return nil, err
}
// Save the movies
var movieJoins []models.MoviesScenes
for _, movie := range input.Movies {
movieID, _ := strconv.Atoi(movie.MovieID)
movieJoin := models.MoviesScenes{
MovieID: movieID,
SceneID: sceneID,
}
if movie.SceneIndex != nil {
movieJoin.SceneIndex = sql.NullInt64{
Int64: int64(*movie.SceneIndex),
Valid: true,
}
}
movieJoins = append(movieJoins, movieJoin)
}
if err := jqb.UpdateMoviesScenes(sceneID, movieJoins, tx); err != nil {
return nil, err
}
// Save the tags
var tagJoins []models.ScenesTags
for _, tid := range input.TagIds {
@@ -163,10 +188,6 @@ func (r *mutationResolver) sceneUpdate(input models.SceneUpdateInput, tx *sqlx.T
// only update the cover image if provided and everything else was successful
if coverImageData != nil {
scene, err := qb.Find(sceneID)
if err != nil {
return nil, err
}
err = manager.SetSceneScreenshot(scene.Checksum, coverImageData)
if err != nil {
@@ -251,9 +272,14 @@ func (r *mutationResolver) BulkSceneUpdate(ctx context.Context, input models.Bul
// Save the performers
if wasFieldIncluded(ctx, "performer_ids") {
performerIDs, err := adjustScenePerformerIDs(tx, sceneID, *input.PerformerIds)
if err != nil {
_ = tx.Rollback()
return nil, err
}
var performerJoins []models.PerformersScenes
for _, pid := range input.PerformerIds {
performerID, _ := strconv.Atoi(pid)
for _, performerID := range performerIDs {
performerJoin := models.PerformersScenes{
PerformerID: performerID,
SceneID: sceneID,
@@ -268,9 +294,14 @@ func (r *mutationResolver) BulkSceneUpdate(ctx context.Context, input models.Bul
// Save the tags
if wasFieldIncluded(ctx, "tag_ids") {
tagIDs, err := adjustSceneTagIDs(tx, sceneID, *input.TagIds)
if err != nil {
_ = tx.Rollback()
return nil, err
}
var tagJoins []models.ScenesTags
for _, tid := range input.TagIds {
tagID, _ := strconv.Atoi(tid)
for _, tagID := range tagIDs {
tagJoin := models.ScenesTags{
SceneID: sceneID,
TagID: tagID,
@@ -292,6 +323,72 @@ func (r *mutationResolver) BulkSceneUpdate(ctx context.Context, input models.Bul
return ret, nil
}
func adjustIDs(existingIDs []int, updateIDs models.BulkUpdateIds) []int {
for _, idStr := range updateIDs.Ids {
id, _ := strconv.Atoi(idStr)
// look for the id in the list
foundExisting := false
for idx, existingID := range existingIDs {
if existingID == id {
if updateIDs.Mode == models.BulkUpdateIDModeRemove {
// remove from the list
existingIDs = append(existingIDs[:idx], existingIDs[idx+1:]...)
}
foundExisting = true
break
}
}
if !foundExisting && updateIDs.Mode != models.BulkUpdateIDModeRemove {
existingIDs = append(existingIDs, id)
}
}
return existingIDs
}
func adjustScenePerformerIDs(tx *sqlx.Tx, sceneID int, ids models.BulkUpdateIds) ([]int, error) {
var ret []int
jqb := models.NewJoinsQueryBuilder()
if ids.Mode == models.BulkUpdateIDModeAdd || ids.Mode == models.BulkUpdateIDModeRemove {
// adding to the joins
performerJoins, err := jqb.GetScenePerformers(sceneID, tx)
if err != nil {
return nil, err
}
for _, join := range performerJoins {
ret = append(ret, join.PerformerID)
}
}
return adjustIDs(ret, ids), nil
}
func adjustSceneTagIDs(tx *sqlx.Tx, sceneID int, ids models.BulkUpdateIds) ([]int, error) {
var ret []int
jqb := models.NewJoinsQueryBuilder()
if ids.Mode == models.BulkUpdateIDModeAdd || ids.Mode == models.BulkUpdateIDModeRemove {
// adding to the joins
tagJoins, err := jqb.GetSceneTags(sceneID, tx)
if err != nil {
return nil, err
}
for _, join := range tagJoins {
ret = append(ret, join.TagID)
}
}
return adjustIDs(ret, ids), nil
}
func (r *mutationResolver) SceneDestroy(ctx context.Context, input models.SceneDestroyInput) (bool, error) {
qb := models.NewSceneQueryBuilder()
tx := database.DB.MustBeginTx(ctx, nil)
@@ -360,6 +457,14 @@ func (r *mutationResolver) SceneMarkerUpdate(ctx context.Context, input models.S
func (r *mutationResolver) SceneMarkerDestroy(ctx context.Context, id string) (bool, error) {
qb := models.NewSceneMarkerQueryBuilder()
tx := database.DB.MustBeginTx(ctx, nil)
markerID, _ := strconv.Atoi(id)
marker, err := qb.Find(markerID)
if err != nil {
return false, err
}
if err := qb.Destroy(id, tx); err != nil {
_ = tx.Rollback()
return false, err
@@ -367,6 +472,16 @@ func (r *mutationResolver) SceneMarkerDestroy(ctx context.Context, id string) (b
if err := tx.Commit(); err != nil {
return false, err
}
// delete the preview for the marker
sqb := models.NewSceneQueryBuilder()
scene, _ := sqb.Find(int(marker.SceneID.Int64))
if scene != nil {
seconds := int(marker.Seconds)
manager.DeleteSceneMarkerFiles(scene, seconds)
}
return true, nil
}
@@ -376,13 +491,18 @@ func changeMarker(ctx context.Context, changeType int, changedMarker models.Scen
qb := models.NewSceneMarkerQueryBuilder()
jqb := models.NewJoinsQueryBuilder()
var existingMarker *models.SceneMarker
var sceneMarker *models.SceneMarker
var err error
switch changeType {
case create:
sceneMarker, err = qb.Create(changedMarker, tx)
case update:
sceneMarker, err = qb.Update(changedMarker, tx)
// check to see if timestamp was changed
existingMarker, err = qb.Find(changedMarker.ID)
if err == nil {
sceneMarker, err = qb.Update(changedMarker, tx)
}
}
if err != nil {
_ = tx.Rollback()
@@ -420,6 +540,18 @@ func changeMarker(ctx context.Context, changeType int, changedMarker models.Scen
return nil, err
}
// remove the marker preview if the timestamp was changed
if existingMarker != nil && existingMarker.Seconds != changedMarker.Seconds {
sqb := models.NewSceneQueryBuilder()
scene, _ := sqb.Find(int(existingMarker.SceneID.Int64))
if scene != nil {
seconds := int(existingMarker.Seconds)
manager.DeleteSceneMarkerFiles(scene, seconds)
}
}
return sceneMarker, nil
}
@@ -482,3 +614,13 @@ func (r *mutationResolver) SceneResetO(ctx context.Context, id string) (int, err
return newVal, nil
}
func (r *mutationResolver) SceneGenerateScreenshot(ctx context.Context, id string, at *float64) (string, error) {
if at != nil {
manager.GetInstance().GenerateScreenshot(id, *at)
} else {
manager.GetInstance().GenerateDefaultScreenshot(id)
}
return "todo", nil
}

View File

@@ -12,12 +12,18 @@ func (r *queryResolver) Configuration(ctx context.Context) (*models.ConfigResult
return makeConfigResult(), nil
}
func (r *queryResolver) Directories(ctx context.Context, path *string) ([]string, error) {
func (r *queryResolver) Directory(ctx context.Context, path *string) (*models.Directory, error) {
var dirPath = ""
if path != nil {
dirPath = *path
}
return utils.ListDir(dirPath), nil
currentDir := utils.GetDir(dirPath)
return &models.Directory{
Path: currentDir,
Parent: utils.GetParent(currentDir),
Directories: utils.ListDir(currentDir),
}, nil
}
func makeConfigResult() *models.ConfigResult {
@@ -33,38 +39,49 @@ func makeConfigGeneralResult() *models.ConfigGeneralResult {
maxTranscodeSize := config.GetMaxTranscodeSize()
maxStreamingTranscodeSize := config.GetMaxStreamingTranscodeSize()
scraperUserAgent := config.GetScraperUserAgent()
return &models.ConfigGeneralResult{
Stashes: config.GetStashPaths(),
DatabasePath: config.GetDatabasePath(),
GeneratedPath: config.GetGeneratedPath(),
CachePath: config.GetCachePath(),
MaxTranscodeSize: &maxTranscodeSize,
MaxStreamingTranscodeSize: &maxStreamingTranscodeSize,
ForceMkv: config.GetForceMKV(),
ForceHevc: config.GetForceHEVC(),
Username: config.GetUsername(),
Password: config.GetPasswordHash(),
MaxSessionAge: config.GetMaxSessionAge(),
LogFile: &logFile,
LogOut: config.GetLogOut(),
LogLevel: config.GetLogLevel(),
LogAccess: config.GetLogAccess(),
Excludes: config.GetExcludes(),
ScraperUserAgent: &scraperUserAgent,
}
}
func makeConfigInterfaceResult() *models.ConfigInterfaceResult {
soundOnPreview := config.GetSoundOnPreview()
wallShowTitle := config.GetWallShowTitle()
wallPlayback := config.GetWallPlayback()
maximumLoopDuration := config.GetMaximumLoopDuration()
autostartVideo := config.GetAutostartVideo()
showStudioAsText := config.GetShowStudioAsText()
css := config.GetCSS()
cssEnabled := config.GetCSSEnabled()
language := config.GetLanguage()
return &models.ConfigInterfaceResult{
SoundOnPreview: &soundOnPreview,
WallShowTitle: &wallShowTitle,
WallPlayback: &wallPlayback,
MaximumLoopDuration: &maximumLoopDuration,
AutostartVideo: &autostartVideo,
ShowStudioAsText: &showStudioAsText,
CSS: &css,
CSSEnabled: &cssEnabled,
Language: &language,
}
}

View File

@@ -0,0 +1,33 @@
package api
import (
"context"
"strconv"
"github.com/stashapp/stash/pkg/models"
)
func (r *queryResolver) FindMovie(ctx context.Context, id string) (*models.Movie, error) {
qb := models.NewMovieQueryBuilder()
idInt, _ := strconv.Atoi(id)
return qb.Find(idInt, nil)
}
func (r *queryResolver) FindMovies(ctx context.Context, movieFilter *models.MovieFilterType, filter *models.FindFilterType) (*models.FindMoviesResultType, error) {
qb := models.NewMovieQueryBuilder()
movies, total := qb.Query(movieFilter, filter)
return &models.FindMoviesResultType{
Count: total,
Movies: movies,
}, nil
}
func (r *queryResolver) AllMovies(ctx context.Context) ([]*models.Movie, error) {
qb := models.NewMovieQueryBuilder()
return qb.All()
}
func (r *queryResolver) AllMoviesSlim(ctx context.Context) ([]*models.Movie, error) {
qb := models.NewMovieQueryBuilder()
return qb.AllSlim()
}

View File

@@ -25,3 +25,8 @@ func (r *queryResolver) AllPerformers(ctx context.Context) ([]*models.Performer,
qb := models.NewPerformerQueryBuilder()
return qb.All()
}
func (r *queryResolver) AllPerformersSlim(ctx context.Context) ([]*models.Performer, error) {
qb := models.NewPerformerQueryBuilder()
return qb.AllSlim()
}

View File

@@ -25,3 +25,8 @@ func (r *queryResolver) AllStudios(ctx context.Context) ([]*models.Studio, error
qb := models.NewStudioQueryBuilder()
return qb.All()
}
func (r *queryResolver) AllStudiosSlim(ctx context.Context) ([]*models.Studio, error) {
qb := models.NewStudioQueryBuilder()
return qb.AllSlim()
}

View File

@@ -16,3 +16,8 @@ func (r *queryResolver) AllTags(ctx context.Context) ([]*models.Tag, error) {
qb := models.NewTagQueryBuilder()
return qb.All()
}
func (r *queryResolver) AllTagsSlim(ctx context.Context) ([]*models.Tag, error) {
qb := models.NewTagQueryBuilder()
return qb.AllSlim()
}

View File

@@ -7,36 +7,6 @@ import (
"github.com/stashapp/stash/pkg/models"
)
func (r *queryResolver) MetadataScan(ctx context.Context, input models.ScanMetadataInput) (string, error) {
manager.GetInstance().Scan(input.UseFileMetadata)
return "todo", nil
}
func (r *queryResolver) MetadataImport(ctx context.Context) (string, error) {
manager.GetInstance().Import()
return "todo", nil
}
func (r *queryResolver) MetadataExport(ctx context.Context) (string, error) {
manager.GetInstance().Export()
return "todo", nil
}
func (r *queryResolver) MetadataGenerate(ctx context.Context, input models.GenerateMetadataInput) (string, error) {
manager.GetInstance().Generate(input.Sprites, input.Previews, input.Markers, input.Transcodes)
return "todo", nil
}
func (r *queryResolver) MetadataAutoTag(ctx context.Context, input models.AutoTagMetadataInput) (string, error) {
manager.GetInstance().AutoTag(input.Performers, input.Studios, input.Tags)
return "todo", nil
}
func (r *queryResolver) MetadataClean(ctx context.Context) (string, error) {
manager.GetInstance().Clean()
return "todo", nil
}
func (r *queryResolver) JobStatus(ctx context.Context) (*models.MetadataUpdateStatus, error) {
status := manager.GetInstance().Status
ret := models.MetadataUpdateStatus{
@@ -47,7 +17,3 @@ func (r *queryResolver) JobStatus(ctx context.Context) (*models.MetadataUpdateSt
return &ret, nil
}
func (r *queryResolver) StopJob(ctx context.Context) (bool, error) {
return manager.GetInstance().Status.Stop(), nil
}

View File

@@ -23,11 +23,15 @@ func (rs galleryRoutes) Routes() chi.Router {
func (rs galleryRoutes) File(w http.ResponseWriter, r *http.Request) {
gallery := r.Context().Value(galleryKey).(*models.Gallery)
if gallery == nil {
http.Error(w, http.StatusText(404), 404)
return
}
fileIndex, _ := strconv.Atoi(chi.URLParam(r, "fileIndex"))
thumb := r.URL.Query().Get("thumb")
w.Header().Add("Cache-Control", "max-age=604800000") // 1 Week
if thumb == "true" {
_, _ = w.Write(gallery.GetThumbnail(fileIndex, 200))
_, _ = w.Write(cacheGthumb(gallery, fileIndex, models.DefaultGthumbWidth))
} else if thumb == "" {
_, _ = w.Write(gallery.GetImage(fileIndex))
} else {
@@ -36,7 +40,7 @@ func (rs galleryRoutes) File(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(400), 400)
return
}
_, _ = w.Write(gallery.GetThumbnail(fileIndex, int(width)))
_, _ = w.Write(cacheGthumb(gallery, fileIndex, int(width)))
}
}

54
pkg/api/routes_movie.go Normal file
View File

@@ -0,0 +1,54 @@
package api
import (
"context"
"net/http"
"strconv"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/models"
)
type movieRoutes struct{}
func (rs movieRoutes) Routes() chi.Router {
r := chi.NewRouter()
r.Route("/{movieId}", func(r chi.Router) {
r.Use(MovieCtx)
r.Get("/frontimage", rs.FrontImage)
r.Get("/backimage", rs.BackImage)
})
return r
}
func (rs movieRoutes) FrontImage(w http.ResponseWriter, r *http.Request) {
movie := r.Context().Value(movieKey).(*models.Movie)
_, _ = w.Write(movie.FrontImage)
}
func (rs movieRoutes) BackImage(w http.ResponseWriter, r *http.Request) {
movie := r.Context().Value(movieKey).(*models.Movie)
_, _ = w.Write(movie.BackImage)
}
func MovieCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
movieID, err := strconv.Atoi(chi.URLParam(r, "movieId"))
if err != nil {
http.Error(w, http.StatusText(404), 404)
return
}
qb := models.NewMovieQueryBuilder()
movie, err := qb.Find(movieID, nil)
if err != nil {
http.Error(w, http.StatusText(404), 404)
return
}
ctx := context.WithValue(r.Context(), movieKey, movie)
next.ServeHTTP(w, r.WithContext(ctx))
})
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"io"
"net/http"
"os"
"strconv"
"strings"
@@ -42,13 +43,32 @@ func (rs sceneRoutes) Routes() chi.Router {
// region Handlers
func (rs sceneRoutes) Stream(w http.ResponseWriter, r *http.Request) {
scene := r.Context().Value(sceneKey).(*models.Scene)
container := ""
if scene.Format.Valid {
container = scene.Format.String
} else { // container isn't in the DB
// shouldn't happen, fallback to ffprobe
tmpVideoFile, err := ffmpeg.NewVideoFile(manager.GetInstance().FFProbePath, scene.Path)
if err != nil {
logger.Errorf("[transcode] error reading video file: %s", err.Error())
return
}
container = string(ffmpeg.MatchContainer(tmpVideoFile.Container, scene.Path))
}
// detect if not a streamable file and try to transcode it instead
filepath := manager.GetInstance().Paths.Scene.GetStreamPath(scene.Path, scene.Checksum)
videoCodec := scene.VideoCodec.String
audioCodec := ffmpeg.MissingUnsupported
if scene.AudioCodec.Valid {
audioCodec = ffmpeg.AudioCodec(scene.AudioCodec.String)
}
hasTranscode, _ := manager.HasTranscode(scene)
if ffmpeg.IsValidCodec(videoCodec) || hasTranscode {
if ffmpeg.IsValidCodec(videoCodec) && ffmpeg.IsValidCombo(videoCodec, ffmpeg.Container(container)) && ffmpeg.IsValidAudioForContainer(audioCodec, ffmpeg.Container(container)) || hasTranscode {
manager.RegisterStream(filepath, &w)
http.ServeFile(w, r, filepath)
manager.WaitAndDeregisterStream(filepath, &w, r)
@@ -69,16 +89,50 @@ func (rs sceneRoutes) Stream(w http.ResponseWriter, r *http.Request) {
encoder := ffmpeg.NewEncoder(manager.GetInstance().FFMPEGPath)
stream, process, err := encoder.StreamTranscode(*videoFile, startTime, config.GetMaxStreamingTranscodeSize())
var stream io.ReadCloser
var process *os.Process
mimeType := ffmpeg.MimeWebm
if audioCodec == ffmpeg.MissingUnsupported {
//ffmpeg fails if it trys to transcode a non supported audio codec
stream, process, err = encoder.StreamTranscodeVideo(*videoFile, startTime, config.GetMaxStreamingTranscodeSize())
} else {
copyVideo := false // try to be smart if the video to be transcoded is in a Matroska container
// mp4 has always supported audio so it doesn't need to be checked
// while mpeg_ts has seeking issues if we don't reencode the video
if config.GetForceMKV() { // If MKV is forced as supported and video codec is also supported then only transcode audio
if ffmpeg.Container(container) == ffmpeg.Matroska {
switch videoCodec {
case ffmpeg.H264, ffmpeg.Vp9, ffmpeg.Vp8:
copyVideo = true
case ffmpeg.Hevc:
if config.GetForceHEVC() {
copyVideo = true
}
}
}
}
if copyVideo { // copy video stream instead of transcoding it
stream, process, err = encoder.StreamMkvTranscodeAudio(*videoFile, startTime, config.GetMaxStreamingTranscodeSize())
mimeType = ffmpeg.MimeMkv
} else {
stream, process, err = encoder.StreamTranscode(*videoFile, startTime, config.GetMaxStreamingTranscodeSize())
}
}
if err != nil {
logger.Errorf("[stream] error transcoding video file: %s", err.Error())
return
}
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "video/webm")
w.Header().Set("Content-Type", mimeType)
logger.Info("[stream] transcoding video file")
logger.Infof("[stream] transcoding video file to %s", mimeType)
// handle if client closes the connection
notify := r.Context().Done()

View File

@@ -2,10 +2,13 @@ package api
import (
"context"
"crypto/md5"
"fmt"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/models"
"net/http"
"strconv"
"strings"
)
type studioRoutes struct{}
@@ -23,6 +26,21 @@ func (rs studioRoutes) Routes() chi.Router {
func (rs studioRoutes) Image(w http.ResponseWriter, r *http.Request) {
studio := r.Context().Value(studioKey).(*models.Studio)
etag := fmt.Sprintf("%x", md5.Sum(studio.Image))
if match := r.Header.Get("If-None-Match"); match != "" {
if strings.Contains(match, etag) {
w.WriteHeader(http.StatusNotModified)
return
}
}
contentType := http.DetectContentType(studio.Image)
if contentType == "text/xml; charset=utf-8" || contentType == "text/plain; charset=utf-8" {
contentType = "image/svg+xml"
}
w.Header().Set("Content-Type", contentType)
w.Header().Add("Etag", etag)
_, _ = w.Write(studio.Image)
}

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
@@ -20,6 +21,7 @@ import (
"github.com/gobuffalo/packr/v2"
"github.com/gorilla/websocket"
"github.com/rs/cors"
"github.com/stashapp/stash/pkg/database"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/manager/config"
@@ -28,46 +30,81 @@ import (
"github.com/stashapp/stash/pkg/utils"
)
var version string = ""
var buildstamp string = ""
var githash string = ""
var version string
var buildstamp string
var githash string
var uiBox *packr.Box
//var legacyUiBox *packr.Box
var setupUIBox *packr.Box
var loginUIBox *packr.Box
func allowUnauthenticated(r *http.Request) bool {
return strings.HasPrefix(r.URL.Path, "/login") || r.URL.Path == "/css"
}
func authenticateHandler() func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// only do this if credentials have been configured
if !config.HasCredentials() {
next.ServeHTTP(w, r)
ctx := r.Context()
// translate api key into current user, if present
userID := ""
var err error
// handle session
userID, err = getSessionUserID(w, r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
authUser, authPW, ok := r.BasicAuth()
// handle redirect if no user and user is required
if userID == "" && config.HasCredentials() && !allowUnauthenticated(r) {
// always allow
if !ok || !config.ValidateCredentials(authUser, authPW) {
unauthorized(w)
// if we don't have a userID, then redirect
// if graphql was requested, we just return a forbidden error
if r.URL.Path == "/graphql" {
w.Header().Add("WWW-Authenticate", `FormBased`)
w.WriteHeader(http.StatusUnauthorized)
return
}
// otherwise redirect to the login page
u := url.URL{
Path: "/login",
}
q := u.Query()
q.Set(returnURLParam, r.URL.Path)
u.RawQuery = q.Encode()
http.Redirect(w, r, u.String(), http.StatusFound)
return
}
ctx = context.WithValue(ctx, ContextUser, userID)
r = r.WithContext(ctx)
next.ServeHTTP(w, r)
})
}
}
func unauthorized(w http.ResponseWriter) {
w.Header().Add("WWW-Authenticate", `Basic realm=\"Stash\"`)
w.WriteHeader(http.StatusUnauthorized)
}
const setupEndPoint = "/setup"
const migrateEndPoint = "/migrate"
const loginEndPoint = "/login"
func Start() {
uiBox = packr.New("UI Box", "../../ui/v2/build")
uiBox = packr.New("UI Box", "../../ui/v2.5/build")
//legacyUiBox = packr.New("UI Box", "../../ui/v1/dist/stash-frontend")
setupUIBox = packr.New("Setup UI Box", "../../ui/setup")
loginUIBox = packr.New("Login UI Box", "../../ui/login")
initSessionStore()
initialiseImages()
r := chi.NewRouter()
@@ -83,6 +120,7 @@ func Start() {
r.Use(cors.AllowAll().Handler)
r.Use(BaseURLMiddleware)
r.Use(ConfigCheckMiddleware)
r.Use(DatabaseCheckMiddleware)
recoverFunc := handler.RecoverFunc(func(ctx context.Context, err interface{}) error {
logger.Error(err)
@@ -105,12 +143,20 @@ func Start() {
r.Handle("/graphql", gqlHandler)
r.Handle("/playground", handler.Playground("GraphQL playground", "/graphql"))
// session handlers
r.Post(loginEndPoint, handleLogin)
r.Get("/logout", handleLogout)
r.Get(loginEndPoint, getLoginHandler)
r.Mount("/gallery", galleryRoutes{}.Routes())
r.Mount("/performer", performerRoutes{}.Routes())
r.Mount("/scene", sceneRoutes{}.Routes())
r.Mount("/studio", studioRoutes{}.Routes())
r.Mount("/movie", movieRoutes{}.Routes())
r.HandleFunc("/css", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/css")
if !config.GetCSSEnabled() {
return
}
@@ -125,6 +171,10 @@ func Start() {
http.ServeFile(w, r, fn)
})
// Serve the migration UI
r.Get("/migrate", getMigrateHandler)
r.Post("/migrate", doMigrateHandler)
// Serve the setup UI
r.HandleFunc("/setup*", func(w http.ResponseWriter, r *http.Request) {
ext := path.Ext(r.URL.Path)
@@ -136,6 +186,16 @@ func Start() {
http.FileServer(setupUIBox).ServeHTTP(w, r)
}
})
r.HandleFunc("/login*", func(w http.ResponseWriter, r *http.Request) {
ext := path.Ext(r.URL.Path)
if ext == ".html" || ext == "" {
data, _ := loginUIBox.Find("login.html")
_, _ = w.Write(data)
} else {
r.URL.Path = strings.Replace(r.URL.Path, loginEndPoint, "", 1)
http.FileServer(loginUIBox).ServeHTTP(w, r)
}
})
r.Post("/init", func(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
@@ -174,7 +234,8 @@ func Start() {
_ = os.Mkdir(downloads, 0755)
config.Set(config.Stash, stash)
// #536 - set stash as slice of strings
config.Set(config.Stash, []string{stash})
config.Set(config.Generated, generated)
config.Set(config.Metadata, metadata)
config.Set(config.Cache, cache)
@@ -189,6 +250,7 @@ func Start() {
http.Redirect(w, r, "/", 301)
})
startThumbCache()
// Serve the web app
r.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
ext := path.Ext(r.URL.Path)
@@ -296,6 +358,11 @@ func BaseURLMiddleware(next http.Handler) http.Handler {
}
baseURL := scheme + "://" + r.Host
externalHost := config.GetExternalHost()
if externalHost != "" {
baseURL = externalHost
}
r = r.WithContext(context.WithValue(ctx, BaseURLCtxKey, baseURL))
next.ServeHTTP(w, r)
@@ -306,10 +373,27 @@ func BaseURLMiddleware(next http.Handler) http.Handler {
func ConfigCheckMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ext := path.Ext(r.URL.Path)
shouldRedirect := ext == "" && r.Method == "GET" && r.URL.Path != "/init"
shouldRedirect := ext == "" && r.Method == "GET"
if !config.IsValid() && shouldRedirect {
if !strings.HasPrefix(r.URL.Path, "/setup") {
http.Redirect(w, r, "/setup", 301)
// #539 - don't redirect if loading login page
if !strings.HasPrefix(r.URL.Path, setupEndPoint) && !strings.HasPrefix(r.URL.Path, loginEndPoint) {
http.Redirect(w, r, setupEndPoint, 301)
return
}
}
next.ServeHTTP(w, r)
})
}
func DatabaseCheckMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ext := path.Ext(r.URL.Path)
shouldRedirect := ext == "" && r.Method == "GET"
if shouldRedirect && database.NeedsMigration() {
// #451 - don't redirect if loading login page
// #539 - or setup page
if !strings.HasPrefix(r.URL.Path, migrateEndPoint) && !strings.HasPrefix(r.URL.Path, loginEndPoint) && !strings.HasPrefix(r.URL.Path, setupEndPoint) {
http.Redirect(w, r, migrateEndPoint, 301)
return
}
}

127
pkg/api/session.go Normal file
View File

@@ -0,0 +1,127 @@
package api
import (
"fmt"
"html/template"
"net/http"
"github.com/stashapp/stash/pkg/manager/config"
"github.com/gorilla/sessions"
)
const cookieName = "session"
const usernameFormKey = "username"
const passwordFormKey = "password"
const userIDKey = "userID"
const returnURLParam = "returnURL"
var sessionStore = sessions.NewCookieStore(config.GetSessionStoreKey())
type loginTemplateData struct {
URL string
Error string
}
func initSessionStore() {
sessionStore.MaxAge(config.GetMaxSessionAge())
}
func redirectToLogin(w http.ResponseWriter, returnURL string, loginError string) {
data, _ := loginUIBox.Find("login.html")
templ, err := template.New("Login").Parse(string(data))
if err != nil {
http.Error(w, fmt.Sprintf("error: %s", err), http.StatusInternalServerError)
return
}
err = templ.Execute(w, loginTemplateData{URL: returnURL, Error: loginError})
if err != nil {
http.Error(w, fmt.Sprintf("error: %s", err), http.StatusInternalServerError)
}
}
func getLoginHandler(w http.ResponseWriter, r *http.Request) {
if !config.HasCredentials() {
http.Redirect(w, r, "/", http.StatusFound)
return
}
redirectToLogin(w, r.URL.Query().Get(returnURLParam), "")
}
func handleLogin(w http.ResponseWriter, r *http.Request) {
url := r.FormValue(returnURLParam)
if url == "" {
url = "/"
}
// ignore error - we want a new session regardless
newSession, _ := sessionStore.Get(r, cookieName)
username := r.FormValue("username")
password := r.FormValue("password")
// authenticate the user
if !config.ValidateCredentials(username, password) {
// redirect back to the login page with an error
redirectToLogin(w, url, "Username or password is invalid")
return
}
newSession.Values[userIDKey] = username
err := newSession.Save(r, w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, url, http.StatusFound)
}
func handleLogout(w http.ResponseWriter, r *http.Request) {
session, err := sessionStore.Get(r, cookieName)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
delete(session.Values, userIDKey)
session.Options.MaxAge = -1
err = session.Save(r, w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// redirect to the login page if credentials are required
getLoginHandler(w, r)
}
func getSessionUserID(w http.ResponseWriter, r *http.Request) (string, error) {
session, err := sessionStore.Get(r, cookieName)
// ignore errors and treat as an empty user id, so that we handle expired
// cookie
if err != nil {
return "", nil
}
if !session.IsNew {
val := session.Values[userIDKey]
// refresh the cookie
err = session.Save(r, w)
if err != nil {
return "", err
}
ret, _ := val.(string)
return ret, nil
}
return "", nil
}

View File

@@ -0,0 +1,24 @@
package urlbuilders
import "strconv"
type MovieURLBuilder struct {
BaseURL string
MovieID string
}
func NewMovieURLBuilder(baseURL string, movieID int) MovieURLBuilder {
return MovieURLBuilder{
BaseURL: baseURL,
MovieID: strconv.Itoa(movieID),
}
}
func (b MovieURLBuilder) GetMovieFrontImageURL() string {
return b.BaseURL + "/movie/" + b.MovieID + "/frontimage"
}
func (b MovieURLBuilder) GetMovieBackImageURL() string {
return b.BaseURL + "/movie/" + b.MovieID + "/backimage"
}

View File

@@ -5,10 +5,11 @@ import (
"errors"
"fmt"
"os"
"regexp"
"time"
"github.com/gobuffalo/packr/v2"
"github.com/golang-migrate/migrate/v4"
sqlite3mig "github.com/golang-migrate/migrate/v4/database/sqlite3"
"github.com/golang-migrate/migrate/v4/source"
"github.com/jmoiron/sqlx"
sqlite3 "github.com/mattn/go-sqlite3"
@@ -17,26 +18,62 @@ import (
)
var DB *sqlx.DB
var appSchemaVersion uint = 3
var dbPath string
var appSchemaVersion uint = 8
var databaseSchemaVersion uint
const sqlite3Driver = "sqlite3_regexp"
const sqlite3Driver = "sqlite3ex"
func init() {
// register custom driver with regexp function
registerRegexpFunc()
registerCustomDriver()
}
func Initialize(databasePath string) {
runMigrations(databasePath)
dbPath = databasePath
if err := getDatabaseSchemaVersion(); err != nil {
panic(err)
}
if databaseSchemaVersion == 0 {
// new database, just run the migrations
if err := RunMigrations(); err != nil {
panic(err)
}
// RunMigrations calls Initialise. Just return
return
} else {
if databaseSchemaVersion > appSchemaVersion {
panic(fmt.Sprintf("Database schema version %d is incompatible with required schema version %d", databaseSchemaVersion, appSchemaVersion))
}
// if migration is needed, then don't open the connection
if NeedsMigration() {
logger.Warnf("Database schema version %d does not match required schema version %d.", databaseSchemaVersion, appSchemaVersion)
return
}
}
const disableForeignKeys = false
DB = open(databasePath, disableForeignKeys)
}
func open(databasePath string, disableForeignKeys bool) *sqlx.DB {
// https://github.com/mattn/go-sqlite3
conn, err := sqlx.Open(sqlite3Driver, "file:"+databasePath+"?_fk=true")
url := "file:" + databasePath
if !disableForeignKeys {
url += "?_fk=true"
}
conn, err := sqlx.Open(sqlite3Driver, url)
conn.SetMaxOpenConns(25)
conn.SetMaxIdleConns(4)
if err != nil {
logger.Fatalf("db.Open(): %q\n", err)
}
DB = conn
return conn
}
func Reset(databasePath string) error {
@@ -55,45 +92,123 @@ func Reset(databasePath string) error {
return nil
}
// Backup the database
func Backup(backupPath string) error {
db, err := sqlx.Connect(sqlite3Driver, "file:"+dbPath+"?_fk=true")
if err != nil {
return fmt.Errorf("Open database %s failed:%s", dbPath, err)
}
defer db.Close()
_, err = db.Exec(`VACUUM INTO "` + backupPath + `"`)
if err != nil {
return fmt.Errorf("Vacuum failed: %s", err)
}
return nil
}
func RestoreFromBackup(backupPath string) error {
return os.Rename(backupPath, dbPath)
}
// Migrate the database
func runMigrations(databasePath string) {
func NeedsMigration() bool {
return databaseSchemaVersion != appSchemaVersion
}
func AppSchemaVersion() uint {
return appSchemaVersion
}
func DatabaseBackupPath() string {
return fmt.Sprintf("%s.%d.%s", dbPath, databaseSchemaVersion, time.Now().Format("20060102_150405"))
}
func Version() uint {
return databaseSchemaVersion
}
func getMigrate() (*migrate.Migrate, error) {
migrationsBox := packr.New("Migrations Box", "./migrations")
packrSource := &Packr2Source{
Box: migrationsBox,
Migrations: source.NewMigrations(),
}
databasePath = utils.FixWindowsPath(databasePath)
databasePath := utils.FixWindowsPath(dbPath)
s, _ := WithInstance(packrSource)
m, err := migrate.NewWithSourceInstance(
const disableForeignKeys = true
conn := open(databasePath, disableForeignKeys)
driver, err := sqlite3mig.WithInstance(conn.DB, &sqlite3mig.Config{})
if err != nil {
return nil, err
}
// use sqlite3Driver so that migration has access to durationToTinyInt
return migrate.NewWithInstance(
"packr2",
s,
fmt.Sprintf("sqlite3://%s", "file:"+databasePath),
databasePath,
driver,
)
}
func getDatabaseSchemaVersion() error {
m, err := getMigrate()
if err != nil {
return err
}
databaseSchemaVersion, _, _ = m.Version()
m.Close()
return nil
}
// Migrate the database
func RunMigrations() error {
m, err := getMigrate()
if err != nil {
panic(err.Error())
}
databaseSchemaVersion, _, _ := m.Version()
databaseSchemaVersion, _, _ = m.Version()
stepNumber := appSchemaVersion - databaseSchemaVersion
if stepNumber != 0 {
err = m.Steps(int(stepNumber))
if err != nil {
panic(err.Error())
// migration failed
m.Close()
return err
}
}
m.Close()
// re-initialise the database
Initialize(dbPath)
return nil
}
func registerRegexpFunc() {
regexFn := func(re, s string) (bool, error) {
return regexp.MatchString(re, s)
}
func registerCustomDriver() {
sql.Register(sqlite3Driver,
&sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
return conn.RegisterFunc("regexp", regexFn, true)
funcs := map[string]interface{}{
"regexp": regexFn,
"durationToTinyInt": durationToTinyIntFn,
}
for name, fn := range funcs {
if err := conn.RegisterFunc(name, fn, true); err != nil {
return fmt.Errorf("Error registering function %s: %s", name, err.Error())
}
}
return nil
},
})
},
)
}

37
pkg/database/functions.go Normal file
View File

@@ -0,0 +1,37 @@
package database
import (
"regexp"
"strconv"
"strings"
)
func regexFn(re, s string) (bool, error) {
return regexp.MatchString(re, s)
}
func durationToTinyIntFn(str string) (int64, error) {
splits := strings.Split(str, ":")
if len(splits) > 3 {
return 0, nil
}
seconds := 0
factor := 1
for len(splits) > 0 {
// pop the last split
var thisSplit string
thisSplit, splits = splits[len(splits)-1], splits[:len(splits)-1]
thisInt, err := strconv.Atoi(thisSplit)
if err != nil {
return 0, nil
}
seconds += factor * thisInt
factor *= 60
}
return int64(seconds), nil
}

View File

@@ -0,0 +1,32 @@
CREATE TABLE `movies` (
`id` integer not null primary key autoincrement,
`name` varchar(255),
`aliases` varchar(255),
`duration` varchar(6),
`date` date,
`rating` varchar(1),
`director` varchar(255),
`synopsis` text,
`front_image` blob not null,
`back_image` blob,
`checksum` varchar(255) not null,
`url` varchar(255),
`created_at` datetime not null,
`updated_at` datetime not null
);
CREATE TABLE `movies_scenes` (
`movie_id` integer,
`scene_id` integer,
`scene_index` varchar(2),
foreign key(`movie_id`) references `movies`(`id`),
foreign key(`scene_id`) references `scenes`(`id`)
);
ALTER TABLE `scraped_items` ADD COLUMN `movie_id` integer;
CREATE UNIQUE INDEX `movies_checksum_unique` on `movies` (`checksum`);
CREATE UNIQUE INDEX `index_movie_id_scene_index_unique` ON `movies_scenes` ( `movie_id`, `scene_index` );
CREATE INDEX `index_movies_scenes_on_movie_id` on `movies_scenes` (`movie_id`);
CREATE INDEX `index_movies_scenes_on_scene_id` on `movies_scenes` (`scene_id`);

View File

@@ -0,0 +1,89 @@
PRAGMA foreign_keys=off;
-- need to re-create the performers table without the added column.
-- also need re-create the performers_scenes table due to the foreign key
-- rename existing performers table
ALTER TABLE `performers` RENAME TO `performers_old`;
ALTER TABLE `performers_scenes` RENAME TO `performers_scenes_old`;
-- drop the indexes
DROP INDEX IF EXISTS `index_performers_on_name`;
DROP INDEX IF EXISTS `index_performers_on_checksum`;
DROP INDEX IF EXISTS `index_performers_scenes_on_scene_id`;
DROP INDEX IF EXISTS `index_performers_scenes_on_performer_id`;
-- recreate the tables
CREATE TABLE `performers` (
`id` integer not null primary key autoincrement,
`image` blob not null,
`checksum` varchar(255) not null,
`name` varchar(255),
`url` varchar(255),
`twitter` varchar(255),
`instagram` varchar(255),
`birthdate` date,
`ethnicity` varchar(255),
`country` varchar(255),
`eye_color` varchar(255),
`height` varchar(255),
`measurements` varchar(255),
`fake_tits` varchar(255),
`career_length` varchar(255),
`tattoos` varchar(255),
`piercings` varchar(255),
`aliases` varchar(255),
`favorite` boolean not null default '0',
`created_at` datetime not null,
`updated_at` datetime not null
);
CREATE TABLE `performers_scenes` (
`performer_id` integer,
`scene_id` integer,
foreign key(`performer_id`) references `performers`(`id`),
foreign key(`scene_id`) references `scenes`(`id`)
);
INSERT INTO `performers`
SELECT
`id`,
`image`,
`checksum`,
`name`,
`url`,
`twitter`,
`instagram`,
`birthdate`,
`ethnicity`,
`country`,
`eye_color`,
`height`,
`measurements`,
`fake_tits`,
`career_length`,
`tattoos`,
`piercings`,
`aliases`,
`favorite`,
`created_at`,
`updated_at`
FROM `performers_old`;
INSERT INTO `performers_scenes`
SELECT
`performer_id`,
`scene_id`
FROM `performers_scenes_old`;
DROP TABLE `performers_scenes_old`;
DROP TABLE `performers_old`;
-- re-create the indexes after removing the old tables
CREATE INDEX `index_performers_on_name` on `performers` (`name`);
CREATE INDEX `index_performers_on_checksum` on `performers` (`checksum`);
CREATE INDEX `index_performers_scenes_on_scene_id` on `performers_scenes` (`scene_id`);
CREATE INDEX `index_performers_scenes_on_performer_id` on `performers_scenes` (`performer_id`);
PRAGMA foreign_keys=on;

View File

@@ -0,0 +1 @@
ALTER TABLE `performers` ADD COLUMN `gender` varchar(20);

View File

@@ -0,0 +1 @@
ALTER TABLE `scenes` ADD COLUMN `format` varchar(255);

View File

@@ -0,0 +1,101 @@
DROP INDEX `performers_checksum_unique`;
DROP INDEX `index_performers_on_name`;
DROP INDEX `index_performers_on_checksum`;
ALTER TABLE `performers` RENAME TO `temp_old_performers`;
CREATE TABLE `performers` (
`id` integer not null primary key autoincrement,
`checksum` varchar(255) not null,
`name` varchar(255),
`gender` varchar(20),
`url` varchar(255),
`twitter` varchar(255),
`instagram` varchar(255),
`birthdate` date,
`ethnicity` varchar(255),
`country` varchar(255),
`eye_color` varchar(255),
`height` varchar(255),
`measurements` varchar(255),
`fake_tits` varchar(255),
`career_length` varchar(255),
`tattoos` varchar(255),
`piercings` varchar(255),
`aliases` varchar(255),
`favorite` boolean not null default '0',
`created_at` datetime not null,
`updated_at` datetime not null,
`image` blob not null
);
CREATE UNIQUE INDEX `performers_checksum_unique` on `performers` (`checksum`);
CREATE INDEX `index_performers_on_name` on `performers` (`name`);
INSERT INTO `performers` (
`id`,
`checksum`,
`name`,
`gender`,
`url`,
`twitter`,
`instagram`,
`birthdate`,
`ethnicity`,
`country`,
`eye_color`,
`height`,
`measurements`,
`fake_tits`,
`career_length`,
`tattoos`,
`piercings`,
`aliases`,
`favorite`,
`created_at`,
`updated_at`,
`image`
)
SELECT
`id`,
`checksum`,
`name`,
`gender`,
`url`,
`twitter`,
`instagram`,
`birthdate`,
`ethnicity`,
`country`,
`eye_color`,
`height`,
`measurements`,
`fake_tits`,
`career_length`,
`tattoos`,
`piercings`,
`aliases`,
`favorite`,
`created_at`,
`updated_at`,
`image`
FROM `temp_old_performers`;
DROP INDEX `index_performers_scenes_on_scene_id`;
DROP INDEX `index_performers_scenes_on_performer_id`;
ALTER TABLE performers_scenes RENAME TO temp_old_performers_scenes;
CREATE TABLE `performers_scenes` (
`performer_id` integer,
`scene_id` integer,
foreign key(`performer_id`) references `performers`(`id`),
foreign key(`scene_id`) references `scenes`(`id`)
);
CREATE INDEX `index_performers_scenes_on_scene_id` on `performers_scenes` (`scene_id`);
CREATE INDEX `index_performers_scenes_on_performer_id` on `performers_scenes` (`performer_id`);
INSERT INTO `performers_scenes` (
`performer_id`,
`scene_id`
)
SELECT
`performer_id`,
`scene_id`
FROM `temp_old_performers_scenes`;
DROP TABLE `temp_old_performers`;
DROP TABLE `temp_old_performers_scenes`;

View File

@@ -0,0 +1,106 @@
ALTER TABLE `movies` rename to `_movies_old`;
ALTER TABLE `movies_scenes` rename to `_movies_scenes_old`;
DROP INDEX IF EXISTS `movies_checksum_unique`;
DROP INDEX IF EXISTS `index_movie_id_scene_index_unique`;
DROP INDEX IF EXISTS `index_movies_scenes_on_movie_id`;
DROP INDEX IF EXISTS `index_movies_scenes_on_scene_id`;
-- recreate the movies table with fixed column types and constraints
CREATE TABLE `movies` (
`id` integer not null primary key autoincrement,
-- add not null
`name` varchar(255) not null,
`aliases` varchar(255),
-- varchar(6) -> integer
`duration` integer,
`date` date,
-- varchar(1) -> tinyint
`rating` tinyint,
`studio_id` integer,
`director` varchar(255),
`synopsis` text,
`checksum` varchar(255) not null,
`url` varchar(255),
`created_at` datetime not null,
`updated_at` datetime not null,
`front_image` blob not null,
`back_image` blob,
foreign key(`studio_id`) references `studios`(`id`) on delete set null
);
CREATE TABLE `movies_scenes` (
`movie_id` integer,
`scene_id` integer,
-- varchar(2) -> tinyint
`scene_index` tinyint,
foreign key(`movie_id`) references `movies`(`id`) on delete cascade,
foreign key(`scene_id`) references `scenes`(`id`) on delete cascade
);
-- add unique index on movie name
CREATE UNIQUE INDEX `movies_name_unique` on `movies` (`name`);
CREATE UNIQUE INDEX `movies_checksum_unique` on `movies` (`checksum`);
-- remove unique index on movies_scenes
CREATE INDEX `index_movies_scenes_on_movie_id` on `movies_scenes` (`movie_id`);
CREATE INDEX `index_movies_scenes_on_scene_id` on `movies_scenes` (`scene_id`);
CREATE INDEX `index_movies_on_studio_id` on `movies` (`studio_id`);
-- custom functions cannot accept NULL values, so massage the old data
UPDATE `_movies_old` set `duration` = 0 WHERE `duration` IS NULL;
-- now populate from the old tables
INSERT INTO `movies`
(
`id`,
`name`,
`aliases`,
`duration`,
`date`,
`rating`,
`director`,
`synopsis`,
`front_image`,
`back_image`,
`checksum`,
`url`,
`created_at`,
`updated_at`
)
SELECT
`id`,
`name`,
`aliases`,
durationToTinyInt(`duration`),
`date`,
CAST(`rating` as tinyint),
`director`,
`synopsis`,
`front_image`,
`back_image`,
`checksum`,
`url`,
`created_at`,
`updated_at`
FROM `_movies_old`
-- ignore null named movies
WHERE `name` is not null;
-- durationToTinyInt returns 0 if it cannot parse the string
-- set these values to null instead
UPDATE `movies` SET `duration` = NULL WHERE `duration` = 0;
INSERT INTO `movies_scenes`
(
`movie_id`,
`scene_id`,
`scene_index`
)
SELECT
`movie_id`,
`scene_id`,
CAST(`scene_index` as tinyint)
FROM `_movies_scenes_old`;
-- drop old tables
DROP TABLE `_movies_scenes_old`;
DROP TABLE `_movies_old`;

View File

@@ -18,8 +18,8 @@ type Encoder struct {
}
var (
runningEncoders map[string][]*os.Process = make(map[string][]*os.Process)
runningEncodersMutex = sync.RWMutex{}
runningEncoders = make(map[string][]*os.Process)
runningEncodersMutex = sync.RWMutex{}
)
func NewEncoder(ffmpegPath string) Encoder {

View File

@@ -13,9 +13,10 @@ type ScenePreviewChunkOptions struct {
OutputPath string
}
func (e *Encoder) ScenePreviewVideoChunk(probeResult VideoFile, options ScenePreviewChunkOptions) {
func (e *Encoder) ScenePreviewVideoChunk(probeResult VideoFile, options ScenePreviewChunkOptions, preset string) {
args := []string{
"-v", "error",
"-xerror",
"-ss", strconv.Itoa(options.Time),
"-i", probeResult.Path,
"-t", "0.75",
@@ -25,7 +26,7 @@ func (e *Encoder) ScenePreviewVideoChunk(probeResult VideoFile, options ScenePre
"-pix_fmt", "yuv420p",
"-profile:v", "high",
"-level", "4.2",
"-preset", "veryslow",
"-preset", preset,
"-crf", "21",
"-threads", "4",
"-vf", fmt.Sprintf("scale=%v:-2", options.Width),

View File

@@ -10,7 +10,7 @@ type ScreenshotOptions struct {
Verbosity string
}
func (e *Encoder) Screenshot(probeResult VideoFile, options ScreenshotOptions) {
func (e *Encoder) Screenshot(probeResult VideoFile, options ScreenshotOptions) error {
if options.Verbosity == "" {
options.Verbosity = "error"
}
@@ -28,5 +28,7 @@ func (e *Encoder) Screenshot(probeResult VideoFile, options ScreenshotOptions) {
"-f", "image2",
options.OutputPath,
}
_, _ = e.run(probeResult, args)
_, err := e.run(probeResult, args)
return err
}

View File

@@ -69,6 +69,49 @@ func (e *Encoder) Transcode(probeResult VideoFile, options TranscodeOptions) {
_, _ = e.run(probeResult, args)
}
//transcode the video, remove the audio
//in some videos where the audio codec is not supported by ffmpeg
//ffmpeg fails if you try to transcode the audio
func (e *Encoder) TranscodeVideo(probeResult VideoFile, options TranscodeOptions) {
scale := calculateTranscodeScale(probeResult, options.MaxTranscodeSize)
args := []string{
"-i", probeResult.Path,
"-an",
"-c:v", "libx264",
"-pix_fmt", "yuv420p",
"-profile:v", "high",
"-level", "4.2",
"-preset", "superfast",
"-crf", "23",
"-vf", "scale=" + scale,
options.OutputPath,
}
_, _ = e.run(probeResult, args)
}
//copy the video stream as is, transcode audio
func (e *Encoder) TranscodeAudio(probeResult VideoFile, options TranscodeOptions) {
args := []string{
"-i", probeResult.Path,
"-c:v", "copy",
"-c:a", "aac",
"-strict", "-2",
options.OutputPath,
}
_, _ = e.run(probeResult, args)
}
//copy the video stream as is, drop audio
func (e *Encoder) CopyVideo(probeResult VideoFile, options TranscodeOptions) {
args := []string{
"-i", probeResult.Path,
"-an",
"-c:v", "copy",
options.OutputPath,
}
_, _ = e.run(probeResult, args)
}
func (e *Encoder) StreamTranscode(probeResult VideoFile, startTime string, maxTranscodeSize models.StreamingResolutionEnum) (io.ReadCloser, *os.Process, error) {
scale := calculateTranscodeScale(probeResult, maxTranscodeSize)
args := []string{}
@@ -92,3 +135,53 @@ func (e *Encoder) StreamTranscode(probeResult VideoFile, startTime string, maxTr
return e.stream(probeResult, args)
}
//transcode the video, remove the audio
//in some videos where the audio codec is not supported by ffmpeg
//ffmpeg fails if you try to transcode the audio
func (e *Encoder) StreamTranscodeVideo(probeResult VideoFile, startTime string, maxTranscodeSize models.StreamingResolutionEnum) (io.ReadCloser, *os.Process, error) {
scale := calculateTranscodeScale(probeResult, maxTranscodeSize)
args := []string{}
if startTime != "" {
args = append(args, "-ss", startTime)
}
args = append(args,
"-i", probeResult.Path,
"-an",
"-c:v", "libvpx-vp9",
"-vf", "scale="+scale,
"-deadline", "realtime",
"-cpu-used", "5",
"-row-mt", "1",
"-crf", "30",
"-b:v", "0",
"-f", "webm",
"pipe:",
)
return e.stream(probeResult, args)
}
//it is very common in MKVs to have just the audio codec unsupported
//copy the video stream, transcode the audio and serve as Matroska
func (e *Encoder) StreamMkvTranscodeAudio(probeResult VideoFile, startTime string, maxTranscodeSize models.StreamingResolutionEnum) (io.ReadCloser, *os.Process, error) {
args := []string{}
if startTime != "" {
args = append(args, "-ss", startTime)
}
args = append(args,
"-i", probeResult.Path,
"-c:v", "copy",
"-c:a", "libopus",
"-b:a", "96k",
"-vbr", "on",
"-f", "matroska",
"pipe:",
)
return e.stream(probeResult, args)
}

View File

@@ -10,11 +10,106 @@ import (
"strconv"
"strings"
"time"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager/config"
)
var ValidCodecs = []string{"h264", "h265", "vp8", "vp9"}
type Container string
type AudioCodec string
const (
Mp4 Container = "mp4"
M4v Container = "m4v"
Mov Container = "mov"
Wmv Container = "wmv"
Webm Container = "webm"
Matroska Container = "matroska"
Avi Container = "avi"
Flv Container = "flv"
Mpegts Container = "mpegts"
Aac AudioCodec = "aac"
Mp3 AudioCodec = "mp3"
Opus AudioCodec = "opus"
Vorbis AudioCodec = "vorbis"
MissingUnsupported AudioCodec = ""
Mp4Ffmpeg string = "mov,mp4,m4a,3gp,3g2,mj2" // browsers support all of them
M4vFfmpeg string = "mov,mp4,m4a,3gp,3g2,mj2" // so we don't care that ffmpeg
MovFfmpeg string = "mov,mp4,m4a,3gp,3g2,mj2" // can't differentiate between them
WmvFfmpeg string = "asf"
WebmFfmpeg string = "matroska,webm"
MatroskaFfmpeg string = "matroska,webm"
AviFfmpeg string = "avi"
FlvFfmpeg string = "flv"
MpegtsFfmpeg string = "mpegts"
H264 string = "h264"
H265 string = "h265" // found in rare cases from a faulty encoder
Hevc string = "hevc"
Vp8 string = "vp8"
Vp9 string = "vp9"
MimeWebm string = "video/webm"
MimeMkv string = "video/x-matroska"
)
var ValidCodecs = []string{H264, H265, Vp8, Vp9}
var validForH264Mkv = []Container{Mp4, Matroska}
var validForH264 = []Container{Mp4}
var validForH265Mkv = []Container{Mp4, Matroska}
var validForH265 = []Container{Mp4}
var validForVp8 = []Container{Webm}
var validForVp9Mkv = []Container{Webm, Matroska}
var validForVp9 = []Container{Webm}
var validForHevcMkv = []Container{Mp4, Matroska}
var validForHevc = []Container{Mp4}
var validAudioForMkv = []AudioCodec{Aac, Mp3, Vorbis, Opus}
var validAudioForWebm = []AudioCodec{Vorbis, Opus}
var validAudioForMp4 = []AudioCodec{Aac, Mp3}
//maps user readable container strings to ffprobe's format_name
//on some formats ffprobe can't differentiate
var ContainerToFfprobe = map[Container]string{
Mp4: Mp4Ffmpeg,
M4v: M4vFfmpeg,
Mov: MovFfmpeg,
Wmv: WmvFfmpeg,
Webm: WebmFfmpeg,
Matroska: MatroskaFfmpeg,
Avi: AviFfmpeg,
Flv: FlvFfmpeg,
Mpegts: MpegtsFfmpeg,
}
var FfprobeToContainer = map[string]Container{
Mp4Ffmpeg: Mp4,
WmvFfmpeg: Wmv,
AviFfmpeg: Avi,
FlvFfmpeg: Flv,
MpegtsFfmpeg: Mpegts,
MatroskaFfmpeg: Matroska,
}
func MatchContainer(format string, filePath string) Container { // match ffprobe string to our Container
container := FfprobeToContainer[format]
if container == Matroska {
container = MagicContainer(filePath) // use magic number instead of ffprobe for matroska,webm
}
if container == "" { // if format is not in our Container list leave it as ffprobes reported format_name
container = Container(format)
}
return container
}
func IsValidCodec(codecName string) bool {
forceHEVC := config.GetForceHEVC()
if forceHEVC {
if codecName == Hevc {
return true
}
}
for _, c := range ValidCodecs {
if c == codecName {
return true
@@ -23,6 +118,78 @@ func IsValidCodec(codecName string) bool {
return false
}
func IsValidAudio(audio AudioCodec, ValidCodecs []AudioCodec) bool {
// if audio codec is missing or unsupported by ffmpeg we can't do anything about it
// report it as valid so that the file can at least be streamed directly if the video codec is supported
if audio == MissingUnsupported {
return true
}
for _, c := range ValidCodecs {
if c == audio {
return true
}
}
return false
}
func IsValidAudioForContainer(audio AudioCodec, format Container) bool {
switch format {
case Matroska:
return IsValidAudio(audio, validAudioForMkv)
case Webm:
return IsValidAudio(audio, validAudioForWebm)
case Mp4:
return IsValidAudio(audio, validAudioForMp4)
}
return false
}
func IsValidForContainer(format Container, validContainers []Container) bool {
for _, fmt := range validContainers {
if fmt == format {
return true
}
}
return false
}
//extend stream validation check to take into account container
func IsValidCombo(codecName string, format Container) bool {
forceMKV := config.GetForceMKV()
forceHEVC := config.GetForceHEVC()
switch codecName {
case H264:
if forceMKV {
return IsValidForContainer(format, validForH264Mkv)
}
return IsValidForContainer(format, validForH264)
case H265:
if forceMKV {
return IsValidForContainer(format, validForH265Mkv)
}
return IsValidForContainer(format, validForH265)
case Vp8:
return IsValidForContainer(format, validForVp8)
case Vp9:
if forceMKV {
return IsValidForContainer(format, validForVp9Mkv)
}
return IsValidForContainer(format, validForVp9)
case Hevc:
if forceHEVC {
if forceMKV {
return IsValidForContainer(format, validForHevcMkv)
}
return IsValidForContainer(format, validForHevc)
}
}
return false
}
type VideoFile struct {
JSON FFProbeJSON
AudioStream *FFProbeStream
@@ -98,7 +265,11 @@ func parse(filePath string, probeJSON *FFProbeJSON) (*VideoFile, error) {
result.Container = probeJSON.Format.FormatName
duration, _ := strconv.ParseFloat(probeJSON.Format.Duration, 64)
result.Duration = math.Round(duration*100) / 100
fileStat, _ := os.Stat(filePath)
fileStat, err := os.Stat(filePath)
if err != nil {
logger.Errorf("Error statting file: %v", err)
return nil, err
}
result.Size = fileStat.Size()
result.StartTime, _ = strconv.ParseFloat(probeJSON.Format.StartTime, 64)
result.CreationTime = probeJSON.Format.Tags.CreationTime.Time

View File

@@ -0,0 +1,66 @@
package ffmpeg
import (
"bytes"
"github.com/stashapp/stash/pkg/logger"
"os"
)
// detect file format from magic file number
// https://github.com/lex-r/filetype/blob/73c10ad714e3b8ecf5cd1564c882ed6d440d5c2d/matchers/video.go
func mkv(buf []byte) bool {
return len(buf) > 3 &&
buf[0] == 0x1A && buf[1] == 0x45 &&
buf[2] == 0xDF && buf[3] == 0xA3 &&
containsMatroskaSignature(buf, []byte{'m', 'a', 't', 'r', 'o', 's', 'k', 'a'})
}
func webm(buf []byte) bool {
return len(buf) > 3 &&
buf[0] == 0x1A && buf[1] == 0x45 &&
buf[2] == 0xDF && buf[3] == 0xA3 &&
containsMatroskaSignature(buf, []byte{'w', 'e', 'b', 'm'})
}
func containsMatroskaSignature(buf, subType []byte) bool {
limit := 4096
if len(buf) < limit {
limit = len(buf)
}
index := bytes.Index(buf[:limit], subType)
if index < 3 {
return false
}
return buf[index-3] == 0x42 && buf[index-2] == 0x82
}
//returns container as string ("" on error or no match)
//implements only mkv or webm as ffprobe can't distinguish between them
//and not all browsers support mkv
func MagicContainer(file_path string) Container {
file, err := os.Open(file_path)
if err != nil {
logger.Errorf("[magicfile] %v", err)
return ""
}
defer file.Close()
buf := make([]byte, 4096)
_, err = file.Read(buf)
if err != nil {
logger.Errorf("[magicfile] %v", err)
return ""
}
if webm(buf) {
return Webm
}
if mkv(buf) {
return Matroska
}
return ""
}

View File

@@ -19,10 +19,12 @@ const Metadata = "metadata"
const Downloads = "downloads"
const Username = "username"
const Password = "password"
const MaxSessionAge = "max_session_age"
const DefaultMaxSessionAge = 60 * 60 * 1 // 1 hours
const Database = "database"
const ScrapersPath = "scrapers_path"
const Exclude = "exclude"
const MaxTranscodeSize = "max_transcode_size"
@@ -30,6 +32,20 @@ const MaxStreamingTranscodeSize = "max_streaming_transcode_size"
const Host = "host"
const Port = "port"
const ExternalHost = "external_host"
// key used to sign JWT tokens
const JWTSignKey = "jwt_secret_key"
// key used for session store
const SessionStoreKey = "session_store_key"
// scraping options
const ScrapersPath = "scrapers_path"
const ScraperUserAgent = "scraper_user_agent"
// i18n
const Language = "language"
// Interface options
const SoundOnPreview = "sound_on_preview"
@@ -38,6 +54,11 @@ const MaximumLoopDuration = "maximum_loop_duration"
const AutostartVideo = "autostart_video"
const ShowStudioAsText = "show_studio_as_text"
const CSSEnabled = "cssEnabled"
const WallPlayback = "wall_playback"
// Playback force codec,container
const ForceMKV = "forceMKV"
const ForceHEVC = "forceHEVC"
// Logging options
const LogFile = "logFile"
@@ -82,6 +103,14 @@ func GetDatabasePath() string {
return viper.GetString(Database)
}
func GetJWTSignKey() []byte {
return []byte(viper.GetString(JWTSignKey))
}
func GetSessionStoreKey() []byte {
return []byte(viper.GetString(SessionStoreKey))
}
func GetDefaultScrapersPath() string {
// default to the same directory as the config file
configFileUsed := viper.ConfigFileUsed()
@@ -96,10 +125,25 @@ func GetExcludes() []string {
return viper.GetStringSlice(Exclude)
}
func GetLanguage() string {
ret := viper.GetString(Language)
// default to English
if ret == "" {
return "en-US"
}
return ret
}
func GetScrapersPath() string {
return viper.GetString(ScrapersPath)
}
func GetScraperUserAgent() string {
return viper.GetString(ScraperUserAgent)
}
func GetHost() string {
return viper.GetString(Host)
}
@@ -108,6 +152,10 @@ func GetPort() int {
return viper.GetInt(Port)
}
func GetExternalHost() string {
return viper.GetString(ExternalHost)
}
func GetMaxTranscodeSize() models.StreamingResolutionEnum {
ret := viper.GetString(MaxTranscodeSize)
@@ -176,6 +224,13 @@ func ValidateCredentials(username string, password string) bool {
return username == authUser && err == nil
}
// GetMaxSessionAge gets the maximum age for session cookies, in seconds.
// Session cookie expiry times are refreshed every request.
func GetMaxSessionAge() int {
viper.SetDefault(MaxSessionAge, DefaultMaxSessionAge)
return viper.GetInt(MaxSessionAge)
}
// Interface options
func GetSoundOnPreview() bool {
viper.SetDefault(SoundOnPreview, true)
@@ -187,6 +242,11 @@ func GetWallShowTitle() bool {
return viper.GetBool(WallShowTitle)
}
func GetWallPlayback() string {
viper.SetDefault(WallPlayback, "video")
return viper.GetString(WallPlayback)
}
func GetMaximumLoopDuration() int {
viper.SetDefault(MaximumLoopDuration, 0)
return viper.GetInt(MaximumLoopDuration)
@@ -241,6 +301,15 @@ func GetCSSEnabled() bool {
return viper.GetBool(CSSEnabled)
}
// force codec,container
func GetForceMKV() bool {
return viper.GetBool(ForceMKV)
}
func GetForceHEVC() bool {
return viper.GetBool(ForceHEVC)
}
// GetLogFile returns the filename of the file to output logs to.
// An empty string means that file logging will be disabled.
func GetLogFile() string {
@@ -289,3 +358,21 @@ func IsValid() bool {
// TODO: check valid paths
return setPaths
}
// SetInitialConfig fills in missing required config fields
func SetInitialConfig() error {
// generate some api keys
const apiKeyLength = 32
if string(GetJWTSignKey()) == "" {
signKey := utils.GenerateRandomKey(apiKeyLength)
Set(JWTSignKey, signKey)
}
if string(GetSessionStoreKey()) == "" {
sessionStoreKey := utils.GenerateRandomKey(apiKeyLength)
Set(SessionStoreKey, sessionStoreKey)
}
return Write()
}

View File

@@ -1,9 +1,10 @@
package manager
import (
"github.com/stashapp/stash/pkg/logger"
"regexp"
"strings"
"github.com/stashapp/stash/pkg/logger"
)
func excludeFiles(files []string, patterns []string) ([]string, int) {
@@ -37,21 +38,13 @@ func excludeFiles(files []string, patterns []string) ([]string, int) {
}
func matchFile(file string, patterns []string) bool {
if patterns == nil {
logger.Infof("No exclude patterns in config.")
} else {
if patterns != nil {
fileRegexps := generateRegexps(patterns)
if len(fileRegexps) == 0 {
return false
}
for _, regPattern := range fileRegexps {
if regPattern.MatchString(strings.ToLower(file)) {
return true
}
}
}

View File

@@ -7,6 +7,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"github.com/stashapp/stash/pkg/models"
@@ -87,8 +88,10 @@ func initParserFields() {
//I = new ParserField("i", undefined, "Matches any ignored word", false);
ret["d"] = newParserField("d", `(?:\.|-|_)`, false)
ret["rating"] = newParserField("rating", `\d`, true)
ret["performer"] = newParserField("performer", ".*", true)
ret["studio"] = newParserField("studio", ".*", true)
ret["movie"] = newParserField("movie", ".*", true)
ret["tag"] = newParserField("tag", ".*", true)
// date fields
@@ -96,6 +99,7 @@ func initParserFields() {
ret["yyyy"] = newParserField("yyyy", `\d{4}`, true)
ret["yy"] = newParserField("yy", `\d{2}`, true)
ret["mm"] = newParserField("mm", `\d{2}`, true)
ret["mmm"] = newParserField("mmm", `\w{3}`, true)
ret["dd"] = newParserField("dd", `\d{2}`, true)
ret["yyyymmdd"] = newFullDateParserField("yyyymmdd", `\d{8}`)
ret["yymmdd"] = newFullDateParserField("yymmdd", `\d{6}`)
@@ -204,6 +208,7 @@ type sceneHolder struct {
mm string
dd string
performers []string
movies []string
studio string
tags []string
}
@@ -222,6 +227,10 @@ func newSceneHolder(scene *models.Scene) *sceneHolder {
return &ret
}
func validateRating(rating int) bool {
return rating >= 1 && rating <= 5
}
func validateDate(dateStr string) bool {
splits := strings.Split(dateStr, "-")
if len(splits) != 3 {
@@ -283,6 +292,20 @@ func (h *sceneHolder) setDate(field *parserField, value string) {
}
}
func mmmToMonth(mmm string) string {
format := "02-Jan-2006"
dateStr := "01-" + mmm + "-2000"
t, err := time.Parse(format, dateStr)
if err != nil {
return ""
}
// expect month in two-digit format
format = "01-02-2006"
return t.Format(format)[0:2]
}
func (h *sceneHolder) setField(field parserField, value interface{}) {
if field.isFullDateField {
h.setDate(&field, value.(string))
@@ -302,27 +325,35 @@ func (h *sceneHolder) setField(field parserField, value interface{}) {
Valid: true,
}
}
case "rating":
rating, _ := strconv.Atoi(value.(string))
if validateRating(rating) {
h.result.Rating = sql.NullInt64{
Int64: int64(rating),
Valid: true,
}
}
case "performer":
// add performer to list
h.performers = append(h.performers, value.(string))
case "studio":
h.studio = value.(string)
case "movie":
h.movies = append(h.movies, value.(string))
case "tag":
h.tags = append(h.tags, value.(string))
case "yyyy":
h.yyyy = value.(string)
break
case "yy":
v := value.(string)
v = "20" + v
h.yyyy = v
break
case "mmm":
h.mm = mmmToMonth(value.(string))
case "mm":
h.mm = value.(string)
break
case "dd":
h.dd = value.(string)
break
}
}
@@ -374,7 +405,7 @@ func (m parseMapper) parse(scene *models.Scene) *sceneHolder {
}
type performerQueryer interface {
FindByNames(names []string, tx *sqlx.Tx) ([]*models.Performer, error)
FindByNames(names []string, tx *sqlx.Tx, nocase bool) ([]*models.Performer, error)
}
type sceneQueryer interface {
@@ -382,11 +413,15 @@ type sceneQueryer interface {
}
type tagQueryer interface {
FindByName(name string, tx *sqlx.Tx) (*models.Tag, error)
FindByName(name string, tx *sqlx.Tx, nocase bool) (*models.Tag, error)
}
type studioQueryer interface {
FindByName(name string, tx *sqlx.Tx) (*models.Studio, error)
FindByName(name string, tx *sqlx.Tx, nocase bool) (*models.Studio, error)
}
type movieQueryer interface {
FindByName(name string, tx *sqlx.Tx, nocase bool) (*models.Movie, error)
}
type SceneFilenameParser struct {
@@ -396,12 +431,14 @@ type SceneFilenameParser struct {
whitespaceRE *regexp.Regexp
performerCache map[string]*models.Performer
studioCache map[string]*models.Studio
movieCache map[string]*models.Movie
tagCache map[string]*models.Tag
performerQuery performerQueryer
sceneQuery sceneQueryer
tagQuery tagQueryer
studioQuery studioQueryer
movieQuery movieQueryer
}
func NewSceneFilenameParser(filter *models.FindFilterType, config models.SceneParserInput) *SceneFilenameParser {
@@ -413,6 +450,7 @@ func NewSceneFilenameParser(filter *models.FindFilterType, config models.ScenePa
p.performerCache = make(map[string]*models.Performer)
p.studioCache = make(map[string]*models.Studio)
p.movieCache = make(map[string]*models.Movie)
p.tagCache = make(map[string]*models.Tag)
p.initWhiteSpaceRegex()
@@ -429,6 +467,9 @@ func NewSceneFilenameParser(filter *models.FindFilterType, config models.ScenePa
studioQuery := models.NewStudioQueryBuilder()
p.studioQuery = &studioQuery
movieQuery := models.NewMovieQueryBuilder()
p.movieQuery = &movieQuery
return p
}
@@ -505,7 +546,7 @@ func (p *SceneFilenameParser) queryPerformer(performerName string) *models.Perfo
}
// perform an exact match and grab the first
performers, _ := p.performerQuery.FindByNames([]string{performerName}, nil)
performers, _ := p.performerQuery.FindByNames([]string{performerName}, nil, true)
var ret *models.Performer
if len(performers) > 0 {
@@ -527,7 +568,7 @@ func (p *SceneFilenameParser) queryStudio(studioName string) *models.Studio {
return ret
}
ret, _ := p.studioQuery.FindByName(studioName, nil)
ret, _ := p.studioQuery.FindByName(studioName, nil, true)
// add result to cache
p.studioCache[studioName] = ret
@@ -535,6 +576,23 @@ func (p *SceneFilenameParser) queryStudio(studioName string) *models.Studio {
return ret
}
func (p *SceneFilenameParser) queryMovie(movieName string) *models.Movie {
// massage the movie name
movieName = delimiterRE.ReplaceAllString(movieName, " ")
// check cache first
if ret, found := p.movieCache[movieName]; found {
return ret
}
ret, _ := p.movieQuery.FindByName(movieName, nil, true)
// add result to cache
p.movieCache[movieName] = ret
return ret
}
func (p *SceneFilenameParser) queryTag(tagName string) *models.Tag {
// massage the performer name
tagName = delimiterRE.ReplaceAllString(tagName, " ")
@@ -545,7 +603,7 @@ func (p *SceneFilenameParser) queryTag(tagName string) *models.Tag {
}
// match tag name exactly
ret, _ := p.tagQuery.FindByName(tagName, nil)
ret, _ := p.tagQuery.FindByName(tagName, nil, true)
// add result to cache
p.tagCache[tagName] = ret
@@ -596,6 +654,24 @@ func (p *SceneFilenameParser) setStudio(h sceneHolder, result *models.SceneParse
}
}
func (p *SceneFilenameParser) setMovies(h sceneHolder, result *models.SceneParserResult) {
// query for each movie
moviesSet := make(map[int]bool)
for _, movieName := range h.movies {
if movieName != "" {
movie := p.queryMovie(movieName)
if movie != nil {
if _, found := moviesSet[movie.ID]; !found {
result.Movies = append(result.Movies, &models.SceneMovieID{
MovieID: strconv.Itoa(movie.ID),
})
moviesSet[movie.ID] = true
}
}
}
}
}
func (p *SceneFilenameParser) setParserResult(h sceneHolder, result *models.SceneParserResult) {
if h.result.Title.Valid {
title := h.result.Title.String
@@ -612,6 +688,11 @@ func (p *SceneFilenameParser) setParserResult(h sceneHolder, result *models.Scen
result.Date = &h.result.Date.String
}
if h.result.Rating.Valid {
rating := int(h.result.Rating.Int64)
result.Rating = &rating
}
if len(h.performers) > 0 {
p.setPerformers(h, result)
}
@@ -619,4 +700,9 @@ func (p *SceneFilenameParser) setParserResult(h sceneHolder, result *models.Scen
p.setTags(h, result)
}
p.setStudio(h, result)
if len(h.movies) > 0 {
p.setMovies(h, result)
}
}

View File

@@ -16,9 +16,14 @@ type PreviewGenerator struct {
VideoFilename string
ImageFilename string
OutputDirectory string
GenerateVideo bool
GenerateImage bool
PreviewPreset string
}
func NewPreviewGenerator(videoFile ffmpeg.VideoFile, videoFilename string, imageFilename string, outputDirectory string) (*PreviewGenerator, error) {
func NewPreviewGenerator(videoFile ffmpeg.VideoFile, videoFilename string, imageFilename string, outputDirectory string, generateVideo bool, generateImage bool, previewPreset string) (*PreviewGenerator, error) {
exists, err := utils.FileExists(videoFile.Path)
if !exists {
return nil, err
@@ -37,6 +42,9 @@ func NewPreviewGenerator(videoFile ffmpeg.VideoFile, videoFilename string, image
VideoFilename: videoFilename,
ImageFilename: imageFilename,
OutputDirectory: outputDirectory,
GenerateVideo: generateVideo,
GenerateImage: generateImage,
PreviewPreset: previewPreset,
}, nil
}
@@ -47,11 +55,16 @@ func (g *PreviewGenerator) Generate() error {
if err := g.generateConcatFile(); err != nil {
return err
}
if err := g.generateVideo(&encoder); err != nil {
return err
if g.GenerateVideo {
if err := g.generateVideo(&encoder); err != nil {
return err
}
}
if err := g.generateImage(&encoder); err != nil {
return err
if g.GenerateImage {
if err := g.generateImage(&encoder); err != nil {
return err
}
}
return nil
}
@@ -91,7 +104,7 @@ func (g *PreviewGenerator) generateVideo(encoder *ffmpeg.Encoder) error {
Width: 640,
OutputPath: chunkOutputPath,
}
encoder.ScenePreviewVideoChunk(g.Info.VideoFile, options)
encoder.ScenePreviewVideoChunk(g.Info.VideoFile, options, g.PreviewPreset)
}
videoOutputPath := filepath.Join(g.OutputDirectory, g.VideoFilename)

View File

@@ -38,6 +38,14 @@ func (jp *jsonUtils) saveStudio(checksum string, studio *jsonschema.Studio) erro
return jsonschema.SaveStudioFile(instance.Paths.JSON.StudioJSONPath(checksum), studio)
}
func (jp *jsonUtils) getMovie(checksum string) (*jsonschema.Movie, error) {
return jsonschema.LoadMovieFile(instance.Paths.JSON.MovieJSONPath(checksum))
}
func (jp *jsonUtils) saveMovie(checksum string, movie *jsonschema.Movie) error {
return jsonschema.SaveMovieFile(instance.Paths.JSON.MovieJSONPath(checksum), movie)
}
func (jp *jsonUtils) getScene(checksum string) (*jsonschema.Scene, error) {
return jsonschema.LoadSceneFile(instance.Paths.JSON.SceneJSONPath(checksum))
}

View File

@@ -1,8 +1,8 @@
package jsonschema
import (
"encoding/json"
"fmt"
"github.com/json-iterator/go"
"os"
)
@@ -19,6 +19,7 @@ type PathMapping struct {
type Mappings struct {
Performers []NameMapping `json:"performers"`
Studios []NameMapping `json:"studios"`
Movies []NameMapping `json:"movies"`
Galleries []PathMapping `json:"galleries"`
Scenes []PathMapping `json:"scenes"`
}
@@ -30,6 +31,7 @@ func LoadMappingsFile(filePath string) (*Mappings, error) {
if err != nil {
return nil, err
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
jsonParser := json.NewDecoder(file)
err = jsonParser.Decode(&mappings)
if err != nil {

View File

@@ -0,0 +1,47 @@
package jsonschema
import (
"fmt"
"github.com/json-iterator/go"
"os"
"github.com/stashapp/stash/pkg/models"
)
type Movie struct {
Name string `json:"name,omitempty"`
Aliases string `json:"aliases,omitempty"`
Duration int `json:"duration,omitempty"`
Date string `json:"date,omitempty"`
Rating int `json:"rating,omitempty"`
Director string `json:"director,omitempty"`
Synopsis string `json:"sypnopsis,omitempty"`
FrontImage string `json:"front_image,omitempty"`
BackImage string `json:"back_image,omitempty"`
URL string `json:"url,omitempty"`
CreatedAt models.JSONTime `json:"created_at,omitempty"`
UpdatedAt models.JSONTime `json:"updated_at,omitempty"`
}
func LoadMovieFile(filePath string) (*Movie, error) {
var movie Movie
file, err := os.Open(filePath)
defer file.Close()
if err != nil {
return nil, err
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
jsonParser := json.NewDecoder(file)
err = jsonParser.Decode(&movie)
if err != nil {
return nil, err
}
return &movie, nil
}
func SaveMovieFile(filePath string, movie *Movie) error {
if movie == nil {
return fmt.Errorf("movie must not be nil")
}
return marshalToFile(filePath, movie)
}

View File

@@ -1,14 +1,16 @@
package jsonschema
import (
"encoding/json"
"fmt"
"github.com/stashapp/stash/pkg/models"
"github.com/json-iterator/go"
"os"
"github.com/stashapp/stash/pkg/models"
)
type Performer struct {
Name string `json:"name,omitempty"`
Gender string `json:"gender,omitempty"`
URL string `json:"url,omitempty"`
Twitter string `json:"twitter,omitempty"`
Instagram string `json:"instagram,omitempty"`
@@ -36,6 +38,7 @@ func LoadPerformerFile(filePath string) (*Performer, error) {
if err != nil {
return nil, err
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
jsonParser := json.NewDecoder(file)
err = jsonParser.Decode(&performer)
if err != nil {

View File

@@ -1,10 +1,11 @@
package jsonschema
import (
"encoding/json"
"fmt"
"github.com/stashapp/stash/pkg/models"
"github.com/json-iterator/go"
"os"
"github.com/stashapp/stash/pkg/models"
)
type SceneMarker struct {
@@ -21,21 +22,29 @@ type SceneFile struct {
Duration string `json:"duration"`
VideoCodec string `json:"video_codec"`
AudioCodec string `json:"audio_codec"`
Format string `json:"format"`
Width int `json:"width"`
Height int `json:"height"`
Framerate string `json:"framerate"`
Bitrate int `json:"bitrate"`
}
type SceneMovie struct {
MovieName string `json:"movieName,omitempty"`
SceneIndex int `json:"scene_index,omitempty"`
}
type Scene struct {
Title string `json:"title,omitempty"`
Studio string `json:"studio,omitempty"`
URL string `json:"url,omitempty"`
Date string `json:"date,omitempty"`
Rating int `json:"rating,omitempty"`
OCounter int `json:"o_counter,omitempty"`
Details string `json:"details,omitempty"`
Gallery string `json:"gallery,omitempty"`
Performers []string `json:"performers,omitempty"`
Movies []SceneMovie `json:"movies,omitempty"`
Tags []string `json:"tags,omitempty"`
Markers []SceneMarker `json:"markers,omitempty"`
File *SceneFile `json:"file,omitempty"`
@@ -51,6 +60,7 @@ func LoadSceneFile(filePath string) (*Scene, error) {
if err != nil {
return nil, err
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
jsonParser := json.NewDecoder(file)
err = jsonParser.Decode(&scene)
if err != nil {

View File

@@ -1,8 +1,8 @@
package jsonschema
import (
"encoding/json"
"fmt"
"github.com/json-iterator/go"
"github.com/stashapp/stash/pkg/models"
"os"
)
@@ -31,6 +31,7 @@ func LoadScrapedFile(filePath string) ([]ScrapedItem, error) {
if err != nil {
return nil, err
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
jsonParser := json.NewDecoder(file)
err = jsonParser.Decode(&scraped)
if err != nil {

View File

@@ -1,8 +1,8 @@
package jsonschema
import (
"encoding/json"
"fmt"
"github.com/json-iterator/go"
"github.com/stashapp/stash/pkg/models"
"os"
)
@@ -22,6 +22,7 @@ func LoadStudioFile(filePath string) (*Studio, error) {
if err != nil {
return nil, err
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
jsonParser := json.NewDecoder(file)
err = jsonParser.Decode(&studio)
if err != nil {

View File

@@ -2,7 +2,8 @@ package jsonschema
import (
"bytes"
"encoding/json"
"github.com/json-iterator/go"
"io/ioutil"
"time"
)
@@ -25,6 +26,7 @@ func marshalToFile(filePath string, j interface{}) error {
func encode(j interface{}) ([]byte, error) {
buffer := &bytes.Buffer{}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")

View File

@@ -110,13 +110,14 @@ func initFlags() {
}
func initEnvs() {
viper.SetEnvPrefix("stash") // will be uppercased automatically
viper.BindEnv("host") // STASH_HOST
viper.BindEnv("port") // STASH_PORT
viper.BindEnv("stash") // STASH_STASH
viper.BindEnv("generated") // STASH_GENERATED
viper.BindEnv("metadata") // STASH_METADATA
viper.BindEnv("cache") // STASH_CACHE
viper.SetEnvPrefix("stash") // will be uppercased automatically
viper.BindEnv("host") // STASH_HOST
viper.BindEnv("port") // STASH_PORT
viper.BindEnv("external_host") // STASH_EXTERNAL_HOST
viper.BindEnv("stash") // STASH_STASH
viper.BindEnv("generated") // STASH_GENERATED
viper.BindEnv("metadata") // STASH_METADATA
viper.BindEnv("cache") // STASH_CACHE
}
func initFFMPEG() {
@@ -153,9 +154,6 @@ func (s *singleton) RefreshConfig() {
_ = utils.EnsureDir(s.Paths.Generated.Markers)
_ = utils.EnsureDir(s.Paths.Generated.Transcodes)
_ = utils.EnsureDir(s.Paths.JSON.Performers)
_ = utils.EnsureDir(s.Paths.JSON.Scenes)
_ = utils.EnsureDir(s.Paths.JSON.Galleries)
_ = utils.EnsureDir(s.Paths.JSON.Studios)
paths.EnsureJSONDirs()
}
}

Some files were not shown because too many files have changed in this diff Show More