Compare commits
278 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb2bd61f4a | |||
| 3461a4ec74 | |||
| 475c9b6ab4 | |||
| 325666c30d | |||
| 92816b02a0 | |||
| 363c648964 | |||
| 2f929e99d5 | |||
| f14be89680 | |||
| ecd027f603 | |||
| f80f237143 | |||
| dbfc354353 | |||
| 28a6d85672 | |||
| b861cfcec3 | |||
| 08e0021535 | |||
| b3bf111f82 | |||
| 23ed5ffca8 | |||
| cc9f246c9a | |||
| 75d75248e1 | |||
| c34a0878b2 | |||
| 681212566b | |||
| df37de00e1 | |||
| fc900d8e93 | |||
| 57ce143ebe | |||
| 3eb2810a31 | |||
| b8598ba404 | |||
| 579428d86b | |||
| 4da8730b6f | |||
| e980a1f70e | |||
| f73105e9c7 | |||
| 755b08b746 | |||
| 5e412f67b9 | |||
| 4ee38a2625 | |||
| dc6ead0fb3 | |||
| a12faf8e72 | |||
| eb1b8b86c7 | |||
| dca1acbbd8 | |||
| 664caa6ba2 | |||
| a425abcdf2 | |||
| 13b15e03d0 | |||
| 3b4a5a27e6 | |||
| 13bd37c32c | |||
| 2d6d3c005c | |||
| f72f950871 | |||
| e4e015daf8 | |||
| 3db89f3214 | |||
| d379d3f147 | |||
| ac8d8769af | |||
| 7a7bd4f566 | |||
| ca82a36d23 | |||
| 1e6a97202b | |||
| 0e54a8c44a | |||
| 5c4c7be115 | |||
| f458eec732 | |||
| 8ad2208162 | |||
| 28c373173b | |||
| d637e04ba4 | |||
| 5fb92daf0c | |||
| 7f4da2d90e | |||
| 199a97e3a7 | |||
| af04698625 | |||
| a9f928a44c | |||
| 485408390b | |||
| 2bad7bc272 | |||
| 8d0642086c | |||
| 3b0b99ad9a | |||
| c16e0af3b2 | |||
| e0f49f25b2 | |||
| 7561b59037 | |||
| 72932f7acd | |||
| e7751807f6 | |||
| cb97aa3914 | |||
| d1e9a60beb | |||
| 0a09e71af7 | |||
| 404b7c680f | |||
| 9bb4f3f948 | |||
| 52bb995937 | |||
| 624a3b1bbf | |||
| a314231780 | |||
| ba6ae06a5f | |||
| fc4d65ccbc | |||
| d5f8644554 | |||
| 4b0abd13cc | |||
| c62c2cdfc0 | |||
| 8955cacee6 | |||
| 8fbf4ddc6d | |||
| 70f59697d3 | |||
| 22f77aa142 | |||
| 532d3f49c7 | |||
| 3ff325cda9 | |||
| 4e40a9fdb5 | |||
| 81a67404d3 | |||
| 307f5324f0 | |||
| 4a922df7e4 | |||
| d89252c4fe | |||
| 749808cd70 | |||
| 0e4249ee42 | |||
| ce264cbf4a | |||
| 47388d327d | |||
| 26dfad19bc | |||
| dce22cf8e8 | |||
| 230ea306ce | |||
| 36159f5792 | |||
| 50c265de24 | |||
| d408cee754 | |||
| 24f5ea19f5 | |||
| 9c26b6b1d7 | |||
| 7f1c2f2e26 | |||
| b2c24761e0 | |||
| 65d5a581f8 | |||
| 9c17a5fbe7 | |||
| c9b3f26dfe | |||
| e54a99cedd | |||
| d4faaa2e85 | |||
| 5cb0a6c666 | |||
| 0ac70349b4 | |||
| 181ce99746 | |||
| 42dd90579f | |||
| ad51f36a0e | |||
| 0d4fc8a9df | |||
| 0921282de6 | |||
| e785a9a92b | |||
| 2e6acf12e4 | |||
| 94c43b1aac | |||
| c900ea7f0a | |||
| e8ec1c36d1 | |||
| e454f6845b | |||
| 86735e5093 | |||
| bd049e75e2 | |||
| 69a66e2183 | |||
| bf6f87246b | |||
| 85bb71758e | |||
| 333912c694 | |||
| 0c287e0bfa | |||
| e9a7898be5 | |||
| bdf7e0199d | |||
| b6def6f43d | |||
| dbb96177e8 | |||
| 42ac57b0a6 | |||
| c421f63977 | |||
| 91a2aa9648 | |||
| f12e7d8f17 | |||
| f77bc1c125 | |||
| da2a7e3952 | |||
| e5a0609f5b | |||
| 1f216e512c | |||
| bff92b8bce | |||
| f7898326f0 | |||
| efbb1078d6 | |||
| d25692577d | |||
| 01619e1da0 | |||
| 7008e69a90 | |||
| e666d5f332 | |||
| 897cc8a044 | |||
| 6db6149e6b | |||
| 1310c6e996 | |||
| 5ea51c7257 | |||
| ec280dbc20 | |||
| d454b9ff57 | |||
| 978aab0804 | |||
| 0d648372b8 | |||
| 9d25406652 | |||
| 68d15dbd5c | |||
| 69d6f44cc5 | |||
| a996ab9767 | |||
| 4b48d849a5 | |||
| 941fab4b0e | |||
| ce845b5bdb | |||
| 693904a1ba | |||
| 53306bad48 | |||
| 26bcf3491f | |||
| 8f4cf90589 | |||
| 727a8244f4 | |||
| a1810a1f75 | |||
| 808cd50599 | |||
| bfd404cdce | |||
| 927b04acaf | |||
| 3384e6f8b5 | |||
| a73e99f2dc | |||
| 7d5427e656 | |||
| 14b6be0d64 | |||
| 391534dc77 | |||
| 142fef5f43 | |||
| e28aea4497 | |||
| 05855571e1 | |||
| a1b35fa70b | |||
| e69bf8c2ab | |||
| 407e6a5a35 | |||
| 64404eb3a8 | |||
| 7dc956ff89 | |||
| 1ed24be195 | |||
| ba5e690a3d | |||
| 581cbb9917 | |||
| 7395b3b034 | |||
| 234120f6eb | |||
| 4596c34ffd | |||
| 2e53997f9e | |||
| fd309c44bb | |||
| 40ec711f71 | |||
| ad643e6641 | |||
| 62e0911b85 | |||
| 8320d379f7 | |||
| 29a207ed10 | |||
| df3ac430da | |||
| 14eba564cb | |||
| 37a37b83c1 | |||
| 1a6aa30d67 | |||
| f2f2cf4d23 | |||
| bf7a001f26 | |||
| cff7debdad | |||
| 8a271122e9 | |||
| 9019413d81 | |||
| 4775505653 | |||
| cbdf926392 | |||
| 66e2d6a41d | |||
| e3029ff558 | |||
| 8f2a76e9a8 | |||
| 61fa88167c | |||
| 84e86cc256 | |||
| 1a56660523 | |||
| 7b24ff619d | |||
| 2f17d9fcea | |||
| bb0d89b25f | |||
| ddebe11ddc | |||
| f3f182a26c | |||
| 031ae7cf03 | |||
| b094abe69b | |||
| ed32101a76 | |||
| 43da0f82d2 | |||
| 26eadb10b3 | |||
| f9dd7c6c73 | |||
| 78b7f85bd0 | |||
| 4285a51d5a | |||
| 0546faeb6c | |||
| 345a28fcc1 | |||
| b1d5da0451 | |||
| 0115b3f238 | |||
| 9be0420534 | |||
| 4748e891db | |||
| 6e4356ca0a | |||
| 14c54ce92d | |||
| 5ed2650a39 | |||
| c1e81cbab4 | |||
| a0ab7d8413 | |||
| 282255dbea | |||
| fa69639123 | |||
| e177562c5a | |||
| 6d0203c6e1 | |||
| 45921a0c94 | |||
| 18ab577662 | |||
| acb388e271 | |||
| d7dafc8d67 | |||
| 77f73bd03b | |||
| a47952e61d | |||
| 72f8ddc8e6 | |||
| 6a53066b72 | |||
| 9ebc46d7d4 | |||
| 0456eefe3b | |||
| 3b85331f3b | |||
| 56fe1152c5 | |||
| 699f19badb | |||
| e415f77e5a | |||
| 124323cc59 | |||
| ee716a9dc8 | |||
| c4694e577f | |||
| d8f914ddca | |||
| 4d145d593b | |||
| 889aa30150 | |||
| 490192b386 | |||
| 9a9cf1e3fb | |||
| 300b063b9a | |||
| 99be784453 | |||
| 2f6cf1c0db | |||
| 23e686385c | |||
| cbe445b7d9 | |||
| 087071a8af | |||
| a0a74e8cdc | |||
| a16769e0db | |||
| 565d90dbf0 |
@@ -0,0 +1,2 @@
|
||||
server/data/
|
||||
server/Makefile
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
node-version: 20
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#
|
||||
# Backend
|
||||
#
|
||||
FROM golang:1.22-alpine AS server
|
||||
FROM golang:1.25-alpine AS server
|
||||
|
||||
WORKDIR /server
|
||||
COPY server/*.go server/go.* ./
|
||||
COPY server/arr/*.go ./arr/
|
||||
COPY server/game/*.go ./game/
|
||||
|
||||
# We can copy the whole server folder, since our .dockerignore file
|
||||
# will filter out stuff we don't want in the final image.
|
||||
COPY server/ ./
|
||||
|
||||
# Required so we can build with cgo
|
||||
RUN apk update && apk add --no-cache musl-dev gcc build-base
|
||||
@@ -33,7 +34,7 @@ FROM node:20-alpine AS runner
|
||||
|
||||
COPY --from=server /server/watcharr /
|
||||
COPY --from=ui /app/build /ui
|
||||
COPY --from=ui /app/package.json /app/package-lock.json /ui
|
||||
COPY --from=ui /app/package.json /app/package-lock.json /ui/
|
||||
|
||||
# Install just the prod dependencies for final step.
|
||||
# We --ignore-scripts, to stop the `prepare` script from auto-
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Watcharr Features
|
||||
|
||||
A basic top-level view of the features included in Watcharr.
|
||||
|
||||
When the word `watched` is used, assume it can be `played` for games too.
|
||||
|
||||
Have a look at when this document was last updated, it may have missing features.
|
||||
|
||||
- Watched List
|
||||
- Supported Content:
|
||||
- Movies
|
||||
- TV Shows / Anime
|
||||
- Seasons
|
||||
- Episodes
|
||||
- Games
|
||||
- Filtering
|
||||
- Sorting
|
||||
- Pinning
|
||||
- Thoughts (for writing a review, etc)
|
||||
- Activity (detailed list of modifications made to each watched item)
|
||||
- Importing from other services
|
||||
- Content detail pages
|
||||
- Basic overview
|
||||
- Watch trailer
|
||||
- Available streaming providers in your region
|
||||
- Cast
|
||||
- Similar content
|
||||
- Person detail pages
|
||||
- Basic overview
|
||||
- All credits (movies & tv they appear in or worked on)
|
||||
- Searching for content
|
||||
- Custom tags
|
||||
- Discovery page
|
||||
- Following other users
|
||||
- Simple user stats (movies watched, time spent watching, etc)
|
||||
- User Settings
|
||||
- Dark & Light themes
|
||||
- Privacy
|
||||
- Hide Spoilers
|
||||
- Rating System
|
||||
- Out of 5
|
||||
- Out of 10
|
||||
- Out of 100
|
||||
- Rating Step
|
||||
- And more generic settings..
|
||||
- Server dashboard
|
||||
- Basic stats
|
||||
- Configuration editing
|
||||
- User management (including permissions)
|
||||
- Jellyfin Integration
|
||||
- Auth
|
||||
- 'Play On Jellyfin' buttons
|
||||
- Plex Integration
|
||||
- Trusted Header Authentication (for auth via proxy)
|
||||
- Basic Sonarr & Radarr integration
|
||||
- Let users Request content (users can be given an auto approve permission)
|
||||
- Manage content requests
|
||||
@@ -1,21 +1,674 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (c) 2023 IRHM
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
.PHONY: dev version
|
||||
|
||||
dev:
|
||||
./node_modules/.bin/vite dev
|
||||
|
||||
dev_host:
|
||||
./node_modules/.bin/vite dev --host
|
||||
|
||||
# Don't judge me.
|
||||
version:
|
||||
@$(eval VER := $(filter-out $@,$(MAKECMDGOALS)))
|
||||
@echo "Updating version to $(VER)"
|
||||
echo -n "$(VER)" > ./server/VERSION
|
||||
npm version $(VER) --git-tag-version false
|
||||
%:
|
||||
@:
|
||||
@@ -72,6 +72,10 @@ If something isn't working for you or you are stuck, [creating an issue](https:/
|
||||
|
||||
You can also [join our space on Matrix](https://matrix.to/#/#watcharr:matrix.org) for support.
|
||||
|
||||
# License
|
||||
|
||||
This project is licensed under the GPLv3 license. You should see the [LICENSE](LICENSE) file located in the root folder of this project for the full license text, if not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Contributing
|
||||
|
||||
Please continue to our [contributing guide](CONTRIBUTING.md).
|
||||
|
||||
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 114 KiB |
|
After Width: | Height: | Size: 282 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 226 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 6.4 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 711 KiB |
|
After Width: | Height: | Size: 291 KiB |
@@ -0,0 +1,5 @@
|
||||
## Changelog Data
|
||||
|
||||
Changelog images, etc go in this folder.
|
||||
|
||||
[View the real changelog for Watcharr.](../CHANGELOG.md)
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# MyAnimeList
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# Text File (.txt list)
|
||||
|
||||
:::info Backup?
|
||||
You may consider a backup of your server before starting any import. They are not easily reversible, though we do our best to ensure they are accurate and bug free!
|
||||
:::
|
||||
|
||||
The text file (.txt) import is of an arbitrary format (the one I used for years before creating Watcharr).
|
||||
|
||||
Hopefully it is useful for others with similar files or in scenarios where its the easiest to generate for an import (though if possible, when generating a backup from another service data manually, matching a Watcharr export would enable keeping more data).
|
||||
|
||||
## Format
|
||||
|
||||
Each line is a new entry. The name of the content (show/movie) must be provided, the year can be optionally provided surrounded by brackets. Doesn't support specifying if name is for a show or movie, the importer will only automatically match on full search matches, if there are multiple results, you will be asked to pick the correct one.
|
||||
|
||||
```
|
||||
<name> [(<year>)]
|
||||
```
|
||||
|
||||
## An example
|
||||
|
||||
```
|
||||
The Terminator (1984)
|
||||
Breaking Bad
|
||||
A Fistful of Dollars
|
||||
Reacher (2022)
|
||||
```
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# Trakt
|
||||
|
||||
:::info Backup?
|
||||
You may consider a backup of your server before starting any import. They are not easily reversible, though we do our best to ensure they are accurate and bug free!
|
||||
:::
|
||||
|
||||
**Note:** Your Trakt profile must be public _during_ this process. You are free to private it again once it completes.
|
||||
|
||||
1. Provide your Trakt username in the text box.
|
||||
2. (Optional) [Provide your own api key](#optional-api-key).
|
||||
3. Press `Start Import`.
|
||||
|
||||
This will be a long process, possibly a couple hours depending on how large of a Trakt history you have. If you think it has frozen or isn't working, try checking your server logs to see if it is doing anything.
|
||||
|
||||
### (Optional) API Key
|
||||
|
||||
This step is optional because Watcharr comes built in with its own API Key that it can use for your import, however, if you encounter any issues where imports cannot start or keep failing and you see any `403` errors in your server logs, providing your own key may fix the problem.
|
||||
|
||||
#### Getting an API Key
|
||||
|
||||
1. [Visit this link to create a new Trakt API App](https://trakt.tv/oauth/applications/new).
|
||||
2. Fill out all required fields (`Name` and `Redirect uri`) with any random data.
|
||||
1. You can set the `Redirect uri` to any value the input accepts since we don't use it (eg: `http://localhost`)
|
||||
3. Click `Save App`.
|
||||
4. You should now be redirected to your new app. Copy the `Client ID` into the `API Key` textbox in Watcharr.
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
sidebar_position: 0
|
||||
---
|
||||
|
||||
# Watcharr
|
||||
|
||||
:::info Backup?
|
||||
You may consider a backup of your server before starting any import. They are not easily reversible, though we do our best to ensure they are accurate and bug free!
|
||||
:::
|
||||
|
||||
:::warning May not be what you want
|
||||
Watcharr import/export is a feature intended for end users. If you are the server admin, it is recommended that you copy your server files directly to any new server you are creating (it'll be much faster and easier). [See backup guide](/docs/server_config/backup).
|
||||
:::
|
||||
|
||||
1. Provide the Watcharr export file (that you generated from your profile page).
|
||||
2. Review the import table, if everything looks good, start the import.
|
||||
@@ -35,7 +35,7 @@ Backing up this way is discouraged because new important files could be added la
|
||||
|
||||
If you don't care about the warning not to backup this way, here are the "important" files that you can single out for backup:
|
||||
|
||||
- `watcharr.db` Your database, holds all users, their watchlists, etc.
|
||||
- `watcharr.db` & `watcharr.db-wal` Your database, holds all users, their watchlists, etc.
|
||||
- `watcharr.json` Server config.
|
||||
- `img/up` Profile picture uploads.
|
||||
- `img/games` Game posters (not exactly important, but scenarios in which this folder is not backed up have not been tested, only relevant for servers with game support enabled).
|
||||
|
||||
@@ -14,17 +14,17 @@
|
||||
"write-heading-ids": "docusaurus write-heading-ids"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.1.1",
|
||||
"@docusaurus/preset-classic": "3.1.1",
|
||||
"@mdx-js/react": "^3.0.0",
|
||||
"clsx": "^2.1.0",
|
||||
"prism-react-renderer": "^2.3.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"viewerjs": "^1.11.6"
|
||||
"@docusaurus/core": "3.9.2",
|
||||
"@docusaurus/preset-classic": "3.9.2",
|
||||
"@mdx-js/react": "^3.1.1",
|
||||
"clsx": "^2.1.1",
|
||||
"prism-react-renderer": "^2.4.1",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"viewerjs": "^1.11.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.1.1"
|
||||
"@docusaurus/module-type-aliases": "3.9.2"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
@@ -39,6 +39,6 @@
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0"
|
||||
"node": ">=20.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from "react";
|
||||
import clsx from "clsx";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
@@ -8,18 +7,18 @@ const FeatureList = [
|
||||
Svg: require("@site/static/img/icon/code-slash.svg").default,
|
||||
description: (
|
||||
<>
|
||||
Watcharr is free and open source software distributed under the MIT
|
||||
license. Feel free to browse, modify or contribute!
|
||||
Free and open source, distributed under the GPLv3 license. Feel free to
|
||||
browse, modify or contribute!
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "Simple",
|
||||
title: "Simple & Intuitive",
|
||||
Svg: require("@site/static/img/icon/happy.svg").default,
|
||||
description: (
|
||||
<>
|
||||
Watcharr is incredibly easy to dive into. Install without hassle and get
|
||||
started with the seamless and intuitive user experience.
|
||||
Incredibly easy to dive into. Install within the minute and get started
|
||||
with the seamless experience.
|
||||
</>
|
||||
),
|
||||
},
|
||||
@@ -28,8 +27,8 @@ const FeatureList = [
|
||||
Svg: require("@site/static/img/icon/go.svg").default,
|
||||
description: (
|
||||
<>
|
||||
Don't know what else to add here, so now you know Watcharr is built with
|
||||
Go and Svelte.
|
||||
Don't know what else to add here, so now you know I'm built with Go and
|
||||
Svelte.
|
||||
</>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -39,32 +39,37 @@ export function HomepageTwoColFeats() {
|
||||
<TwoColFeat
|
||||
title="Neat UI"
|
||||
description="We just look lightweight."
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/homepage.png?v=2"
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/homepage.png?v=3"
|
||||
/>
|
||||
<TwoColFeat
|
||||
title="Easy To Use"
|
||||
description="Not much to it, other than ease of use."
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/homepage-poster-change-status.png?v=2"
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/homepage-poster-change-status.png?v=3"
|
||||
/>
|
||||
<TwoColFeat
|
||||
title="In-Depth Details"
|
||||
description="About your favourite content."
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/content-details-page.png?v=2"
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/content-details-page.png?v=3"
|
||||
/>
|
||||
<TwoColFeat
|
||||
title="Personal Stats and Configuration"
|
||||
description="Make it how you like."
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/user-profile.png?v=2"
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/user-profile.png?v=3"
|
||||
/>
|
||||
<TwoColFeat
|
||||
title="Discovery"
|
||||
description="Find the latest trending content."
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/discover-page.png?v=2"
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/discover-page.png?v=3"
|
||||
/>
|
||||
<TwoColFeat
|
||||
title="Dark Theme"
|
||||
description="For you who are still unsatisfied. ;("
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/content-details-page-dark.png?v=2"
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/content-details-page-dark.png?v=3"
|
||||
/>
|
||||
<TwoColFeat
|
||||
title="Cast & Crew"
|
||||
description="What are your favorite actors up to?"
|
||||
imgSrc="https://github.com/sbondCo/Watcharr/raw/dev/screenshot/person-page.png?v=3"
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "watcharr",
|
||||
"version": "2.0.2",
|
||||
"license": "GPL-3.0-only",
|
||||
"version": "3.0.2-dev1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
@@ -10,32 +11,31 @@
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"prepare": "svelte-kit sync",
|
||||
"lint": "prettier --check . && eslint .",
|
||||
"format": "prettier --write .",
|
||||
"server": "cd ./server && MODE=DEV go run ."
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-node": "^5.2.12",
|
||||
"@sveltejs/kit": "^2.16.0",
|
||||
"@sveltejs/kit": "^2.21.0",
|
||||
"@types/papaparse": "^5.3.15",
|
||||
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
||||
"@typescript-eslint/parser": "^8.18.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
||||
"@typescript-eslint/parser": "^8.32.1",
|
||||
"@vite-pwa/sveltekit": "^0.6.6",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-config-prettier": "^10.1.2",
|
||||
"eslint-plugin-svelte": "^2.45.1",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-plugin-svelte": "^3.2.6",
|
||||
"sass": "^1.83.0",
|
||||
"prettier-plugin-svelte": "^3.4.0",
|
||||
"sass": "^1.97.3",
|
||||
"svelte": "^5.17.3",
|
||||
"svelte-check": "^4.1.3",
|
||||
"svelte-eslint-parser": "^0.42.0",
|
||||
"svelte-preprocess": "^6.0.3",
|
||||
"typescript": "^5.7.2",
|
||||
"vite": "^6.0.7"
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.3.5"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.4",
|
||||
"axios": "^1.9.0",
|
||||
"blurhash": "^2.0.5",
|
||||
"papaparse": "^5.4.1"
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 488 KiB After Width: | Height: | Size: 520 KiB |
|
Before Width: | Height: | Size: 342 KiB After Width: | Height: | Size: 510 KiB |
|
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 900 KiB After Width: | Height: | Size: 805 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 997 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 900 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 913 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 989 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 393 KiB |
|
After Width: | Height: | Size: 279 KiB |
|
After Width: | Height: | Size: 777 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 60 KiB |
@@ -0,0 +1,8 @@
|
||||
run:
|
||||
MODE=DEV go run .
|
||||
|
||||
plainrun:
|
||||
go run .
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
@@ -0,0 +1 @@
|
||||
3.0.2-dev1
|
||||
@@ -1,130 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ActivityType string
|
||||
|
||||
// _AUTO activities are for when logic updates something for the user (automations basically).
|
||||
var (
|
||||
ADDED_WATCHED ActivityType = "ADDED_WATCHED"
|
||||
REMOVED_WATCHED ActivityType = "REMOVED_WATCHED"
|
||||
RATING_CHANGED ActivityType = "RATING_CHANGED"
|
||||
STATUS_CHANGED ActivityType = "STATUS_CHANGED"
|
||||
STATUS_CHANGED_AUTO ActivityType = "STATUS_CHANGED_AUTO"
|
||||
THOUGHTS_CHANGED ActivityType = "THOUGHTS_CHANGED"
|
||||
THOUGHTS_REMOVED ActivityType = "THOUGHTS_REMOVED"
|
||||
IMPORTED_WATCHED ActivityType = "IMPORTED_WATCHED"
|
||||
IMPORTED_WATCHED_JF ActivityType = "IMPORTED_WATCHED_JF"
|
||||
IMPORTED_WATCHED_PLEX ActivityType = "IMPORTED_WATCHED_PLEX"
|
||||
IMPORTED_RATING ActivityType = "IMPORTED_RATING" // Imported rating, but with no rating acts as original import of content to old platform (where they are importing from) activity
|
||||
IMPORTED_ADDED_WATCHED ActivityType = "IMPORTED_ADDED_WATCHED" // Imported watched date, so we can save the original watch dates of content from users old platform (where they are importing from).
|
||||
IMPORTED_ADDED_WATCHED_JF ActivityType = "IMPORTED_ADDED_WATCHED_JF"
|
||||
IMPORTED_ADDED_WATCHED_PLEX ActivityType = "IMPORTED_ADDED_WATCHED_PLEX"
|
||||
SEASON_ADDED ActivityType = "SEASON_ADDED"
|
||||
SEASON_ADDED_AUTO ActivityType = "SEASON_ADDED_AUTO"
|
||||
SEASON_ADDED_JF ActivityType = "SEASON_ADDED_JF"
|
||||
SEASON_ADDED_PLEX ActivityType = "SEASON_ADDED_PLEX"
|
||||
SEASON_REMOVED ActivityType = "SEASON_REMOVED"
|
||||
SEASON_RATING_CHANGED ActivityType = "SEASON_RATING_CHANGED"
|
||||
SEASON_STATUS_CHANGED ActivityType = "SEASON_STATUS_CHANGED"
|
||||
SEASON_STATUS_CHANGED_AUTO ActivityType = "SEASON_STATUS_CHANGED_AUTO"
|
||||
EPISODE_ADDED ActivityType = "EPISODE_ADDED"
|
||||
EPISODE_ADDED_JF ActivityType = "EPISODE_ADDED_JF"
|
||||
EPISODE_ADDED_PLEX ActivityType = "EPISODE_ADDED_PLEX"
|
||||
EPISODE_REMOVED ActivityType = "EPISODE_REMOVED"
|
||||
EPISODE_RATING_CHANGED ActivityType = "EPISODE_RATING_CHANGED"
|
||||
EPISODE_STATUS_CHANGED ActivityType = "EPISODE_STATUS_CHANGED"
|
||||
)
|
||||
|
||||
type Activity struct {
|
||||
GormModel
|
||||
// ID of user this activity is linked to, so it can be easily
|
||||
// secured (users can only view their own activities).
|
||||
UserID uint `json:"-" gorm:"not null"`
|
||||
// ID of watched list item this activity is linked to.
|
||||
WatchedID uint `json:"watchedId" gorm:"not null"`
|
||||
// Type of activity.
|
||||
Type ActivityType `json:"type" gorm:"not null"`
|
||||
// Holds custom data (ex, if rating changed, this can
|
||||
// hold new rating - if status changed, this will hold that).
|
||||
Data string `json:"data" gorm:"not null"`
|
||||
// Custom date for the activity, that the user can define.
|
||||
CustomDate *time.Time `json:"customDate,omitempty"`
|
||||
}
|
||||
|
||||
type ActivityAddRequest struct {
|
||||
WatchedID uint `json:"watchedId" binding:"required"`
|
||||
Type ActivityType `json:"type" binding:"required"`
|
||||
Data string `json:"data" binding:"required"`
|
||||
CustomDate *time.Time `json:"customDate,omitempty"`
|
||||
}
|
||||
|
||||
type ActivityUpdateRequest struct {
|
||||
CustomDate time.Time `json:"customDate" binding:"required"`
|
||||
}
|
||||
|
||||
func getActivity(db *gorm.DB, userId uint, watchedId uint) ([]Activity, error) {
|
||||
activity := new([]Activity)
|
||||
res := db.Model(&Activity{}).Where("user_id = ? AND watched_id = ?", userId, watchedId).Find(&activity)
|
||||
if res.Error != nil {
|
||||
slog.Error("Failed getting activity from database", "error", res.Error.Error())
|
||||
return []Activity{}, errors.New("failed getting activity")
|
||||
}
|
||||
return *activity, nil
|
||||
}
|
||||
|
||||
func addActivity(db *gorm.DB, userId uint, ar ActivityAddRequest) (Activity, error) {
|
||||
if ar.WatchedID == 0 {
|
||||
return Activity{}, errors.New("watchedId must be set to add an activity")
|
||||
}
|
||||
activity := Activity{UserID: userId, WatchedID: ar.WatchedID, Type: ar.Type, Data: ar.Data, CustomDate: ar.CustomDate}
|
||||
res := db.Create(&activity)
|
||||
if res.Error != nil {
|
||||
slog.Error("Error adding activity to database", "error", res.Error.Error())
|
||||
return Activity{}, errors.New("failed adding new activity to database")
|
||||
}
|
||||
slog.Debug("Adding activity", "added_activity", activity)
|
||||
return activity, nil
|
||||
}
|
||||
|
||||
func updateActivity(db *gorm.DB, userId uint, id uint, activityUpdateRequest ActivityUpdateRequest) error {
|
||||
if id == 0 {
|
||||
return errors.New("id must be set to update an activity")
|
||||
}
|
||||
if activityUpdateRequest.CustomDate.IsZero() {
|
||||
return errors.New("customDate must be set to update an activity")
|
||||
}
|
||||
res := db.Model(&Activity{}).Where("user_id = ? AND id = ?", userId, id).Update("custom_date", activityUpdateRequest.CustomDate)
|
||||
if res.Error != nil {
|
||||
slog.Error("Error updating activity in database", "error", res.Error.Error())
|
||||
return errors.New("failed updating activity in database")
|
||||
}
|
||||
if res.RowsAffected < 1 {
|
||||
slog.Error("No activities were updated. This may be because the activity doesn't exist or is not owned by the calling user.")
|
||||
return errors.New("failed updating activity in database")
|
||||
}
|
||||
slog.Debug("Updating activity", "updated_activity", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteActivity(db *gorm.DB, userId uint, id uint) error {
|
||||
if id == 0 {
|
||||
return errors.New("an id must be provided to delete an activity")
|
||||
}
|
||||
res := db.Where("user_id = ?", userId).Delete(&Activity{}, id)
|
||||
if res.Error != nil {
|
||||
slog.Error("Error deleting activity in database", "error", res.Error.Error())
|
||||
return errors.New("failed deleting activity in database")
|
||||
}
|
||||
if res.RowsAffected < 1 {
|
||||
slog.Error("No activities were deleted. This may be because the activity doesn't exist or is not owned by the calling user.")
|
||||
return errors.New("failed deleting activity from database")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
|
||||
"github.com/sbondCo/Watcharr/arr"
|
||||
)
|
||||
|
||||
type ArrSettings struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}
|
||||
|
||||
type SonarrSettings struct {
|
||||
ArrSettings
|
||||
QualityProfile int `json:"qualityProfile,omitempty"`
|
||||
RootFolder int `json:"rootFolder,omitempty"`
|
||||
LanguageProfile int `json:"languageProfile,omitempty"`
|
||||
AutomaticSearch bool `json:"automaticSearch"`
|
||||
// TODO eventually separate profiles and root for anime content (i can see diff language profile being useful)
|
||||
}
|
||||
|
||||
func (s *SonarrSettings) safe() SonarrSettings {
|
||||
s.Key = ""
|
||||
return *s
|
||||
}
|
||||
|
||||
type RadarrSettings struct {
|
||||
ArrSettings
|
||||
QualityProfile int `json:"qualityProfile,omitempty"`
|
||||
RootFolder int `json:"rootFolder,omitempty"`
|
||||
AutomaticSearch bool `json:"automaticSearch"`
|
||||
}
|
||||
|
||||
func (s *RadarrSettings) safe() RadarrSettings {
|
||||
s.Key = ""
|
||||
return *s
|
||||
}
|
||||
|
||||
type ArrTestParams struct {
|
||||
Host string `json:"host,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}
|
||||
|
||||
type SonarrTestResponse struct {
|
||||
QualityProfiles []arr.QualityProfile `json:"qualityProfiles"`
|
||||
RootFolders []arr.RootFolder `json:"rootFolders"`
|
||||
LanguageProfiles []arr.LanguageProfile `json:"languageProfiles"`
|
||||
}
|
||||
|
||||
type RadarrTestResponse struct {
|
||||
QualityProfiles []arr.QualityProfile `json:"qualityProfiles"`
|
||||
RootFolders []arr.RootFolder `json:"rootFolders"`
|
||||
LanguageProfiles []arr.LanguageProfile `json:"languageProfiles"`
|
||||
}
|
||||
|
||||
// Response given to users with PERM_REQUEST_CONTENT - should never include sensitive info
|
||||
func testSonarr(p ArrTestParams) (SonarrTestResponse, error) {
|
||||
sonarr := arr.New(arr.SONARR, &p.Host, &p.Key)
|
||||
qps, err := sonarr.GetQualityProfiles()
|
||||
if err != nil {
|
||||
slog.Error("testSonarr failed to get quality profiles!", "error", err)
|
||||
return SonarrTestResponse{}, errors.New("failed to get quality profiles")
|
||||
}
|
||||
rfs, err := sonarr.GetRootFolders()
|
||||
if err != nil {
|
||||
slog.Error("testSonarr failed to get root folders!", "error", err)
|
||||
return SonarrTestResponse{}, errors.New("failed to get root folders")
|
||||
}
|
||||
lps, err := sonarr.GetLangaugeProfiles()
|
||||
if err != nil {
|
||||
slog.Error("testSonarr failed to get language profiles!", "error", err)
|
||||
return SonarrTestResponse{}, errors.New("failed to get language profiles")
|
||||
}
|
||||
return SonarrTestResponse{QualityProfiles: qps, RootFolders: rfs, LanguageProfiles: lps}, nil
|
||||
}
|
||||
|
||||
// Response given to users with PERM_REQUEST_CONTENT - should never include sensitive info
|
||||
func testRadarr(p ArrTestParams) (RadarrTestResponse, error) {
|
||||
radarr := arr.New(arr.RADARR, &p.Host, &p.Key)
|
||||
qps, err := radarr.GetQualityProfiles()
|
||||
if err != nil {
|
||||
slog.Error("testRadarr failed to get quality profiles!", "error", err)
|
||||
return RadarrTestResponse{}, errors.New("failed to get quality profiles")
|
||||
}
|
||||
rfs, err := radarr.GetRootFolders()
|
||||
if err != nil {
|
||||
slog.Error("testRadarr failed to get root folders!", "error", err)
|
||||
return RadarrTestResponse{}, errors.New("failed to get root folders")
|
||||
}
|
||||
return RadarrTestResponse{QualityProfiles: qps, RootFolders: rfs}, nil
|
||||
}
|
||||
|
||||
// TODO any way to simplify (deduplicate/reuse) these methods (and the whole file tbh) would be very good
|
||||
|
||||
// Add sonarr server to config
|
||||
func addSonarr(s SonarrSettings) error {
|
||||
for _, v := range Config.SONARR {
|
||||
if v.Name == s.Name {
|
||||
// Server exists with this name...
|
||||
return errors.New("server with that name already exists")
|
||||
}
|
||||
}
|
||||
Config.SONARR = append(Config.SONARR, s)
|
||||
writeConfig()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edit sonarr server in config
|
||||
func editSonarr(s SonarrSettings) error {
|
||||
for i, v := range Config.SONARR {
|
||||
if v.Name == s.Name {
|
||||
Config.SONARR[i] = s
|
||||
writeConfig()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("can't edit server that does not exist")
|
||||
}
|
||||
|
||||
func rmSonarr(name string) error {
|
||||
for i, v := range Config.SONARR {
|
||||
if v.Name == name {
|
||||
Config.SONARR = append(Config.SONARR[:i], Config.SONARR[i+1:]...)
|
||||
writeConfig()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("can't remove a server that does not exist")
|
||||
}
|
||||
|
||||
func getSonarr(name string) (SonarrSettings, error) {
|
||||
for i, v := range Config.SONARR {
|
||||
if v.Name == name {
|
||||
return Config.SONARR[i], nil
|
||||
}
|
||||
}
|
||||
return SonarrSettings{}, errors.New("server not found")
|
||||
}
|
||||
|
||||
// Get list of sonarr servers without api keys.
|
||||
// Regular users with access to adding to sonarr will request this.
|
||||
func getSonarrsSafe() []SonarrSettings {
|
||||
s := []SonarrSettings{}
|
||||
for _, v := range Config.SONARR {
|
||||
s = append(s, v.safe())
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Add radarr server to config
|
||||
func addRadarr(s RadarrSettings) error {
|
||||
for _, v := range Config.RADARR {
|
||||
if v.Name == s.Name {
|
||||
// Server exists with this name...
|
||||
return errors.New("server with that name already exists")
|
||||
}
|
||||
}
|
||||
Config.RADARR = append(Config.RADARR, s)
|
||||
writeConfig()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edit radarr server in config
|
||||
func editRadarr(s RadarrSettings) error {
|
||||
for i, v := range Config.RADARR {
|
||||
if v.Name == s.Name {
|
||||
Config.RADARR[i] = s
|
||||
writeConfig()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("can't edit server that does not exist")
|
||||
}
|
||||
|
||||
func rmRadarr(name string) error {
|
||||
for i, v := range Config.RADARR {
|
||||
if v.Name == name {
|
||||
Config.RADARR = append(Config.RADARR[:i], Config.RADARR[i+1:]...)
|
||||
writeConfig()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("can't remove a server that does not exist")
|
||||
}
|
||||
|
||||
func getRadarr(name string) (RadarrSettings, error) {
|
||||
for i, v := range Config.RADARR {
|
||||
if v.Name == name {
|
||||
return Config.RADARR[i], nil
|
||||
}
|
||||
}
|
||||
return RadarrSettings{}, errors.New("server not found")
|
||||
}
|
||||
|
||||
// Get list of radarr servers without api keys.
|
||||
// Regular users with access to adding to radarr will request this.
|
||||
func getRadarrsSafe() []RadarrSettings {
|
||||
s := []RadarrSettings{}
|
||||
for _, v := range Config.RADARR {
|
||||
s = append(s, v.safe())
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/robfig/go-cache"
|
||||
)
|
||||
|
||||
// Extension of the `.Get` method for `go-cache`.
|
||||
// This method will simplify our usage so we don't need
|
||||
// to type assert everywhere, this method will handle
|
||||
// everything related to getting the value from cache.
|
||||
// Returns `true` if `rv` was set to the cached value.
|
||||
// Returns `false` if we couldn't get anything from cache.
|
||||
func GetCache(c *cache.Cache, k string, rv any) bool {
|
||||
if val, found := c.Get(k); found {
|
||||
v := reflect.ValueOf(rv)
|
||||
if v.Type().Kind() == reflect.Ptr && v.Elem().CanSet() {
|
||||
v.Elem().Set(reflect.ValueOf(val))
|
||||
slog.Debug("cachefunc: Cache found.", "key", k)
|
||||
return true
|
||||
}
|
||||
slog.Error("cachefunc: Cache not set", "key", k)
|
||||
return false
|
||||
}
|
||||
slog.Debug("cachefunc: Cache not found", "key", k)
|
||||
return false
|
||||
}
|
||||
|
||||
// Create a cache key for our in-mem cache.
|
||||
//
|
||||
// `name` should be the name of the function response we are caching.
|
||||
//
|
||||
// `...u` can be any amount of values that will make this key unique.
|
||||
// Currently supports types:
|
||||
// - `string`
|
||||
// - `map[string]string`
|
||||
// - `int`
|
||||
func CreateCacheKey(name string, u ...any) string {
|
||||
str := name
|
||||
appnd := func(s string) {
|
||||
str += "-" + s
|
||||
}
|
||||
for _, v := range u {
|
||||
switch vv := v.(type) {
|
||||
case string:
|
||||
appnd(vv)
|
||||
case map[string]string:
|
||||
for k, e := range vv {
|
||||
appnd(k + "_" + e)
|
||||
}
|
||||
case int:
|
||||
appnd(strconv.Itoa(vv))
|
||||
default:
|
||||
// This should never happen, but incase of unknown
|
||||
// value passed, hopefully this should make it easier
|
||||
// to catch in logs.
|
||||
str = str + "KEYTYPEERR"
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cfgmodel
|
||||
|
||||
type ArrSettings struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}
|
||||
|
||||
type SonarrSettings struct {
|
||||
ArrSettings
|
||||
QualityProfile int `json:"qualityProfile,omitempty"`
|
||||
RootFolder int `json:"rootFolder,omitempty"`
|
||||
LanguageProfile int `json:"languageProfile,omitempty"`
|
||||
AutomaticSearch bool `json:"automaticSearch"`
|
||||
// TODO eventually separate profiles and root for anime
|
||||
// content (i can see diff language profile being useful)
|
||||
}
|
||||
|
||||
type RadarrSettings struct {
|
||||
ArrSettings
|
||||
QualityProfile int `json:"qualityProfile,omitempty"`
|
||||
RootFolder int `json:"rootFolder,omitempty"`
|
||||
AutomaticSearch bool `json:"automaticSearch"`
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -9,8 +9,10 @@ import (
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/sbondCo/Watcharr/game"
|
||||
"gorm.io/gorm"
|
||||
"github.com/sbondCo/Watcharr/config/cfgmodel"
|
||||
"github.com/sbondCo/Watcharr/logging"
|
||||
"github.com/sbondCo/Watcharr/media/igdb"
|
||||
"github.com/sbondCo/Watcharr/util"
|
||||
)
|
||||
|
||||
var DataPath = func() string {
|
||||
@@ -21,6 +23,24 @@ var DataPath = func() string {
|
||||
return path
|
||||
}()
|
||||
|
||||
type TrustedHeaderAuthSetting struct {
|
||||
// Required: Should header auth be enabled?
|
||||
// This bool exists so header auth can be toggled
|
||||
// easily without having to remove configuration.
|
||||
// To be actually enabled, HEADER_NAME must also
|
||||
// be set.
|
||||
Enabled bool `json:"enabled"`
|
||||
// Required: What is the name of the trusted header
|
||||
// that will contain the logged in users username?
|
||||
HeaderName string `json:"headerName"`
|
||||
// Should the frontend attempt auto login if
|
||||
// trusted header auth is enabled.
|
||||
AutoLogin bool `json:"autoLogin"`
|
||||
// Where can we redirect the user to logout
|
||||
// of the auth service?
|
||||
LogoutUrl string `json:"logoutUrl"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
// Used to sign JWT tokens. Make sure to make
|
||||
// it strong, just like a very long, complicated password.
|
||||
@@ -28,6 +48,7 @@ type ServerConfig struct {
|
||||
|
||||
// Default country for new users. This is used to set the default
|
||||
// region to get correct content streaming providers.
|
||||
// TODO Enforce iso_3166_1 validity (same as tmdb)
|
||||
DEFAULT_COUNTRY string `json:",omitempty"`
|
||||
|
||||
// Optional: Point to your Jellyfin install
|
||||
@@ -58,9 +79,9 @@ type ServerConfig struct {
|
||||
// VERY DANGEROUS if access is not controlled correctly!
|
||||
HEADER_AUTH TrustedHeaderAuthSetting `json:",omitempty"`
|
||||
|
||||
SONARR []SonarrSettings `json:",omitempty"`
|
||||
RADARR []RadarrSettings `json:",omitempty"`
|
||||
TWITCH game.IGDB `json:",omitempty"`
|
||||
SONARR []cfgmodel.SonarrSettings `json:",omitempty"`
|
||||
RADARR []cfgmodel.RadarrSettings `json:",omitempty"`
|
||||
TWITCH igdb.IGDB `json:",omitzero"`
|
||||
|
||||
// Optional: Schedule for tasks.
|
||||
TASK_SCHEDULE map[string]int `json:",omitempty"`
|
||||
@@ -90,7 +111,7 @@ func (c *ServerConfig) GetSafe() ServerConfig {
|
||||
DEBUG: c.DEBUG,
|
||||
SONARR: c.SONARR, // Dont act safe, this contains sonarr api key, needed for config
|
||||
RADARR: c.RADARR, // Dont act safe, this contains radarr api key, needed for config
|
||||
TWITCH: game.IGDB{
|
||||
TWITCH: igdb.IGDB{
|
||||
ClientID: c.TWITCH.ClientID,
|
||||
ClientSecret: c.TWITCH.ClientSecret,
|
||||
}, // Dont act safe, this contains twitch secrets, needed for config
|
||||
@@ -126,47 +147,117 @@ func (c *ServerConfig) Get(s string) (ServerConfigGetByName, error) {
|
||||
return ServerConfigGetByName{}, errors.New("invalid setting")
|
||||
}
|
||||
|
||||
var (
|
||||
// Our server config.. `readConfig` will overwrite from watcharr.json cfg file.
|
||||
Config = ServerConfig{}
|
||||
)
|
||||
|
||||
// Read config file
|
||||
// Calls generateConfig if file doesn't exist
|
||||
func readConfig() error {
|
||||
cfg, err := os.Open(path.Join(DataPath, "watcharr.json"))
|
||||
// Update server config property
|
||||
func (c *ServerConfig) UpdateConfig(k string, v any) error {
|
||||
slog.Debug("updateConfig", "k", k, "v", v)
|
||||
if v == nil {
|
||||
return errors.New("invalid value")
|
||||
}
|
||||
if k == "JELLYFIN_HOST" {
|
||||
c.JELLYFIN_HOST = v.(string)
|
||||
} else if k == "USE_EMBY" {
|
||||
c.USE_EMBY = v.(bool)
|
||||
} else if k == "SIGNUP_ENABLED" {
|
||||
c.SIGNUP_ENABLED = v.(bool)
|
||||
} else if k == "TMDB_KEY" {
|
||||
c.TMDB_KEY = v.(string)
|
||||
} else if k == "DEBUG" {
|
||||
c.DEBUG = v.(bool)
|
||||
logging.SetLevel(c.DEBUG)
|
||||
} else if k == "DEFAULT_COUNTRY" {
|
||||
c.DEFAULT_COUNTRY = v.(string)
|
||||
} else {
|
||||
return errors.New("invalid setting")
|
||||
}
|
||||
err := c.Write()
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
slog.Info("Config file doesn't exist... generating.")
|
||||
if err = generateConfig(); err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
slog.Error("updateConfig: Failed to write updated config!", "error", err)
|
||||
return errors.New("failed to write config")
|
||||
}
|
||||
defer cfg.Close()
|
||||
jsonParser := json.NewDecoder(cfg)
|
||||
if err = jsonParser.Decode(&Config); err != nil {
|
||||
return err
|
||||
}
|
||||
initFromConfig()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ensure required config is provided
|
||||
func initFromConfig() error {
|
||||
if Config.JWT_SECRET == "" {
|
||||
log.Fatal("JWT_SECRET missing from config!")
|
||||
// Write current Config to file
|
||||
func (c *ServerConfig) Write() error {
|
||||
barej, err := json.MarshalIndent(*c, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path.Join(DataPath, "watcharr.json"), barej, 0755)
|
||||
}
|
||||
|
||||
func (c *ServerConfig) SaveTwitchConfig(newt igdb.IGDB) error {
|
||||
// If existing client id and secret are same.. just return here
|
||||
if (c.TWITCH.ClientID != nil && newt.ClientID != nil && c.TWITCH.ClientSecret != nil && newt.ClientSecret != nil) &&
|
||||
*c.TWITCH.ClientID == *newt.ClientID && *c.TWITCH.ClientSecret == *newt.ClientSecret {
|
||||
slog.Info("SaveTwitchConfig: New ClientID and ClientSecret match old ClientID and ClientSecret.. ignoring request to update.")
|
||||
return nil
|
||||
}
|
||||
// Update our config
|
||||
c.TWITCH.ClientID = newt.ClientID
|
||||
c.TWITCH.ClientSecret = newt.ClientSecret
|
||||
c.TWITCH.AccessToken = ""
|
||||
c.TWITCH.AccessTokenExpires = time.Time{}
|
||||
// Try to init again
|
||||
err := c.TWITCH.Init()
|
||||
if err != nil {
|
||||
slog.Error("SaveTwitchConfig failed to initialize TWITCH", "error", err)
|
||||
return errors.New("initialization with credentials failed")
|
||||
}
|
||||
err = c.Write()
|
||||
if err != nil {
|
||||
slog.Error("SaveTwitchConfig failed to write config", "error", err)
|
||||
return errors.New("failed to save config")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ServerConfig) TwitchEnabled() bool {
|
||||
if c.TWITCH.ClientID != nil && c.TWITCH.ClientSecret != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Read config file
|
||||
// Calls generateConfig if file doesn't exist
|
||||
func read() (*ServerConfig, error) {
|
||||
cfgFile, err := os.Open(path.Join(DataPath, "watcharr.json"))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
slog.Info("Config file doesn't exist... generating.")
|
||||
if genCfg, err := generateConfig(); err == nil {
|
||||
return genCfg, nil
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
defer cfgFile.Close()
|
||||
|
||||
c := new(ServerConfig)
|
||||
dec := json.NewDecoder(cfgFile)
|
||||
if err = dec.Decode(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
initFromConfig(c)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Ensure required config is provided
|
||||
func initFromConfig(c *ServerConfig) {
|
||||
if c.JWT_SECRET == "" {
|
||||
log.Fatal("JWT_SECRET missing from config!")
|
||||
}
|
||||
}
|
||||
|
||||
// Generate new barebones watcharr.json config file.
|
||||
// Generates a JWT_SECRET and set default config.
|
||||
func generateConfig() error {
|
||||
key, err := generateString(64)
|
||||
func generateConfig() (*ServerConfig, error) {
|
||||
key, err := util.GenerateString(64)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
cfg := ServerConfig{
|
||||
JWT_SECRET: key,
|
||||
@@ -176,150 +267,17 @@ func generateConfig() error {
|
||||
}
|
||||
barej, err := json.MarshalIndent(cfg, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
Config = cfg
|
||||
return os.WriteFile(path.Join(DataPath, "watcharr.json"), barej, 0755)
|
||||
return &cfg, os.WriteFile(path.Join(DataPath, "watcharr.json"), barej, 0755)
|
||||
}
|
||||
|
||||
// Update server config property
|
||||
func updateConfig(k string, v any) error {
|
||||
slog.Debug("updateConfig", "k", k, "v", v)
|
||||
if v == nil {
|
||||
return errors.New("invalid value")
|
||||
}
|
||||
if k == "JELLYFIN_HOST" {
|
||||
Config.JELLYFIN_HOST = v.(string)
|
||||
} else if k == "USE_EMBY" {
|
||||
Config.USE_EMBY = v.(bool)
|
||||
} else if k == "SIGNUP_ENABLED" {
|
||||
Config.SIGNUP_ENABLED = v.(bool)
|
||||
} else if k == "TMDB_KEY" {
|
||||
Config.TMDB_KEY = v.(string)
|
||||
} else if k == "DEBUG" {
|
||||
Config.DEBUG = v.(bool)
|
||||
setLoggingLevel()
|
||||
} else if k == "DEFAULT_COUNTRY" {
|
||||
Config.DEFAULT_COUNTRY = v.(string)
|
||||
} else {
|
||||
return errors.New("invalid setting")
|
||||
}
|
||||
err := writeConfig()
|
||||
// Get server config.
|
||||
// Reads from config file.
|
||||
func Get() (*ServerConfig, error) {
|
||||
cfg, err := read()
|
||||
if err != nil {
|
||||
slog.Error("updateConfig: Failed to write updated config!", "error", err)
|
||||
return errors.New("failed to write config")
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write current Config to file
|
||||
func writeConfig() error {
|
||||
barej, err := json.MarshalIndent(Config, "", "\t")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path.Join(DataPath, "watcharr.json"), barej, 0755)
|
||||
}
|
||||
|
||||
type ServerFeatures struct {
|
||||
Sonarr bool `json:"sonarr"`
|
||||
Radarr bool `json:"radarr"`
|
||||
Games bool `json:"games"`
|
||||
}
|
||||
|
||||
// Get enabled server functionality from Config.
|
||||
// Mainly so the frontend can store this once and know
|
||||
// which btns should be shown, etc.
|
||||
func getEnabledFeatures(userPerms int) ServerFeatures {
|
||||
var f ServerFeatures
|
||||
if Config.TWITCH.ClientID != nil && Config.TWITCH.ClientSecret != nil {
|
||||
f.Games = true
|
||||
}
|
||||
if hasPermission(userPerms, PERM_REQUEST_CONTENT) {
|
||||
if len(Config.SONARR) > 0 {
|
||||
f.Sonarr = true
|
||||
}
|
||||
if len(Config.RADARR) > 0 {
|
||||
f.Radarr = true
|
||||
}
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func saveTwitchConfig(c game.IGDB) error {
|
||||
// If existing client id and secret are same.. just return here
|
||||
if (Config.TWITCH.ClientID != nil && c.ClientID != nil && Config.TWITCH.ClientSecret != nil && c.ClientSecret != nil) &&
|
||||
*Config.TWITCH.ClientID == *c.ClientID && *Config.TWITCH.ClientSecret == *c.ClientSecret {
|
||||
slog.Info("saveTwitchConfig: New ClientID and ClientSecret match old ClientID and ClientSecret.. ignoring request to update.")
|
||||
return nil
|
||||
}
|
||||
// Update our config
|
||||
Config.TWITCH.ClientID = c.ClientID
|
||||
Config.TWITCH.ClientSecret = c.ClientSecret
|
||||
Config.TWITCH.AccessToken = ""
|
||||
Config.TWITCH.AccessTokenExpires = time.Time{}
|
||||
// Try to init again
|
||||
err := Config.TWITCH.Init()
|
||||
if err != nil {
|
||||
slog.Error("saveTwitchConfig failed to initialize TWITCH", "error", err)
|
||||
return errors.New("initialization with credentials failed")
|
||||
}
|
||||
err = writeConfig()
|
||||
if err != nil {
|
||||
slog.Error("saveTwitchConfig failed to write config", "error", err)
|
||||
return errors.New("failed to save config")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ServerStats struct {
|
||||
Users int64 `json:"users"`
|
||||
PrivateUsers int64 `json:"privateUsers"`
|
||||
WatchedMovies int64 `json:"watchedMovies"`
|
||||
WatchedShows int64 `json:"watchedShows"`
|
||||
WatchedSeasons int64 `json:"watchedSeasons"`
|
||||
MostWatchedMovie Content `json:"mostWatchedMovie"`
|
||||
MostWatchedShow Content `json:"mostWatchedShow"`
|
||||
Activities int64 `json:"activities"`
|
||||
}
|
||||
|
||||
// Collect and return server stats
|
||||
// I cant sql so this the best yall gettin
|
||||
func getServerStats(db *gorm.DB) ServerStats {
|
||||
stats := ServerStats{}
|
||||
resp := db.Model(&User{}).Count(&stats.Users).Where("private = 1").Count(&stats.PrivateUsers)
|
||||
if resp.Error != nil {
|
||||
slog.Error("getServerStats - Users query failed", "error", resp.Error)
|
||||
}
|
||||
resp = db.Model(&WatchedSeason{}).Count(&stats.WatchedSeasons)
|
||||
if resp.Error != nil {
|
||||
slog.Error("getServerStats - WatchedSeasons query failed", "error", resp.Error)
|
||||
}
|
||||
resp = db.Model(&Activity{}).Count(&stats.Activities)
|
||||
if resp.Error != nil {
|
||||
slog.Error("getServerStats - Activities query failed", "error", resp.Error)
|
||||
}
|
||||
resp = db.Joins("JOIN contents ON contents.id = watcheds.content_id AND contents.type = ?", "tv").Find(&Watched{}).Count(&stats.WatchedShows)
|
||||
if resp.Error != nil {
|
||||
slog.Error("getServerStats - WatchedShows query failed", "error", resp.Error)
|
||||
}
|
||||
resp = db.Joins("JOIN contents ON contents.id = watcheds.content_id AND contents.type = ?", "movie").Find(&Watched{}).Count(&stats.WatchedMovies)
|
||||
if resp.Error != nil {
|
||||
slog.Error("getServerStats - WatchedMovies query failed", "error", resp.Error)
|
||||
}
|
||||
|
||||
var w Watched
|
||||
resp = db.Model(&Watched{}).Select("content_id, COUNT(*) AS mag").Joins("JOIN contents ON contents.type = ? AND contents.id = watcheds.content_id", "tv").Group("content_id").Order("mag DESC").Preload("Content").First(&w)
|
||||
if resp.Error != nil {
|
||||
slog.Error("getServerStats - MostWatchedShow query failed", "error", resp.Error)
|
||||
} else {
|
||||
stats.MostWatchedShow = *w.Content
|
||||
}
|
||||
resp = db.Model(&Watched{}).Select("content_id, COUNT(*) AS mag").Joins("JOIN contents ON contents.type = ? AND contents.id = watcheds.content_id", "movie").Group("content_id").Order("mag DESC").Preload("Content").First(&w)
|
||||
if resp.Error != nil {
|
||||
slog.Error("getServerStats - MostWatchedMovie query failed", "error", resp.Error)
|
||||
} else {
|
||||
stats.MostWatchedMovie = *w.Content
|
||||
}
|
||||
return stats
|
||||
return cfg, nil
|
||||
}
|
||||
@@ -1,485 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-contrib/cache/persistence"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
type ContentType string
|
||||
|
||||
const (
|
||||
MOVIE ContentType = "movie"
|
||||
SHOW ContentType = "tv"
|
||||
// Show episode
|
||||
SHOW_EPISODE ContentType = "tv_episode"
|
||||
)
|
||||
|
||||
var ContentStore = persistence.NewInMemoryStore(time.Hour * 24)
|
||||
|
||||
// For storing cached content, so we can serve the basic local data for watched list to work
|
||||
type Content struct {
|
||||
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
TmdbID int `json:"tmdbId" gorm:"uniqueIndex:contentidtotypeidx;not null"`
|
||||
Title string `json:"title"`
|
||||
PosterPath string `json:"poster_path"`
|
||||
Overview string `json:"overview"`
|
||||
Type ContentType `json:"type" gorm:"uniqueIndex:contentidtotypeidx;not null"`
|
||||
ReleaseDate *time.Time `json:"release_date,omitempty"`
|
||||
Popularity float32 `json:"popularity"`
|
||||
VoteAverage float32 `json:"vote_average"`
|
||||
VoteCount uint32 `json:"vote_count"`
|
||||
ImdbID string `json:"imdb_id"`
|
||||
Status string `json:"status"`
|
||||
Budget uint32 `json:"budget"`
|
||||
Revenue uint32 `json:"revenue"`
|
||||
Runtime uint32 `json:"runtime"`
|
||||
NumberOfEpisodes uint32 `json:"numberOfEpisodes"`
|
||||
NumberOfSeasons uint32 `json:"numberOfSeasons"`
|
||||
}
|
||||
|
||||
// onlyUpdate - If we should only update existing row if exists, or false to create/update if not exist.
|
||||
func saveContent(db *gorm.DB, c *Content, onlyUpdate bool) error {
|
||||
slog.Info("Saving content to db", "id", c.TmdbID, "title", c.Title)
|
||||
if c.TmdbID == 0 || c.Title == "" || c.Type == "" {
|
||||
slog.Error("saveContent: content missing id, title or type!", "id", c.TmdbID, "title", c.Title, "type", c.Type)
|
||||
return errors.New("content missing id or title")
|
||||
}
|
||||
var res *gorm.DB
|
||||
if onlyUpdate {
|
||||
// We only want to update an existing row, if it exists.
|
||||
res = db.Model(&Content{}).Where("type = ? AND tmdb_id = ?", c.Type, c.TmdbID).Updates(c)
|
||||
if res.Error != nil {
|
||||
slog.Error("saveContent: Error updating content in database", "error", res.Error.Error())
|
||||
return errors.New("failed to update cached content in database")
|
||||
}
|
||||
} else {
|
||||
// On conflict, update existing row with details incase any were updated/missing.
|
||||
res = db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "tmdb_id"}, {Name: "type"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{
|
||||
"title",
|
||||
"poster_path",
|
||||
"overview",
|
||||
"release_date",
|
||||
"popularity",
|
||||
"vote_average",
|
||||
"vote_count",
|
||||
"imdb_id",
|
||||
"status",
|
||||
"budget",
|
||||
"revenue",
|
||||
"runtime",
|
||||
"number_of_episodes",
|
||||
"number_of_seasons",
|
||||
}),
|
||||
}).Create(&c)
|
||||
if res.Error != nil {
|
||||
// Error if anything but unique contraint error
|
||||
if res.Error != gorm.ErrDuplicatedKey {
|
||||
slog.Error("saveContent: Error creating content in database", "error", res.Error.Error())
|
||||
return errors.New("failed to cache content in database")
|
||||
}
|
||||
}
|
||||
}
|
||||
// If row created, download the image
|
||||
if res.RowsAffected > 0 {
|
||||
slog.Debug("saveContent: Downloading poster.")
|
||||
err := download("https://image.tmdb.org/t/p/w500"+c.PosterPath, path.Join(DataPath, "img", c.PosterPath), false)
|
||||
if err != nil {
|
||||
slog.Error("saveContent: Failed to download content image!", "error", err.Error())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cacheContentTv(db *gorm.DB, content TMDBShowDetails, onlyUpdate bool) (Content, error) {
|
||||
slog.Debug("cacheContentTv", "content", content)
|
||||
var (
|
||||
releaseDate time.Time
|
||||
runtime uint32
|
||||
)
|
||||
var dateFormat = "2006-01-02"
|
||||
releaseDate, err := time.Parse(dateFormat, content.FirstAirDate)
|
||||
if err != nil {
|
||||
slog.Error("Failed to parse tv release date", "error", err)
|
||||
}
|
||||
if len(content.EpisodeRunTime) > 0 {
|
||||
runtime = uint32(content.EpisodeRunTime[0])
|
||||
}
|
||||
|
||||
c := Content{
|
||||
TmdbID: content.ID,
|
||||
Title: content.Name,
|
||||
Overview: content.Overview,
|
||||
PosterPath: content.PosterPath,
|
||||
Type: SHOW,
|
||||
ReleaseDate: &releaseDate,
|
||||
Popularity: content.Popularity,
|
||||
VoteAverage: content.VoteAverage,
|
||||
VoteCount: content.VoteCount,
|
||||
Status: content.Status,
|
||||
Runtime: runtime,
|
||||
NumberOfEpisodes: content.NumberOfEpisodes,
|
||||
NumberOfSeasons: content.NumberOfSeasons,
|
||||
}
|
||||
|
||||
err = saveContent(db, &c, onlyUpdate)
|
||||
if err != nil {
|
||||
slog.Error("cacheContentTv: Failed to save content!", "error", err)
|
||||
return Content{}, errors.New("failed to save content")
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func cacheContentMovie(db *gorm.DB, content TMDBMovieDetails, onlyUpdate bool) (Content, error) {
|
||||
var (
|
||||
releaseDate time.Time
|
||||
)
|
||||
var dateFormat = "2006-01-02"
|
||||
// Get details from movie/show response and fill out needed vars
|
||||
releaseDate, err := time.Parse(dateFormat, content.ReleaseDate)
|
||||
if err != nil {
|
||||
slog.Error("Failed to parse movie release date", "error", err)
|
||||
}
|
||||
|
||||
c := Content{
|
||||
TmdbID: content.ID,
|
||||
Title: content.Title,
|
||||
Overview: content.Overview,
|
||||
PosterPath: content.PosterPath,
|
||||
Type: MOVIE,
|
||||
ReleaseDate: &releaseDate,
|
||||
Popularity: content.Popularity,
|
||||
VoteAverage: content.VoteAverage,
|
||||
VoteCount: content.VoteCount,
|
||||
ImdbID: content.ImdbID,
|
||||
Status: content.Status,
|
||||
Budget: content.Budget,
|
||||
Revenue: content.Revenue,
|
||||
Runtime: content.Runtime,
|
||||
}
|
||||
|
||||
err = saveContent(db, &c, onlyUpdate)
|
||||
if err != nil {
|
||||
slog.Error("cacheContentMovie: Failed to save content!", "error", err)
|
||||
return Content{}, errors.New("failed to save content")
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Get content from our cache, or cache it if it doesn't exist.
|
||||
func getOrCacheContent(db *gorm.DB, contentType ContentType, tmdbId int) (Content, error) {
|
||||
var content Content
|
||||
// Look in db for content.
|
||||
db.Where("type = ? AND tmdb_id = ?", contentType, tmdbId).Find(&content)
|
||||
// Create content if not found from our db.
|
||||
if content == (Content{}) {
|
||||
slog.Debug("Content not in db, fetching...", "type", contentType, "tmdbId", tmdbId)
|
||||
|
||||
resp, err := tmdbAPIRequest("/"+string(contentType)+"/"+strconv.Itoa(tmdbId), map[string]string{})
|
||||
if err != nil {
|
||||
slog.Error("getOrCacheContent: content tmdb api request failed", "error", err)
|
||||
return Content{}, errors.New("failed to find requested media")
|
||||
}
|
||||
|
||||
if contentType == "movie" {
|
||||
c := new(TMDBMovieDetails)
|
||||
err := json.Unmarshal([]byte(resp), &c)
|
||||
if err != nil {
|
||||
slog.Error("Failed to unmarshal movie details", "error", err)
|
||||
return Content{}, errors.New("failed to process movie details response")
|
||||
}
|
||||
content, err = cacheContentMovie(db, *c, false)
|
||||
if err != nil {
|
||||
slog.Error("getOrCacheContent: failed to cache movie content", "type", contentType, "content_id", tmdbId, "err", err)
|
||||
return Content{}, errors.New("failed to cache content")
|
||||
}
|
||||
} else {
|
||||
c := new(TMDBShowDetails)
|
||||
err := json.Unmarshal(resp, &c)
|
||||
if err != nil {
|
||||
slog.Error("Failed to unmarshal tv details", "error", err)
|
||||
return Content{}, errors.New("failed to process tv details response")
|
||||
}
|
||||
content, err = cacheContentTv(db, *c, false)
|
||||
if err != nil {
|
||||
slog.Error("getOrCacheContent: failed to cache tv content", "type", contentType, "content_id", tmdbId, "err", err)
|
||||
return Content{}, errors.New("failed to cache content")
|
||||
}
|
||||
}
|
||||
}
|
||||
return content, nil
|
||||
}
|
||||
|
||||
// Getting only region needed from api is not a feature yet
|
||||
// https://trello.com/c/75tR4cpF/106-add-watch-provider-region-filtering
|
||||
// When it is, this can be removed for that instead.
|
||||
func transformProviders(c *interface{}, country string) {
|
||||
slog.Debug("transformProviders called", "country", country)
|
||||
if cmap, ok := (*c).(map[string]interface{}); ok {
|
||||
if rmap, ok := cmap["results"].(map[string]interface{}); ok {
|
||||
if val, ok := rmap[country]; ok {
|
||||
slog.Debug("transformProviders: Found country.. overwriting whole object", "new_obj", val)
|
||||
if rvmap, ok := val.(map[string]interface{}); ok {
|
||||
rvmap["country"] = country
|
||||
}
|
||||
*c = val
|
||||
} else {
|
||||
slog.Warn("transformProviders: Couldn't find country..", "country", country)
|
||||
}
|
||||
} else {
|
||||
slog.Warn("transformProviders: Couldn't find results property..")
|
||||
}
|
||||
} else {
|
||||
slog.Error("transformProviders: Assertion failed")
|
||||
}
|
||||
}
|
||||
|
||||
func searchContent(query string, pageNum int) (TMDBSearchMultiResponse, error) {
|
||||
resp := new(TMDBSearchMultiResponse)
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
err := tmdbRequest("/search/multi", map[string]string{"query": query, "page": strconv.Itoa(pageNum)}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete multi search request!", "error", err.Error())
|
||||
return TMDBSearchMultiResponse{}, errors.New("failed to complete multi search request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func searchMovies(query string, pageNum int) (TMDBSearchMoviesResponse, error) {
|
||||
resp := new(TMDBSearchMoviesResponse)
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
err := tmdbRequest("/search/movie", map[string]string{"query": query, "page": strconv.Itoa(pageNum)}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete movie search request!", "error", err.Error())
|
||||
return TMDBSearchMoviesResponse{}, errors.New("failed to complete movie search request")
|
||||
}
|
||||
for i := range resp.Results {
|
||||
resp.Results[i].MediaType = "movie"
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func searchTv(query string, pageNum int) (TMDBSearchShowsResponse, error) {
|
||||
resp := new(TMDBSearchShowsResponse)
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
err := tmdbRequest("/search/tv", map[string]string{"query": query, "page": strconv.Itoa(pageNum)}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete tv search request!", "error", err.Error())
|
||||
return TMDBSearchShowsResponse{}, errors.New("failed to complete tv search request")
|
||||
}
|
||||
for i := range resp.Results {
|
||||
resp.Results[i].MediaType = "tv"
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func searchPeople(query string, pageNum int) (TMDBSearchPeopleResponse, error) {
|
||||
resp := new(TMDBSearchPeopleResponse)
|
||||
if pageNum == 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
err := tmdbRequest("/search/person", map[string]string{"query": query, "page": strconv.Itoa(pageNum)}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete people search request!", "error", err.Error())
|
||||
return TMDBSearchPeopleResponse{}, errors.New("failed to complete people search request")
|
||||
}
|
||||
for i := range resp.Results {
|
||||
resp.Results[i].MediaType = "person"
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
// Search for content by an external id (imdb, etc).
|
||||
// Defaults to imdb if no source if provided (probably most common).
|
||||
func searchByExternalId(id string, source string) (TMDBSearchMultiResponse, error) {
|
||||
resp := new(TMDBFindByExternalIdResponse)
|
||||
if source == "" {
|
||||
source = "imdb"
|
||||
}
|
||||
err := tmdbRequest("/find/"+id, map[string]string{"external_source": source + "_id"}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete find/external_id request!", "error", err.Error())
|
||||
return TMDBSearchMultiResponse{}, errors.New("failed to complete find/external_id request")
|
||||
}
|
||||
comb := []TMDBSearchMultiResults{}
|
||||
comb = append(comb, resp.MovieResults...)
|
||||
comb = append(comb, resp.TvResults...)
|
||||
comb = append(comb, resp.PersonResults...)
|
||||
comb = append(comb, resp.TvSeasonResults...)
|
||||
comb = append(comb, resp.TvEpisodeResults...)
|
||||
return TMDBSearchMultiResponse{TMDBSearchResponse: TMDBSearchResponse[TMDBSearchMultiResults]{
|
||||
Results: comb,
|
||||
TotalResults: len(comb),
|
||||
// Just providing these so we don't break frontend pagination logic.
|
||||
TotalPages: 1,
|
||||
Page: 1,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func movieDetails(db *gorm.DB, id string, country string, rParams map[string]string) (TMDBMovieDetails, error) {
|
||||
resp := new(TMDBMovieDetails)
|
||||
err := tmdbRequest("/movie/"+id, rParams, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete movie details request!", "error", err.Error())
|
||||
return TMDBMovieDetails{}, errors.New("failed to complete movie details request")
|
||||
}
|
||||
transformProviders(&resp.WatchProviders, country)
|
||||
go cacheContentMovie(db, *resp, true)
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func movieCredits(id string) (TMDBContentCredits, error) {
|
||||
resp := new(TMDBContentCredits)
|
||||
err := tmdbRequest("/movie/"+id+"/credits", map[string]string{}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete movie cast request!", "error", err.Error())
|
||||
return TMDBContentCredits{}, errors.New("failed to complete movie cast request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func tvDetails(db *gorm.DB, id string, country string, rParams map[string]string) (TMDBShowDetails, error) {
|
||||
resp := new(TMDBShowDetails)
|
||||
err := tmdbRequest("/tv/"+id, rParams, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete tv details request!", "error", err.Error())
|
||||
return TMDBShowDetails{}, errors.New("failed to complete tv details request")
|
||||
}
|
||||
transformProviders(&resp.WatchProviders, country)
|
||||
go cacheContentTv(db, *resp, true)
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func tvCredits(id string) (TMDBContentCredits, error) {
|
||||
resp := new(TMDBContentCredits)
|
||||
err := tmdbRequest("/tv/"+id+"/credits", map[string]string{}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete tv cast request!", "error", err.Error())
|
||||
return TMDBContentCredits{}, errors.New("failed to complete tv cast request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
// This method is manually cached, so it can be easily used in other places (on the server) with cache benefits
|
||||
func seasonDetails(tvId string, seasonNumber string) (TMDBSeasonDetails, error) {
|
||||
var cacheKey = "contentstore-seasondetails-" + tvId + "-" + seasonNumber
|
||||
resp := new(TMDBSeasonDetails)
|
||||
if err := ContentStore.Get(cacheKey, &resp); err != nil {
|
||||
if err != persistence.ErrCacheMiss {
|
||||
slog.Error("seasonDetails: Cache failed for some reason", "error", err)
|
||||
}
|
||||
} else {
|
||||
slog.Debug("seasonDetails: Returning cache.")
|
||||
return *resp, nil
|
||||
}
|
||||
err := tmdbRequest("/tv/"+tvId+"/season/"+seasonNumber, map[string]string{}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("seasonDetails: Failed to complete season details request!", "error", err.Error())
|
||||
return TMDBSeasonDetails{}, errors.New("failed to complete season details request")
|
||||
}
|
||||
if err := ContentStore.Set(cacheKey, resp, time.Hour*24); err != nil {
|
||||
slog.Error("seasonDetails: Failed to set cache!", "error", err)
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func personDetails(id string) (TMDBPersonDetails, error) {
|
||||
resp := new(TMDBPersonDetails)
|
||||
err := tmdbRequest("/person/"+id, map[string]string{}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete person details request!", "error", err.Error())
|
||||
return TMDBPersonDetails{}, errors.New("failed to complete person details request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func personCredits(id string) (TMDBPersonCombinedCredits, error) {
|
||||
resp := new(TMDBPersonCombinedCredits)
|
||||
err := tmdbRequest("/person/"+id+"/combined_credits", map[string]string{}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete person details request!", "error", err.Error())
|
||||
return TMDBPersonCombinedCredits{}, errors.New("failed to complete person details request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func discoverMovies() (TMDBDiscoverMovies, error) {
|
||||
resp := new(TMDBDiscoverMovies)
|
||||
err := tmdbRequest("/discover/movie", map[string]string{"page": "1"}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete discover movies request!", "error", err.Error())
|
||||
return TMDBDiscoverMovies{}, errors.New("failed to complete discover movies request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func discoverTv() (TMDBDiscoverShows, error) {
|
||||
resp := new(TMDBDiscoverShows)
|
||||
err := tmdbRequest("/discover/tv", map[string]string{"page": "1"}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete discover tv request!", "error", err.Error())
|
||||
return TMDBDiscoverShows{}, errors.New("failed to complete discover tv request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func allTrending() (TMDBTrendingAll, error) {
|
||||
resp := new(TMDBTrendingAll)
|
||||
err := tmdbRequest("/trending/all/day", map[string]string{}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete all trending request!", "error", err.Error())
|
||||
return TMDBTrendingAll{}, errors.New("failed to complete all trending request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func upcomingMovies() (TMDBUpcomingMovies, error) {
|
||||
resp := new(TMDBUpcomingMovies)
|
||||
err := tmdbRequest("/movie/upcoming", map[string]string{"page": "1"}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete upcoming movies request!", "error", err.Error())
|
||||
return TMDBUpcomingMovies{}, errors.New("failed to complete upcoming movies request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
// Theres no upcoming endpoint for tv ;( - using discover with future dates
|
||||
func upcomingTv() (TMDBUpcomingShows, error) {
|
||||
resp := new(TMDBUpcomingShows)
|
||||
dFmt := "2006-01-02"
|
||||
mind := time.Now().Format(dFmt)
|
||||
maxd := time.Now().AddDate(0, 0, 15).Format(dFmt)
|
||||
err := tmdbRequest("/discover/tv", map[string]string{"page": "1", "first_air_date.gte": mind, "first_air_date.lte": maxd, "sort_by": "popularity.desc", "with_type": "2|3"}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete upcoming tv request!", "error", err.Error())
|
||||
return TMDBUpcomingShows{}, errors.New("failed to complete upcoming tv request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
|
||||
func regions() (TMDBRegions, error) {
|
||||
resp := new(TMDBRegions)
|
||||
err := tmdbRequest("/watch/providers/regions", map[string]string{}, &resp)
|
||||
if err != nil {
|
||||
slog.Error("Failed to complete regions request!", "error", err.Error())
|
||||
return TMDBRegions{}, errors.New("failed to complete regions request")
|
||||
}
|
||||
return *resp, nil
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/sbondCo/Watcharr/config"
|
||||
"github.com/sbondCo/Watcharr/database/entity"
|
||||
"github.com/sbondCo/Watcharr/database/migrate"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Create a new database connection.
|
||||
// Also runs migrations, etc, before returning connection.
|
||||
// Any error returned from this func should always make our app Exit (caller
|
||||
// handled).
|
||||
func New() (*gorm.DB, error) {
|
||||
slog.Info("New: Opening new database connection")
|
||||
// Open the database.
|
||||
db, err := gorm.Open(
|
||||
sqlite.Open(path.Join(config.DataPath, "watcharr.db")),
|
||||
&gorm.Config{TranslateError: true},
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error("New: Opening database failed.")
|
||||
return nil, err
|
||||
}
|
||||
if err := configure(db); err != nil {
|
||||
slog.Error("New: Configuring connection failed!", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
// Perform auto migration.
|
||||
slog.Info("New: AutoMigrating")
|
||||
err = db.AutoMigrate(
|
||||
&migrate.MigrationRecord{},
|
||||
&entity.User{},
|
||||
&entity.UserServices{},
|
||||
&entity.Content{},
|
||||
&entity.Watched{},
|
||||
&entity.WatchedSeason{},
|
||||
&entity.WatchedEpisode{},
|
||||
&entity.Activity{},
|
||||
&entity.Token{},
|
||||
&entity.Follow{},
|
||||
&entity.Image{},
|
||||
&entity.Game{},
|
||||
&entity.ArrRequest{},
|
||||
&entity.Tag{},
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error("New: Auto migration failed.")
|
||||
return nil, err
|
||||
}
|
||||
slog.Info("New: AutoMigrated")
|
||||
// Perform our manual migrations.
|
||||
if err := migrate.Now(db); err != nil {
|
||||
slog.Error("New: Manual migrations failed.", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
// Optimize database.
|
||||
if err := optimize(db); err != nil {
|
||||
slog.Error("New: Optimizing database failed.", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// Configure our SQLite database connection.
|
||||
// Some PRAGMAs need to be defined per-connection, so we do that here.
|
||||
func configure(db *gorm.DB) error {
|
||||
slog.Info("configure: Configuring connection.")
|
||||
|
||||
// Synchronous: https://sqlite.org/pragma.html#pragma_synchronous
|
||||
// Configured to `FULL` because I'm slightly confused.
|
||||
// `NORMAL` is recommended for most apps with WAL, but you
|
||||
// lose "durability", which doesn't sound like a good thing to me...
|
||||
// personally I'm okay with less performance for the best durability.
|
||||
if res := db.Exec("PRAGMA synchronous=2"); res.Error != nil {
|
||||
slog.Error("configure: Configuring synchronous failed!")
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("configure: Configured synchronous.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Optimize the database.
|
||||
func optimize(db *gorm.DB) error {
|
||||
slog.Info("optimize: Running optimizations.")
|
||||
|
||||
// WAL Checkpoint (aka commit anything in the WAL to the main db).
|
||||
// Seems best to do this to make sure it has happened, especially since
|
||||
// we are running vacuum next.
|
||||
// https://sqlite.org/pragma.html#pragma_wal_checkpoint
|
||||
timeBeforeQuery := time.Now()
|
||||
if res := db.Exec("PRAGMA wal_checkpoint(TRUNCATE)"); res.Error != nil {
|
||||
slog.Error("optimize: Checkpoint failed!")
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("optimize: Checkpointed.", "took", time.Since(timeBeforeQuery))
|
||||
|
||||
// Optimize pragma.
|
||||
// Running with recommended argument for our new long-living connection.
|
||||
// https://sqlite.org/pragma.html#pragma_optimize
|
||||
timeBeforeQuery = time.Now()
|
||||
if res := db.Exec("PRAGMA optimize=0x10002"); res.Error != nil {
|
||||
slog.Error("optimize: Optimize pragma failed!")
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("optimize: Optimize pragma succeeded.",
|
||||
"took", time.Since(timeBeforeQuery))
|
||||
|
||||
// Vacuum.
|
||||
// > VACUUM rebuilds the database file, repacking it into a minimal amount
|
||||
// > of disk space.
|
||||
// https://sqlite.org/lang_vacuum.html
|
||||
timeBeforeQuery = time.Now()
|
||||
if res := db.Exec("VACUUM"); res.Error != nil {
|
||||
slog.Error("optimize: Vacuum failed!")
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("optimize: Vacuumed successfully.",
|
||||
"took", time.Since(timeBeforeQuery))
|
||||
|
||||
// WAL Checkpoint (aka commit anything in the WAL to the main db).
|
||||
// Do this after vacuum too to ensure we have a clean slate for this
|
||||
// startup.
|
||||
// https://sqlite.org/pragma.html#pragma_wal_checkpoint
|
||||
timeBeforeQuery = time.Now()
|
||||
if res := db.Exec("PRAGMA wal_checkpoint(TRUNCATE)"); res.Error != nil {
|
||||
slog.Error("optimize: Checkpoint failed!")
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("optimize: Checkpointed.", "took", time.Since(timeBeforeQuery))
|
||||
|
||||
slog.Info("optimize: Done.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Optimize task that is scheduled and ran every whenever.
|
||||
// So this func is for optimzations that we want to re-run every time the
|
||||
// task is scheduled for.
|
||||
func TaskOptimize(db *gorm.DB) error {
|
||||
slog.Info("TaskOptimize: Running optimizations.")
|
||||
|
||||
// WAL Checkpoint (aka commit anything in the WAL to the main db).
|
||||
// To avoid our WAL file becoming huge, we checkpoint regularly.
|
||||
// https://sqlite.org/pragma.html#pragma_wal_checkpoint
|
||||
timeBeforeQuery := time.Now()
|
||||
if res := db.Exec("PRAGMA wal_checkpoint(TRUNCATE)"); res.Error != nil {
|
||||
slog.Error("TaskOptimize: Checkpoint failed!")
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("TaskOptimize: Checkpointed.",
|
||||
"took", time.Since(timeBeforeQuery))
|
||||
|
||||
// Optimize pragma.
|
||||
// No args for our task as recommended.
|
||||
// https://sqlite.org/pragma.html#pragma_optimize
|
||||
timeBeforeQuery = time.Now()
|
||||
if res := db.Exec("PRAGMA optimize"); res.Error != nil {
|
||||
slog.Error("TaskOptimize: Optimize pragma failed!")
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("TaskOptimize: Optimize pragma succeeded.",
|
||||
"took", time.Since(timeBeforeQuery))
|
||||
|
||||
slog.Info("TaskOptimize: Done.")
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dbmodel
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GormModel struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
|
||||
}
|
||||
|
||||
// Same as GormModel, but without the DeletedAt field,
|
||||
// so use this for tables where we don't need soft deletion.
|
||||
type GormModelNoDel struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/sbondCo/Watcharr/database/dbmodel"
|
||||
)
|
||||
|
||||
type ActivityType string
|
||||
|
||||
// _AUTO activities are for when logic updates something for the user (automations basically).
|
||||
var (
|
||||
ADDED_WATCHED ActivityType = "ADDED_WATCHED"
|
||||
REMOVED_WATCHED ActivityType = "REMOVED_WATCHED"
|
||||
RATING_CHANGED ActivityType = "RATING_CHANGED"
|
||||
STATUS_CHANGED ActivityType = "STATUS_CHANGED"
|
||||
STATUS_CHANGED_AUTO ActivityType = "STATUS_CHANGED_AUTO"
|
||||
THOUGHTS_CHANGED ActivityType = "THOUGHTS_CHANGED"
|
||||
THOUGHTS_REMOVED ActivityType = "THOUGHTS_REMOVED"
|
||||
IMPORTED_WATCHED ActivityType = "IMPORTED_WATCHED"
|
||||
IMPORTED_WATCHED_JF ActivityType = "IMPORTED_WATCHED_JF"
|
||||
IMPORTED_WATCHED_PLEX ActivityType = "IMPORTED_WATCHED_PLEX"
|
||||
IMPORTED_RATING ActivityType = "IMPORTED_RATING" // Imported rating, but with no rating acts as original import of content to old platform (where they are importing from) activity
|
||||
IMPORTED_ADDED_WATCHED ActivityType = "IMPORTED_ADDED_WATCHED" // Imported watched date, so we can save the original watch dates of content from users old platform (where they are importing from).
|
||||
IMPORTED_ADDED_WATCHED_JF ActivityType = "IMPORTED_ADDED_WATCHED_JF"
|
||||
IMPORTED_ADDED_WATCHED_PLEX ActivityType = "IMPORTED_ADDED_WATCHED_PLEX"
|
||||
SEASON_ADDED ActivityType = "SEASON_ADDED"
|
||||
SEASON_ADDED_AUTO ActivityType = "SEASON_ADDED_AUTO"
|
||||
SEASON_ADDED_JF ActivityType = "SEASON_ADDED_JF"
|
||||
SEASON_ADDED_PLEX ActivityType = "SEASON_ADDED_PLEX"
|
||||
SEASON_REMOVED ActivityType = "SEASON_REMOVED"
|
||||
SEASON_RATING_CHANGED ActivityType = "SEASON_RATING_CHANGED"
|
||||
SEASON_STATUS_CHANGED ActivityType = "SEASON_STATUS_CHANGED"
|
||||
SEASON_STATUS_CHANGED_AUTO ActivityType = "SEASON_STATUS_CHANGED_AUTO"
|
||||
EPISODE_ADDED ActivityType = "EPISODE_ADDED"
|
||||
EPISODE_ADDED_JF ActivityType = "EPISODE_ADDED_JF"
|
||||
EPISODE_ADDED_PLEX ActivityType = "EPISODE_ADDED_PLEX"
|
||||
EPISODE_REMOVED ActivityType = "EPISODE_REMOVED"
|
||||
EPISODE_RATING_CHANGED ActivityType = "EPISODE_RATING_CHANGED"
|
||||
EPISODE_STATUS_CHANGED ActivityType = "EPISODE_STATUS_CHANGED"
|
||||
)
|
||||
|
||||
type Activity struct {
|
||||
dbmodel.GormModel
|
||||
// ID of user this activity is linked to, so it can be easily
|
||||
// secured (users can only view their own activities).
|
||||
UserID uint `json:"-" gorm:"not null"`
|
||||
// ID of watched list item this activity is linked to.
|
||||
WatchedID uint `json:"watchedId" gorm:"not null"`
|
||||
// Type of activity.
|
||||
Type ActivityType `json:"type" gorm:"not null"`
|
||||
// Holds custom data (ex, if rating changed, this can
|
||||
// hold new rating - if status changed, this will hold that).
|
||||
Data string `json:"data" gorm:"not null"`
|
||||
// Custom date for the activity, that the user can define.
|
||||
CustomDate *time.Time `json:"customDate,omitempty"`
|
||||
// Count this Activity as a Play?
|
||||
// Currently this was the best way I could see forward for implementing
|
||||
// counting plays of media that doesn't involve inefficient querying of
|
||||
// the actitivties table (or a whole new table, which would create extra
|
||||
// complexities itself, ie, plays/activity showing different records).
|
||||
// We write to this field when creating the activity to count is as a play
|
||||
// or not (ie when we create STATUS CHANGE activities with status of
|
||||
// FINISHED, imports, etc).
|
||||
// We won't support the user (or the system) modifying this value after
|
||||
// creation; if the user wants to delete a 'Play', they should delete the
|
||||
// activity.
|
||||
// Indexed (check migrations) to make search faster, since we frequently
|
||||
// do it over the whole table for watched sorting at the moment.
|
||||
CountAsPlay bool `json:"countAsPlay"`
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type ArrRequestStatus string
|
||||
|
||||
const (
|
||||
// Pending approval from an admin.
|
||||
ARR_REQUEST_PENDING ArrRequestStatus = "PENDING"
|
||||
// Request has been approved and should be added to sonarr/radarr.
|
||||
ARR_REQUEST_APPROVED ArrRequestStatus = "APPROVED"
|
||||
ARR_REQUEST_AUTO_APPROVED ArrRequestStatus = "AUTO_APPROVED"
|
||||
// Request has been denied, not adding content.
|
||||
ARR_REQUEST_DENIED ArrRequestStatus = "DENIED"
|
||||
// Content was found on sonarr/radarr already, nothing needs to be done.
|
||||
ARR_REQUEST_FOUND ArrRequestStatus = "FOUND"
|
||||
)
|
||||
|
||||
type ArrRequest struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
UserID uint `json:"-" gorm:"not null"`
|
||||
User User `json:"-"`
|
||||
// Username of `User`.
|
||||
// We don't want to send back the entire user object, just their name.
|
||||
// Not stored in DB, only used for our response from api.
|
||||
Username string `json:"username" gorm:"-"`
|
||||
ContentID *int `json:"-" gorm:"uniqueIndex:sn_to_cid;not null"`
|
||||
Content *Content `json:"content,omitempty"`
|
||||
// Server names are used as an identifier
|
||||
ServerName string `json:"serverName" gorm:"uniqueIndex:sn_to_cid;not null"`
|
||||
// Sonarr/Radarrs seriesId/movieId
|
||||
ArrID int `json:"arrId"`
|
||||
// Tracked request status
|
||||
Status ArrRequestStatus `json:"status" gorm:"default:PENDING"`
|
||||
// Full request made by user (arr.SonarrRequest / arr.RadarrRequest)
|
||||
// so we know how to fulfil the request if approved.
|
||||
RequestJson string `json:"requestJson"`
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
type UserType uint8
|
||||
|
||||
var (
|
||||
WATCHARR_USER UserType = 0
|
||||
JELLYFIN_USER UserType = 1
|
||||
PLEX_USER UserType = 2
|
||||
// Registered via trusted header auth
|
||||
PROXY_USER UserType = 3
|
||||
)
|
||||
|
||||
// User Perms
|
||||
// iota auto increments for us so when adding new
|
||||
// perms, add to bottom as to not change other perm
|
||||
// values.
|
||||
const (
|
||||
PERM_NONE int = 1 << iota
|
||||
PERM_ADMIN
|
||||
PERM_REQUEST_CONTENT
|
||||
PERM_REQUEST_CONTENT_AUTO_APPROVE
|
||||
)
|
||||
|
||||
// Holds third party service auth tokens for users.
|
||||
// Each service may use the fields in their own way.
|
||||
// Unique index applied between service name and clientID
|
||||
// to ensure no duplicates (no need to apply it against
|
||||
// user_id, no accounts should share an integration).
|
||||
//
|
||||
// Plex:
|
||||
// - AuthToken : Used for requests against plex.tv
|
||||
// - AuthToken2 : Used for requests against home plex server.
|
||||
type UserServices struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
// Service/integration name
|
||||
Name string `gorm:"uniqueIndex:svc_name_to_cltid;not null;" json:"-"`
|
||||
// The users id on the third party service
|
||||
ClientID string `gorm:"uniqueIndex:svc_name_to_cltid;not null;" json:"-"`
|
||||
AuthToken string `gorm:"not null;" json:"-"`
|
||||
// Second auth token, generic name so future services can use it without extra confusion.
|
||||
// Ex: We require a second auth token for use with our local server for Plex.
|
||||
AuthToken2 string `json:"-"`
|
||||
UserID uint `gorm:"not null;" json:"-"`
|
||||
}
|
||||
|
||||
type ArgonParams struct {
|
||||
Memory uint32
|
||||
Iterations uint32
|
||||
Parallelism uint8
|
||||
SaltLength uint32
|
||||
KeyLength uint32
|
||||
}
|
||||
|
||||
func GetPassArgonParams() *ArgonParams {
|
||||
return &ArgonParams{
|
||||
Memory: 64 * 1024,
|
||||
Iterations: 3,
|
||||
Parallelism: 2,
|
||||
SaltLength: 16,
|
||||
KeyLength: 32,
|
||||
}
|
||||
}
|
||||
|
||||
type TokenClaims struct {
|
||||
UserID uint `json:"userId"`
|
||||
Username string `json:"username"`
|
||||
Type UserType `json:"type"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/sbondCo/Watcharr/util"
|
||||
)
|
||||
|
||||
type ContentType string
|
||||
|
||||
const (
|
||||
MOVIE ContentType = "movie"
|
||||
SHOW ContentType = "tv"
|
||||
// Show episode
|
||||
SHOW_EPISODE ContentType = "tv_episode"
|
||||
)
|
||||
|
||||
// For storing cached content, so we can serve the basic local data for watched list to work
|
||||
type Content struct {
|
||||
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
TmdbID int `json:"tmdbId" gorm:"uniqueIndex:contentidtotypeidx;not null"`
|
||||
Title string `json:"title"`
|
||||
PosterPath string `json:"poster_path"`
|
||||
Overview string `json:"overview"`
|
||||
Type ContentType `json:"type" gorm:"uniqueIndex:contentidtotypeidx;not null"`
|
||||
ReleaseDate *time.Time `json:"release_date,omitempty"`
|
||||
Popularity float32 `json:"popularity"`
|
||||
VoteAverage float32 `json:"vote_average"`
|
||||
VoteCount uint32 `json:"vote_count"`
|
||||
ImdbID string `json:"imdb_id"`
|
||||
Status string `json:"status"`
|
||||
Budget uint32 `json:"budget"`
|
||||
Revenue uint32 `json:"revenue"`
|
||||
Runtime uint32 `json:"runtime"`
|
||||
NumberOfEpisodes uint32 `json:"numberOfEpisodes"`
|
||||
NumberOfSeasons uint32 `json:"numberOfSeasons"`
|
||||
}
|
||||
|
||||
// NOTE: Can return empty string, so use only when we know that a valid option
|
||||
// will be returned or we are okay with that.
|
||||
func (c *Content) GetTypeSupportedMedia() util.SupportedMedia {
|
||||
if c == nil {
|
||||
return ""
|
||||
}
|
||||
switch c.Type {
|
||||
case MOVIE:
|
||||
return util.SupportedMediaMovie
|
||||
case SHOW:
|
||||
return util.SupportedMediaShow
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
// Database struct, only internal.
|
||||
type Follow struct {
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
UserID uint `gorm:"primaryKey:usr_id_to_followed_id;not null;check:user_id != followed_user_id" json:"-"`
|
||||
User User `json:"-"`
|
||||
FollowedUserID uint `gorm:"primaryKey:usr_id_to_followed_id;not null" json:"-"`
|
||||
FollowedUser User `json:"-"`
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
// For storing cached games, so we can serve the basic local data for watched list to work
|
||||
type Game struct {
|
||||
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
IgdbID int `json:"igdbId" gorm:"uniqueIndex;not null"`
|
||||
Name string `json:"name"`
|
||||
CoverID string `json:"coverId"`
|
||||
Summary string `json:"summary"`
|
||||
Storyline string `json:"storyline"`
|
||||
// First release date
|
||||
ReleaseDate *time.Time `json:"releaseDate,omitempty"`
|
||||
Rating float64 `json:"rating"`
|
||||
RatingCount int `json:"ratingCount"`
|
||||
Status int `json:"status"`
|
||||
Category int `json:"category"`
|
||||
// Arrays turned to strings that may be useful
|
||||
GameModes string `json:"gameModes"`
|
||||
Genres string `json:"genres"`
|
||||
Platforms string `json:"platforms"`
|
||||
// Id to poster image row (cached game cover)
|
||||
PosterID *uint `json:"-"`
|
||||
Poster *Image `json:"poster,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
// For user uploaded images
|
||||
type Image struct {
|
||||
ID uint `gorm:"primarykey" json:"-"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Hash string `gorm:"uniqueIndex;not null" json:"-"`
|
||||
BlurHash string `json:"blurHash"`
|
||||
// Path constructable from hash alone, but I can't decide
|
||||
// if I should have this or not so I figure it's easier
|
||||
// to remove it later than to add it later....... -_-
|
||||
Path string `gorm:"not null" json:"path"`
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package entity
|
||||
|
||||
import "github.com/sbondCo/Watcharr/database/dbmodel"
|
||||
|
||||
type Tag struct {
|
||||
dbmodel.GormModel
|
||||
// ID of user that own this tag.
|
||||
UserID uint `json:"-" gorm:"not null"`
|
||||
// Name of the tag.
|
||||
Name string `json:"name" gorm:"not null"`
|
||||
// Hex of text color.
|
||||
Color string `json:"color"`
|
||||
// Hex of background color.
|
||||
BgColor string `json:"bgColor"`
|
||||
// All watched items.
|
||||
Watched []Watched `json:"watched,omitempty" gorm:"many2many:watched_tags;"`
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type TokenType string
|
||||
|
||||
var (
|
||||
TOKENTYPE_ADMIN TokenType = "ADMIN"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Value string `gorm:"not null"`
|
||||
Type TokenType `gorm:"not null"`
|
||||
UserID uint `gorm:"not null"`
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"github.com/sbondCo/Watcharr/database/dbmodel"
|
||||
)
|
||||
|
||||
// uniqueIndex applied between Username and UserType, so same usernames can exist, but only with different types.
|
||||
// This is incase different users with same name from different services try to signup.
|
||||
type User struct {
|
||||
dbmodel.GormModel
|
||||
Username string `gorm:"uniqueIndex:usr_name_to_type;not null" json:"username" binding:"required"`
|
||||
Password string `gorm:"not null" json:"password" binding:"required"`
|
||||
AvatarID uint `json:"-"`
|
||||
Avatar Image `json:"avatar"`
|
||||
Bio string `json:"bio"`
|
||||
// The type of user/which auth service they originate from.
|
||||
// Empty if from Watcharr, or the name of the service (eg. jellyfin)
|
||||
Type UserType `gorm:"uniqueIndex:usr_name_to_type;not null;default:0" json:"type"`
|
||||
// ID of user from the third party service, this will be used purely for lookup of user at signin.
|
||||
ThirdPartyID string `json:"-"`
|
||||
// Auth token from third party (jellyfin)
|
||||
ThirdPartyAuth string `json:"-"`
|
||||
// Users third party integrations (minus jellyfin for now)
|
||||
UserServices []UserServices `json:"-"`
|
||||
Watched []Watched
|
||||
// All Tags
|
||||
Tags []Tag `json:"-"`
|
||||
// Users permissions
|
||||
Permissions int `gorm:"default:1" json:"-"`
|
||||
// All user settings cols, in another struct for reusability
|
||||
UserSettings
|
||||
}
|
||||
|
||||
func (u *User) GetSafe() PublicUser {
|
||||
return PublicUser{
|
||||
ID: u.ID,
|
||||
Username: u.Username,
|
||||
Avatar: u.Avatar,
|
||||
Bio: u.Bio,
|
||||
}
|
||||
}
|
||||
|
||||
// This struct uses pointer to the values, so in update user settings,
|
||||
// we can tell which setting is being updated (if not nil..).
|
||||
type UserSettings struct {
|
||||
// Is profile private
|
||||
Private *bool `gorm:"default:false" json:"private"`
|
||||
// Are watched list content thoughts public (profile must also be public is false)
|
||||
PrivateThoughts *bool `gorm:"default:false" json:"privateThoughts"`
|
||||
// If ui 'spoilers' should be shown
|
||||
HideSpoilers *bool `gorm:"default:false" json:"hideSpoilers"`
|
||||
// If user wants previously watched items to show in 'Finished' filter,
|
||||
// even if the watched item state has since been changed.
|
||||
// Also if user wants to show in watched stats.
|
||||
IncludePreviouslyWatched *bool `gorm:"default:false" json:"includePreviouslyWatched"`
|
||||
// User's country to get correct content streaming providers.
|
||||
// TODO Enforce iso_3166_1 validity (same as tmdb)
|
||||
Country *string `gorm:"default:'US'" json:"country"`
|
||||
// Does the user want show, season and episode automations enabled.
|
||||
AutomateShowStatuses *bool `gorm:"default:true" json:"automateShowStatuses"`
|
||||
// Rating system user wants to use (frontend only).
|
||||
// RatingSystem enum in frontend maxes out at 3, so just max=3 on this and we should be gut.
|
||||
RatingSystem *int `json:"ratingSystem" binding:"omitempty,max=3"`
|
||||
// Rating step for supported rating systems (frontend only, enum goes up to 2).
|
||||
RatingStep *int `json:"ratingStep" binding:"omitempty,max=2"`
|
||||
}
|
||||
|
||||
// Public user details for search results
|
||||
type PublicUser struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
AvatarID uint `json:"-"`
|
||||
Avatar Image `json:"avatar,omitzero"`
|
||||
Bio string `json:"bio,omitempty"`
|
||||
}
|
||||
|
||||
// Private user details, for returning users details to themselves
|
||||
type PrivateUser struct {
|
||||
Username string `json:"username"`
|
||||
Type UserType `json:"type"`
|
||||
Permissions int `json:"permissions"`
|
||||
AvatarID uint `json:"-"`
|
||||
Avatar Image `json:"avatar"`
|
||||
Bio string `json:"bio"`
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package entity
|
||||
|
||||
import "github.com/sbondCo/Watcharr/database/dbmodel"
|
||||
|
||||
type WatchedStatus string
|
||||
|
||||
const (
|
||||
FINISHED WatchedStatus = "FINISHED"
|
||||
WATCHING WatchedStatus = "WATCHING"
|
||||
PLANNED WatchedStatus = "PLANNED"
|
||||
HOLD WatchedStatus = "HOLD"
|
||||
DROPPED WatchedStatus = "DROPPED"
|
||||
)
|
||||
|
||||
func (r WatchedStatus) IsValid() bool {
|
||||
switch r {
|
||||
case FINISHED,
|
||||
WATCHING,
|
||||
PLANNED,
|
||||
HOLD,
|
||||
DROPPED:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type Watched struct {
|
||||
dbmodel.GormModel
|
||||
Status WatchedStatus `json:"status"`
|
||||
// float so we can support decimal ratings.
|
||||
// Ratings should still always be saved as out of 10.0,
|
||||
// so they can be viewed with any ratings setting in the client.
|
||||
Rating float64 `json:"rating" gorm:"type:numeric(2,1)"`
|
||||
Thoughts string `json:"thoughts"`
|
||||
Pinned bool `json:"pinned" gorm:"default:false;not null"`
|
||||
UserID uint `json:"-" gorm:"uniqueIndex:usernctnidx;uniqueIndex:userngamidx"`
|
||||
ContentID *int `json:"-" gorm:"uniqueIndex:usernctnidx"`
|
||||
Content *Content `json:"content,omitempty"`
|
||||
GameID *int `json:"-" gorm:"uniqueIndex:userngamidx"`
|
||||
Game *Game `json:"game,omitempty"`
|
||||
Activity []Activity `json:"activity"`
|
||||
WatchedSeasons []WatchedSeason `json:"watchedSeasons,omitempty"` // For shows
|
||||
WatchedEpisodes []WatchedEpisode `json:"watchedEpisodes,omitempty"` // For shows
|
||||
Tags []Tag `json:"tags,omitempty" gorm:"many2many:watched_tags;"`
|
||||
// The last season that was viewed by the user for this watched entry.
|
||||
// Only applies to tv shows of course.
|
||||
LastViewedSeason *int `json:"lastViewedSeason,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package entity
|
||||
|
||||
import "github.com/sbondCo/Watcharr/database/dbmodel"
|
||||
|
||||
// UniqueIndex applied between WatchedID, SeasonNum and EpisodeNum to avoid duplicates incase logic fails.
|
||||
//
|
||||
// Episodes on tmdb are only queried by season number + episode number, not possible via episode id,
|
||||
// since episodes can be removed and re-added. For this reason we store season and episodes nums instead
|
||||
// of just the episode id.
|
||||
type WatchedEpisode struct {
|
||||
dbmodel.GormModelNoDel
|
||||
UserID uint `json:"-" gorm:"not null"`
|
||||
User User `json:"-"`
|
||||
WatchedID uint `json:"-" gorm:"uniqueIndex:we_watched_to_ens;not null"`
|
||||
SeasonNumber int `json:"seasonNumber" gorm:"uniqueIndex:we_watched_to_ens;not null"`
|
||||
EpisodeNumber int `json:"episodeNumber" gorm:"uniqueIndex:we_watched_to_ens;not null"`
|
||||
Status WatchedStatus `json:"status"`
|
||||
Rating int8 `json:"rating"`
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package entity
|
||||
|
||||
import "github.com/sbondCo/Watcharr/database/dbmodel"
|
||||
|
||||
// UniqueIndex applied between WatchedID and SeasonNumber to avoid duplicates incase logic fails.
|
||||
type WatchedSeason struct {
|
||||
dbmodel.GormModelNoDel
|
||||
UserID uint `json:"-" gorm:"not null"`
|
||||
User User `json:"-"`
|
||||
WatchedID uint `json:"-" gorm:"uniqueIndex:ws_watched_to_season_num;not null"`
|
||||
SeasonNumber int `json:"seasonNumber" gorm:"uniqueIndex:ws_watched_to_season_num;not null"`
|
||||
Status WatchedStatus `json:"status"`
|
||||
Rating int8 `json:"rating"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package migrate
|
||||
|
||||
import "time"
|
||||
|
||||
// Record of all our applied migrations.
|
||||
type MigrationRecord struct {
|
||||
// Migration ID
|
||||
ID string `gorm:"primarykey"`
|
||||
// When migration was applied on this db.
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Migration struct {
|
||||
// ID of migration, stick to YYYYMMDDHHMM.
|
||||
ID string
|
||||
// Apply migration func.
|
||||
Up func(tx *gorm.DB) error
|
||||
// When `true`, the migration is not run inside of a transaction.
|
||||
// You should only use this when is required by sqlite that the command
|
||||
// we need to run for eg cannot be ran from within a transaction!
|
||||
// YOU SHOULD ENSURE YOU ONLY RUN ONE COMMAND PER MIGRATION WHEN USING
|
||||
// THIS WITH `TRUE` TO AVOID BEING LEFT IN A BAD OR INCOMPLETE STATE!!!
|
||||
//
|
||||
// ALSO: All statements used with this should take into account that since,
|
||||
// it isn't inside of a transaction, it's possible the migration succeeds,
|
||||
// but creating the record of it doesn't. If a user starts the server again
|
||||
// after we error in this case, the migration will run again, so it must
|
||||
// not break data integrity or make any assumptions of it being the first
|
||||
// time running!
|
||||
UNSAFE bool
|
||||
}
|
||||
|
||||
// Start our migrations.
|
||||
// NOTE: This is only to be ran after GORM's AutoMigrate.
|
||||
func Now(db *gorm.DB) error {
|
||||
slog.Info("Starting migrations.")
|
||||
|
||||
for _, mig := range migrations {
|
||||
slog.Debug("Processing migration.", "id", mig.ID)
|
||||
|
||||
migRecord := MigrationRecord{ID: mig.ID}
|
||||
|
||||
// First ensure that the migration hasn't already been applied.
|
||||
var alreadyApplied int64
|
||||
res := db.
|
||||
Model(&MigrationRecord{}).
|
||||
Where(&migRecord).
|
||||
Count(&alreadyApplied)
|
||||
if res.Error != nil {
|
||||
slog.Error("already applied check failed!")
|
||||
return res.Error
|
||||
}
|
||||
if alreadyApplied > 0 {
|
||||
// If record exists in our table, then migration was applied
|
||||
// already, so skip processing it.
|
||||
slog.Debug("Migration already applied.", "id", mig.ID)
|
||||
continue
|
||||
}
|
||||
|
||||
// Timing the migration.
|
||||
timeBeforeMig := time.Now()
|
||||
|
||||
// Apply the migration.
|
||||
if mig.UNSAFE {
|
||||
// Unsafe migrations are not ran inside of a transaction
|
||||
// and are only used when required by sqlite engine.
|
||||
if err := mig.Up(db); err != nil {
|
||||
slog.Error("Migration failed!", "id", mig.ID, "error", err)
|
||||
return err
|
||||
}
|
||||
// Record the migration record.
|
||||
if res := db.Create(&migRecord); res.Error != nil {
|
||||
slog.Error("Unsafe migration succeeded, but we failed to create the record of it!",
|
||||
"id", mig.ID, "error", res.Error)
|
||||
return res.Error
|
||||
}
|
||||
} else {
|
||||
// Migrations go through a transaction wrapper.
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := mig.Up(tx); err != nil {
|
||||
// Errored.. rollback any changes made.
|
||||
return err
|
||||
}
|
||||
// Migration succeeded.. record it.
|
||||
// If the Create succeeds, all will be committed.
|
||||
return tx.Create(&migRecord).Error
|
||||
})
|
||||
if err != nil {
|
||||
// If any migration fails, we return here.
|
||||
slog.Error("Migration failed!", "id", mig.ID, "error", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
slog.Debug("Migration applied successfully.",
|
||||
"id", mig.ID,
|
||||
"duration", time.Since(timeBeforeMig))
|
||||
}
|
||||
|
||||
slog.Info("Done processing all migrations.")
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/sbondCo/Watcharr/database/entity"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// NOTE: For obvious reasons, once a migration is created and in production,
|
||||
// it is set in stone, so there should be almost no reason to change an existing
|
||||
// migration, create a new one instead!
|
||||
// If it's not obvious, changing an existing migration won't apply for people
|
||||
// who already have applied it and only apply for people who haven't yet,
|
||||
// so we are risking splitting the consistency of everyones databases as a
|
||||
// whole. I can't forsee any circumstance that would require doing so..
|
||||
|
||||
var migrations = []Migration{
|
||||
{
|
||||
// Backfilling `plays` data from users Activity.
|
||||
// (we have just created the 'count_as_play' column, instead of starting
|
||||
// existing data from 0 plays, we can check what existing activities
|
||||
// should count, and count them).
|
||||
ID: "202603201715_0001",
|
||||
Up: func(tx *gorm.DB) error {
|
||||
migID := "202603201715_0001"
|
||||
slog.Info("Migration is starting.", "mig", migID)
|
||||
// For ADDED_WATCHED and STATUS_CHANGED activities where the data
|
||||
// holds something saying FINISHED somewhere, count as a play.
|
||||
res := tx.
|
||||
Model(&entity.Activity{}).
|
||||
Where(
|
||||
`type IN ? AND data LIKE "%FINISHED%"`,
|
||||
[]entity.ActivityType{
|
||||
entity.ADDED_WATCHED,
|
||||
entity.STATUS_CHANGED,
|
||||
},
|
||||
).
|
||||
Update("count_as_play", 1)
|
||||
if res.Error != nil {
|
||||
slog.Error("First step failed!", "mig", migID,
|
||||
"error", res.Error)
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("First step succeeded, continuing.", "mig", migID)
|
||||
// For IMPORTED_ADDED_WATCHED* activities, we don't need to check
|
||||
// data (since there isn't any). We know these should always count
|
||||
// as a play, so count them.
|
||||
res = tx.
|
||||
Model(&entity.Activity{}).
|
||||
Where("type IN ?", []entity.ActivityType{
|
||||
entity.IMPORTED_ADDED_WATCHED,
|
||||
// TODO: Should these be here?:
|
||||
entity.IMPORTED_ADDED_WATCHED_JF,
|
||||
entity.IMPORTED_ADDED_WATCHED_PLEX,
|
||||
}).
|
||||
Update("count_as_play", 1)
|
||||
if res.Error != nil {
|
||||
slog.Error("Second step failed!", "mig", migID,
|
||||
"error", res.Error)
|
||||
return res.Error
|
||||
}
|
||||
slog.Info("Second step succeeded, continuing.", "mig", migID)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
// Dropping `deleted_at` columns for `watched_seasons` and
|
||||
// `watched_episodes` tables since we do not use them.
|
||||
ID: "202604142234_0002",
|
||||
Up: func(tx *gorm.DB) error {
|
||||
migID := "202604142234_0002"
|
||||
slog.Info("Migration is starting.", "mig", migID)
|
||||
|
||||
// Drop deleted_at for watched_seasons
|
||||
err := tx.Migrator().DropColumn(&entity.WatchedSeason{}, "deleted_at")
|
||||
if err != nil {
|
||||
slog.Error("watched_seasons migration failed!", "mig", migID)
|
||||
return err
|
||||
}
|
||||
slog.Info("watched_seasons migration succeeded.", "mig", migID)
|
||||
|
||||
// Drop deleted_at for watched_episodes
|
||||
err = tx.Migrator().DropColumn(&entity.WatchedEpisode{}, "deleted_at")
|
||||
if err != nil {
|
||||
slog.Error("watched_episodes migration failed!", "mig", migID)
|
||||
return err
|
||||
}
|
||||
slog.Info("watched_episodes migration succeeded.", "mig", migID)
|
||||
|
||||
slog.Info("Migration complete.", "mig", migID)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
// Moving to using WAL journal_mode for our sqlite database, which
|
||||
// should grant us improvements in all areas.
|
||||
// https://sqlite.org/pragma.html#pragma_journal_mode
|
||||
ID: "202604162229_0003",
|
||||
// NOTE: We are using `unsafe` so that this migration isn't ran inside
|
||||
// of a transaction (can't change into WAL from within one), so we
|
||||
// MUST ENSURE we are only doing one thing!
|
||||
UNSAFE: true,
|
||||
Up: func(db *gorm.DB) error {
|
||||
migID := "202604162229_0003"
|
||||
slog.Info("Migration is starting.", "mig", migID)
|
||||
|
||||
var mode string
|
||||
res := db.Raw("PRAGMA journal_mode=WAL").Scan(&mode)
|
||||
if res.Error != nil {
|
||||
slog.Error("Setting journal_mode=WAL failed!", "mig", migID)
|
||||
return res.Error
|
||||
}
|
||||
// Setting journal_mode might not return an error if it fails,
|
||||
// it always returns the current journal_mode of the db, which
|
||||
// will be WAL if it succeeds OR the "old" journal_mode if it
|
||||
// wasn't changed.
|
||||
// If the mode returned isn't WAL, then something has failed, so
|
||||
// we'll error to stop here and prevent the migration record from
|
||||
// being created, allowing the user to try again.
|
||||
// Note: I was able to test this code by opening the db like this
|
||||
// `sqlite.Open("file:data/watcharr.db?immutable=true")` and
|
||||
// commenting out other code so we get right to this migration
|
||||
// without failing at AutoMigration, etc.
|
||||
slog.Info("journal_mode response.", "mode", mode)
|
||||
if strings.ToLower(mode) != "wal" {
|
||||
slog.Error("Setting journal_mode=WAL failed silently!")
|
||||
return errors.New("Database is not in WAL mode after setting journal_mode=WAL")
|
||||
}
|
||||
slog.Info("WAL journal_mode migration succeeded.", "mig", migID)
|
||||
|
||||
slog.Info("Migration complete.", "mig", migID)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/sbondCo/Watcharr/database/entity"
|
||||
)
|
||||
|
||||
type (
|
||||
// Internal struct accepted by AddActivity function.
|
||||
ActivityAddProps struct {
|
||||
WatchedID uint `json:"watchedId" binding:"required"`
|
||||
Type entity.ActivityType `json:"type" binding:"required"`
|
||||
Data string `json:"data" binding:"required"`
|
||||
CustomDate *time.Time `json:"customDate,omitempty"`
|
||||
}
|
||||
|
||||
ActivityUpdateRequest struct {
|
||||
CustomDate time.Time `json:"customDate" binding:"required"`
|
||||
}
|
||||
|
||||
ActivityAddProvider interface {
|
||||
AddActivity(
|
||||
userId uint,
|
||||
ar ActivityAddProps,
|
||||
countAsPlay bool,
|
||||
) (entity.Activity, error)
|
||||
}
|
||||
)
|
||||
|
||||
// Looks through Activity for Watched entry and calculates the amount
|
||||
// that count as plays.
|
||||
func getPlaysFromActivity(a []entity.Activity) int {
|
||||
plays := 0
|
||||
for i := range a {
|
||||
if a[i].CountAsPlay {
|
||||
plays++
|
||||
}
|
||||
}
|
||||
return plays
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type ContentDetailsResponse struct {
|
||||
Media
|
||||
}
|
||||
|
||||
type PersonCreditsResponse struct {
|
||||
Credits []Media `json:"credits,omitempty"`
|
||||
}
|
||||
|
||||
type PersonDetailsResponse struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Birthday time.Time `json:"birthday,omitzero"`
|
||||
Deathday time.Time `json:"deathday,omitzero"`
|
||||
Age int `json:"age,omitempty"`
|
||||
PlaceOfBirth string `json:"placeOfBirth,omitempty"`
|
||||
KnownForDepartment string `json:"knownForDepartment,omitempty"`
|
||||
Biography string `json:"biography,omitempty"`
|
||||
ExtPosterPath string `json:"extPosterPath,omitempty"`
|
||||
Homepage string `json:"homepage,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/sbondCo/Watcharr/util"
|
||||
)
|
||||
|
||||
type DiscoverFilter string
|
||||
|
||||
const (
|
||||
// Generic "What's Trending?" (all)
|
||||
DiscoverFilterTrending DiscoverFilter = "trending"
|
||||
// Popular stuff (basically trending but over months instead of just a day).
|
||||
DiscoverFilterPopular DiscoverFilter = "popular"
|
||||
// Upcoming content (all).
|
||||
DiscoverFilterUpcoming DiscoverFilter = "upcoming"
|
||||
// What's streaming (movies/tv).
|
||||
DiscoverFilterStreaming DiscoverFilter = "streaming"
|
||||
// What's in theatres (movies).
|
||||
DiscoverFilterInTheatres DiscoverFilter = "intheatres"
|
||||
)
|
||||
|
||||
type DiscoverRequest struct {
|
||||
// The type of content we want to discover.
|
||||
// Reusing the SearchType enum here, but if this needs to diverge,
|
||||
// then make our own enum in this file.
|
||||
Type SearchType `form:"type" binding:"validsearchtype"`
|
||||
// A main filter.
|
||||
// Not every `Type` of discover will support all Filters (service funcs
|
||||
// will error individually based on what they support).
|
||||
Filter DiscoverFilter `form:"filter" binding:"validdiscoverfilter"`
|
||||
}
|
||||
|
||||
// Extra data that we provide to the Discover service func.
|
||||
type DiscoverRequestMeta struct {
|
||||
PageParams util.PaginationParams
|
||||
Region string
|
||||
}
|
||||
|
||||
type DiscoverResponse struct {
|
||||
util.PaginationResponse[Media, util.None]
|
||||
}
|
||||
|
||||
var ValidDiscoverFilter validator.Func = func(fl validator.FieldLevel) bool {
|
||||
st, ok := fl.Field().Interface().(DiscoverFilter)
|
||||
if ok {
|
||||
switch st {
|
||||
case DiscoverFilterTrending,
|
||||
DiscoverFilterPopular,
|
||||
DiscoverFilterUpcoming,
|
||||
DiscoverFilterStreaming,
|
||||
DiscoverFilterInTheatres:
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/sbondCo/Watcharr/database/entity"
|
||||
"github.com/sbondCo/Watcharr/util"
|
||||
)
|
||||
|
||||
type ImportContentType string
|
||||
|
||||
const (
|
||||
ImportContentTypeMovie ImportContentType = "movie"
|
||||
ImportContentTypeShow ImportContentType = "tv"
|
||||
ImportContentTypeShowEpisode ImportContentType = "tv_episode"
|
||||
ImportContentTypeGame ImportContentType = "game"
|
||||
)
|
||||
|
||||
func ImportContentTypeToSearchType(t ImportContentType) SearchType {
|
||||
switch t {
|
||||
case ImportContentTypeMovie:
|
||||
return SearchTypeMovie
|
||||
case ImportContentTypeShow:
|
||||
return SearchTypeShow
|
||||
case ImportContentTypeGame:
|
||||
return SearchTypeGame
|
||||
}
|
||||
// Empty string should be caught as an error.
|
||||
return ""
|
||||
}
|
||||
|
||||
type ImportResponseType string
|
||||
|
||||
var (
|
||||
// Successful import
|
||||
IMPORT_SUCCESS ImportResponseType = "IMPORT_SUCCESS"
|
||||
// Import failed for reasons user cant fix
|
||||
IMPORT_FAILED ImportResponseType = "IMPORT_FAILED"
|
||||
// Import query returned multiple results, user must decide
|
||||
IMPORT_MULTI ImportResponseType = "IMPORT_MULTI"
|
||||
// Import query returned zero results, user must provide more info
|
||||
IMPORT_NOTFOUND ImportResponseType = "IMPORT_NOTFOUND"
|
||||
// Item already exists so couldn't import (unique constraint hit when adding)
|
||||
IMPORT_EXISTS ImportResponseType = "IMPORT_EXISTS"
|
||||
)
|
||||
|
||||
type ImportRequest struct {
|
||||
TmdbID int `json:"tmdbId"`
|
||||
ImdbID string `json:"imdbId"`
|
||||
IgdbID int `json:"igdbId"`
|
||||
|
||||
Name string `json:"name"`
|
||||
Year int `json:"year"`
|
||||
Type ImportContentType `json:"type"`
|
||||
Rating float64 `json:"rating" binding:"max=10"`
|
||||
RatingCustomDate *time.Time `json:"ratingCustomDate"`
|
||||
Status entity.WatchedStatus `json:"status"`
|
||||
Thoughts string `json:"thoughts"`
|
||||
DatesWatched []time.Time `json:"datesWatched"`
|
||||
Activity []entity.Activity `json:"activity"`
|
||||
WatchedEpisodes []entity.WatchedEpisode `json:"watchedEpisodes"`
|
||||
WatchedSeason []entity.WatchedSeason `json:"watchedSeasons"`
|
||||
Tags []TagAddRequest `json:"tags"`
|
||||
}
|
||||
|
||||
// Internal struct given to the SuccessfulImport function.
|
||||
type SuccessfulImportProps struct {
|
||||
TmdbID int
|
||||
IgdbID int
|
||||
ContentType util.SupportedMedia
|
||||
}
|
||||
|
||||
func NewSuccessfulImportPropsFromMedia(m *Media) (SuccessfulImportProps, error) {
|
||||
p := SuccessfulImportProps{ContentType: m.GetMediaType()}
|
||||
switch p.ContentType {
|
||||
case util.SupportedMediaMovie, util.SupportedMediaShow:
|
||||
p.TmdbID = m.IDs.TMDB
|
||||
case util.SupportedMediaGame:
|
||||
p.IgdbID = m.IDs.IGDB
|
||||
default:
|
||||
return p, errors.New("unsupported content type on media")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
type ImportResponse struct {
|
||||
Type ImportResponseType `json:"type"`
|
||||
Results []Media `json:"results,omitempty"`
|
||||
Match Media `json:"match,omitzero"`
|
||||
// On success this will be filled with the new watched entry
|
||||
WatchedEntry entity.Watched `json:"watchedEntry,omitzero"`
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
// Types that we can use for all content types (movie, tv, game, everything).
|
||||
// Data responses to the client can use these "uniform" types to make access
|
||||
// easier.
|
||||
|
||||
package domain
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/sbondCo/Watcharr/database/entity"
|
||||
"github.com/sbondCo/Watcharr/util"
|
||||
)
|
||||
|
||||
type MediaType string
|
||||
|
||||
const (
|
||||
MediaTypeTMDBMovie MediaType = "tmdb_movie"
|
||||
MediaTypeTMDBShow MediaType = "tmdb_tv"
|
||||
MediaTypeTMDBPerson MediaType = "tmdb_person"
|
||||
|
||||
MediaTypeIGDBGame MediaType = "igdb_game"
|
||||
)
|
||||
|
||||
type Media struct {
|
||||
// The type of media.
|
||||
Type MediaType `json:"type,omitempty"`
|
||||
// The ids associated with this media.
|
||||
IDs MediaIDs `json:"ids"`
|
||||
// The name of the media.
|
||||
Name string `json:"name,omitempty"`
|
||||
// A description.
|
||||
Summary string `json:"summary,omitempty"`
|
||||
// The poster.
|
||||
Poster *entity.Image `json:"poster,omitempty"`
|
||||
// The external poster path.
|
||||
ExtPosterPath string `json:"extPosterPath,omitempty"`
|
||||
// The rating.
|
||||
Rating uint `json:"rating,omitempty"`
|
||||
// The amount of votes that made up the rating.
|
||||
RatingCount uint `json:"ratingCount,omitempty"`
|
||||
// Watched data.
|
||||
Watched WatchedDto `json:"watched,omitzero"`
|
||||
// Similar media.
|
||||
Similar []Media `json:"similar,omitempty"`
|
||||
// Release date / first air date.
|
||||
ReleaseDate time.Time `json:"releaseDate,omitzero"`
|
||||
// Videos (trailers, etc)
|
||||
Videos []MediaVideo `json:"videos,omitempty"`
|
||||
|
||||
//
|
||||
// Properties that are less important (not used for all responses).
|
||||
//
|
||||
|
||||
// Backdrop path.
|
||||
ExtBackdropPath string `json:"extBackdropPath,omitempty"`
|
||||
// Genres.
|
||||
Genres []MediaGenre `json:"genres,omitempty"`
|
||||
// Media website.
|
||||
Homepage string `json:"homepage,omitempty"`
|
||||
// Media providers (eg Streaming sites, game markets)
|
||||
Providers []MediaProvider `json:"providers,omitempty"`
|
||||
// A link to the database we are using that lists all providers with max details.
|
||||
// (especially for TMDB since it's data from JustWatch isn't available to us).
|
||||
ProvidersFullListLink string `json:"providersFullListLink,omitempty"`
|
||||
|
||||
//
|
||||
// Properties only for movies/tv.
|
||||
//
|
||||
|
||||
// Runtime.
|
||||
Runtime uint `json:"runtime,omitempty"`
|
||||
// Seasons.
|
||||
Seasons []MediaSeason `json:"seasons,omitempty"`
|
||||
// Simple bool for our RequestShow component since Sonarr can be given a
|
||||
// series type (ideally the frontend doesn't need to do that, but for now it
|
||||
// does.. if (son)arr code is refactored, can the client just pass very basic
|
||||
// details for the server to fetch fully/verify, i.e fetched full details from
|
||||
// tmdb again to verify if show is anime itself, etc).
|
||||
IsShowAnime bool `json:"isShowAnime,omitempty"`
|
||||
|
||||
//
|
||||
// Properties only for Games
|
||||
//
|
||||
|
||||
// Game modes.
|
||||
GameModes []MediaGenre `json:"gameModes,omitempty"`
|
||||
}
|
||||
|
||||
func (t Media) GetId() int {
|
||||
switch t.Type {
|
||||
case MediaTypeTMDBMovie,
|
||||
MediaTypeTMDBShow:
|
||||
return t.IDs.TMDB
|
||||
case MediaTypeIGDBGame:
|
||||
return t.IDs.IGDB
|
||||
}
|
||||
return -99
|
||||
}
|
||||
|
||||
// If this changes, verify all use cases still make sense!
|
||||
func (t Media) GetMediaType() util.SupportedMedia {
|
||||
switch t.Type {
|
||||
case MediaTypeTMDBMovie:
|
||||
return util.SupportedMediaMovie
|
||||
case MediaTypeTMDBShow:
|
||||
return util.SupportedMediaShow
|
||||
case MediaTypeIGDBGame:
|
||||
return util.SupportedMediaGame
|
||||
}
|
||||
// Unsupported...
|
||||
slog.Warn("GetMediaType: Requested, but unsupported type encountered.",
|
||||
"type", t.Type)
|
||||
return ""
|
||||
}
|
||||
|
||||
type MediaIDs struct {
|
||||
// The internal ID
|
||||
// Watcharr uint
|
||||
|
||||
// For tmdb data
|
||||
TMDB int `json:"tmdb,omitempty"`
|
||||
IMDB string `json:"imdb,omitempty"`
|
||||
Wikidata string `json:"wikidata,omitempty"`
|
||||
TVDB int `json:"tvdb,omitempty"`
|
||||
|
||||
// For igdb data
|
||||
IGDB int `json:"igdb,omitempty"`
|
||||
}
|
||||
|
||||
type MediaGenre struct {
|
||||
// ID of the genre on the external database.
|
||||
ID uint `json:"id,omitempty"`
|
||||
// Name of genre.
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type MediaSeason struct {
|
||||
// Season number (doesn't omit empty to keep support for season 0).
|
||||
Number int `json:"number"`
|
||||
// Season name.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Season air date.
|
||||
ReleaseDate time.Time `json:"releaseDate,omitzero"`
|
||||
// Number of episodes in season.
|
||||
EpisodeCount int `json:"episodeCount"`
|
||||
}
|
||||
|
||||
// Create Media dto from Watched entity.
|
||||
func NewMediaFromWatched(w *entity.Watched, watchedDto *WatchedDto) Media {
|
||||
var media Media
|
||||
|
||||
if w.Content != nil {
|
||||
media = NewMediaFromContent(w.Content)
|
||||
} else if w.Game != nil {
|
||||
media = NewMediaFromGame(w.Game)
|
||||
}
|
||||
|
||||
media.Watched = *watchedDto
|
||||
|
||||
return media
|
||||
}
|
||||
|
||||
// Converter for Content (tv/movie) entity to Media
|
||||
func NewMediaFromContent(c *entity.Content) Media {
|
||||
m := Media{
|
||||
IDs: MediaIDs{
|
||||
TMDB: c.TmdbID,
|
||||
},
|
||||
Name: c.Title,
|
||||
Summary: c.Overview,
|
||||
ExtPosterPath: c.PosterPath,
|
||||
Rating: uint(c.VoteAverage),
|
||||
RatingCount: uint(c.VoteCount),
|
||||
Runtime: uint(c.Runtime),
|
||||
}
|
||||
switch c.Type {
|
||||
case entity.MOVIE:
|
||||
m.Type = MediaTypeTMDBMovie
|
||||
case entity.SHOW:
|
||||
m.Type = MediaTypeTMDBShow
|
||||
}
|
||||
if c.ReleaseDate != nil {
|
||||
m.ReleaseDate = *c.ReleaseDate
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Converter for Game entity to Media
|
||||
func NewMediaFromGame(c *entity.Game) Media {
|
||||
m := Media{
|
||||
IDs: MediaIDs{
|
||||
IGDB: c.IgdbID,
|
||||
},
|
||||
Type: MediaTypeIGDBGame,
|
||||
Name: c.Name,
|
||||
Summary: c.Summary,
|
||||
Poster: c.Poster,
|
||||
ExtPosterPath: c.CoverID,
|
||||
Rating: uint(c.Rating),
|
||||
RatingCount: uint(c.RatingCount),
|
||||
}
|
||||
if c.ReleaseDate != nil {
|
||||
m.ReleaseDate = *c.ReleaseDate
|
||||
}
|
||||
return m
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package domain
|
||||
|
||||
type MediaProviderType string
|
||||
|
||||
const (
|
||||
MediaProviderTypeSub MediaProviderType = "sub"
|
||||
MediaProviderTypeFree MediaProviderType = "free"
|
||||
)
|
||||
|
||||
type MediaProvider struct {
|
||||
// Name of the provider.
|
||||
Name string `json:"name,omitempty"`
|
||||
// The type of service provided by the provider.
|
||||
Type MediaProviderType `json:"type,omitempty"`
|
||||
// Link to watch.
|
||||
// We can't get a direct link to content from tmdb, we are told to link
|
||||
// to tmdb to support them instead and from there the user can see deep links.
|
||||
Link string `json:"link,omitempty"`
|
||||
}
|
||||