feat: initial user list (no edit/delete yet) and job schedules

pull/162/head
sct 4 years ago
parent 320432657e
commit 24a0423f3b

@ -33,6 +33,10 @@ components:
type: string type: string
example: '2020-09-02T05:02:23.000Z' example: '2020-09-02T05:02:23.000Z'
readOnly: true readOnly: true
requests:
type: array
items:
$ref: '#/components/schemas/MediaRequest'
required: required:
- id - id
- email - email

@ -28,6 +28,7 @@
"intl": "^1.2.5", "intl": "^1.2.5",
"lodash": "^4.17.20", "lodash": "^4.17.20",
"next": "9.5.4", "next": "9.5.4",
"node-schedule": "^1.3.2",
"nookies": "^2.4.0", "nookies": "^2.4.0",
"plex-api": "^5.3.1", "plex-api": "^5.3.1",
"react": "16.13.1", "react": "16.13.1",
@ -58,6 +59,7 @@
"@types/express-session": "^1.17.0", "@types/express-session": "^1.17.0",
"@types/lodash": "^4.14.161", "@types/lodash": "^4.14.161",
"@types/node": "^14.10.0", "@types/node": "^14.10.0",
"@types/node-schedule": "^1.3.1",
"@types/react": "^16.9.49", "@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8", "@types/react-dom": "^16.9.8",
"@types/react-toast-notifications": "^2.4.0", "@types/react-toast-notifications": "^2.4.0",

@ -39,7 +39,7 @@ export class User {
public avatar: string; public avatar: string;
@OneToMany(() => MediaRequest, (request) => request.requestedBy) @OneToMany(() => MediaRequest, (request) => request.requestedBy)
public requests: MediaRequest; public requests: MediaRequest[];
@CreateDateColumn() @CreateDateColumn()
public createdAt: Date; public createdAt: Date;

@ -13,6 +13,7 @@ import { OpenApiValidator } from 'express-openapi-validator';
import { Session } from './entity/Session'; import { Session } from './entity/Session';
import { getSettings } from './lib/settings'; import { getSettings } from './lib/settings';
import logger from './logger'; import logger from './logger';
import { startJobs } from './job/schedule';
const API_SPEC_PATH = path.join(__dirname, '../overseerr-api.yml'); const API_SPEC_PATH = path.join(__dirname, '../overseerr-api.yml');
@ -27,6 +28,9 @@ app
// Load Settings // Load Settings
getSettings().load(); getSettings().load();
// Start Jobs
startJobs();
const server = express(); const server = express();
server.use(cookieParser()); server.use(cookieParser());
server.use(bodyParser.json()); server.use(bodyParser.json());

@ -67,7 +67,8 @@ class JobPlexSync {
existing.status = MediaStatus.AVAILABLE; existing.status = MediaStatus.AVAILABLE;
mediaRepository.save(existing); mediaRepository.save(existing);
this.log( this.log(
`Request for ${metadata.title} exists. Setting status AVAILABLE` `Request for ${metadata.title} exists. Setting status AVAILABLE`,
'info'
); );
} else { } else {
newMedia.status = MediaStatus.AVAILABLE; newMedia.status = MediaStatus.AVAILABLE;
@ -90,7 +91,8 @@ class JobPlexSync {
existing.status = MediaStatus.AVAILABLE; existing.status = MediaStatus.AVAILABLE;
await mediaRepository.save(existing); await mediaRepository.save(existing);
this.log( this.log(
`Request for ${plexitem.title} exists. Setting status AVAILABLE` `Request for ${plexitem.title} exists. Setting status AVAILABLE`,
'info'
); );
} else if (tmdbMovie) { } else if (tmdbMovie) {
const newMedia = new Media(); const newMedia = new Media();
@ -139,8 +141,11 @@ class JobPlexSync {
} }
} }
private log(message: string): void { private log(
logger.info(message, { label: 'Plex Sync' }); message: string,
level: 'info' | 'error' | 'debug' = 'debug'
): void {
logger[level](message, { label: 'Plex Sync' });
} }
public async run(): Promise<void> { public async run(): Promise<void> {
@ -160,7 +165,7 @@ class JobPlexSync {
for (const library of this.libraries) { for (const library of this.libraries) {
this.currentLibrary = library; this.currentLibrary = library;
this.log(`Beginning to process library: ${library.name}`); this.log(`Beginning to process library: ${library.name}`, 'info');
this.items = await this.plexClient.getLibraryContents(library.id); this.items = await this.plexClient.getLibraryContents(library.id);
await this.loop(); await this.loop();
} }

@ -0,0 +1,15 @@
import schedule from 'node-schedule';
import jobPlexSync from './plexsync';
import logger from '../logger';
export const scheduledJobs: Record<string, schedule.Job> = {};
export const startJobs = (): void => {
// Run full plex sync every 6 hours
scheduledJobs.plexFullSync = schedule.scheduleJob('* */6 * * *', () => {
logger.info('Starting scheduled job: Plex Full Sync', { label: 'Jobs' });
jobPlexSync.run();
});
logger.info('Scheduled jobs loaded', { label: 'Jobs' });
};

@ -7,7 +7,7 @@ const router = Router();
router.get('/', async (req, res) => { router.get('/', async (req, res) => {
const userRepository = getRepository(User); const userRepository = getRepository(User);
const users = await userRepository.find(); const users = await userRepository.find({ relations: ['requests'] });
return res.status(200).json(User.filterMany(users)); return res.status(200).json(User.filterMany(users));
}); });

@ -0,0 +1,114 @@
import React from 'react';
import useSWR from 'swr';
import LoadingSpinner from '../Common/LoadingSpinner';
import type { User } from '../../../server/entity/User';
import Badge from '../Common/Badge';
import { FormattedDate } from 'react-intl';
import Button from '../Common/Button';
import { hasPermission } from '../../../server/lib/permissions';
import { Permission } from '../../hooks/useUser';
const UserList: React.FC = () => {
const { data, error } = useSWR<User[]>('/api/v1/user');
if (!data && !error) {
return <LoadingSpinner />;
}
return (
<>
<div className="md:flex md:items-center md:justify-between mt-8 mb-6">
<div className="flex-1 min-w-0 mx-4">
<h2 className="text-2xl font-bold leading-7 text-cool-gray-100 sm:text-3xl sm:leading-9 sm:truncate">
User List
</h2>
</div>
</div>
<div className="flex flex-col">
<div className="my-2 overflow-x-auto -mx-6 sm:-mx-6 md:mx-4 lg:mx-4">
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div className="shadow overflow-hidden sm:rounded-lg">
<table className="min-w-full">
<thead>
<tr>
<th className="px-6 py-3 bg-cool-gray-500 text-left text-xs leading-4 font-medium text-gray-200 uppercase tracking-wider">
Name
</th>
<th className="px-6 py-3 bg-cool-gray-500 text-left text-xs leading-4 font-medium text-gray-200 uppercase tracking-wider">
Total Requests
</th>
<th className="px-6 py-3 bg-cool-gray-500 text-left text-xs leading-4 font-medium text-gray-200 uppercase tracking-wider">
User Type
</th>
<th className="px-6 py-3 bg-cool-gray-500 text-left text-xs leading-4 font-medium text-gray-200 uppercase tracking-wider">
Role
</th>
<th className="px-6 py-3 bg-cool-gray-500 text-left text-xs leading-4 font-medium text-gray-200 uppercase tracking-wider">
Created
</th>
<th className="px-6 py-3 bg-cool-gray-500 text-left text-xs leading-4 font-medium text-gray-200 uppercase tracking-wider">
Last Updated
</th>
<th className="px-6 py-3 bg-cool-gray-500"></th>
</tr>
</thead>
<tbody className="bg-cool-gray-600 divide-y divide-cool-gray-700">
{data?.map((user) => (
<tr key={`user-list-${user.id}`}>
<td className="px-6 py-4 whitespace-no-wrap">
<div className="flex items-center">
<div className="flex-shrink-0 h-10 w-10">
<img
className="h-10 w-10 rounded-full"
src={user.avatar}
alt=""
/>
</div>
<div className="ml-4">
<div className="text-sm leading-5 font-medium text-white">
{user.username}
</div>
<div className="text-sm leading-5 text-gray-300">
{user.email}
</div>
</div>
</div>
</td>
<td className="px-6 py-4 whitespace-no-wrap">
<div className="text-sm leading-5 text-white">
{user.requests.length}
</div>
</td>
<td className="px-6 py-4 whitespace-no-wrap">
<Badge badgeType="warning">Plex User</Badge>
</td>
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-white">
{hasPermission(Permission.ADMIN, user.permissions)
? 'Admin'
: 'User'}
</td>
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-white">
<FormattedDate value={user.createdAt} />
</td>
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-white">
<FormattedDate value={user.updatedAt} />
</td>
<td className="px-6 py-4 whitespace-no-wrap text-right text-sm leading-5 font-medium">
<Button buttonType="warning" className="mr-2">
Edit
</Button>
<Button buttonType="danger">Delete</Button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
</>
);
};
export default UserList;

@ -0,0 +1,9 @@
import React from 'react';
import type { NextPage } from 'next';
import UserList from '../../components/UserList';
const UsersPage: NextPage = () => {
return <UserList />;
};
export default UsersPage;

@ -1792,6 +1792,13 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6" resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY= integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=
"@types/node-schedule@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@types/node-schedule/-/node-schedule-1.3.1.tgz#6785ea71b12b0b8899c3fce0650b2ef5a7ea9d1e"
integrity sha512-xAY/ZATrThUkMElSDfOk+5uXprCrV6c6GQ5gTw3U04qPS6NofE1dhOUW+yrOF2UyrUiAax/Zc4WtagrbPAN3Tw==
dependencies:
"@types/node" "*"
"@types/node@*", "@types/node@^14.10.0": "@types/node@*", "@types/node@^14.10.0":
version "14.10.0" version "14.10.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.10.0.tgz#15815dff82c8dc30827f6b1286f865902945095a" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.10.0.tgz#15815dff82c8dc30827f6b1286f865902945095a"
@ -3702,6 +3709,14 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
safe-buffer "^5.0.1" safe-buffer "^5.0.1"
sha.js "^2.4.8" sha.js "^2.4.8"
cron-parser@^2.7.3:
version "2.17.0"
resolved "https://registry.yarnpkg.com/cron-parser/-/cron-parser-2.17.0.tgz#5707421a7e0a73ee74675d1c032a2f14123f2cf8"
integrity sha512-oTmzVEwlurRe51HqTm4afshVr8Rkxy9kFiWxh5e6SmrY2o9NDYU4S6SduanBZYXLgkLy0skA98y7/tztW/DmjQ==
dependencies:
is-nan "^1.3.0"
moment-timezone "^0.5.31"
cross-fetch@3.0.5: cross-fetch@3.0.5:
version "3.0.5" version "3.0.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.5.tgz#2739d2981892e7ab488a7ad03b92df2816e03f4c" resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.5.tgz#2739d2981892e7ab488a7ad03b92df2816e03f4c"
@ -6004,6 +6019,13 @@ is-installed-globally@^0.3.1:
global-dirs "^2.0.1" global-dirs "^2.0.1"
is-path-inside "^3.0.1" is-path-inside "^3.0.1"
is-nan@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/is-nan/-/is-nan-1.3.0.tgz#85d1f5482f7051c2019f5673ccebdb06f3b0db03"
integrity sha512-z7bbREymOqt2CCaZVly8aC4ML3Xhfi0ekuOnjO2L8vKdl+CttdVoGZQhd4adMFAsxQ5VeRVwORs4tU8RH+HFtQ==
dependencies:
define-properties "^1.1.3"
is-npm@^4.0.0: is-npm@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/is-npm/-/is-npm-4.0.0.tgz#c90dd8380696df87a7a6d823c20d0b12bbe3c84d" resolved "https://registry.yarnpkg.com/is-npm/-/is-npm-4.0.0.tgz#c90dd8380696df87a7a6d823c20d0b12bbe3c84d"
@ -6571,6 +6593,11 @@ logform@^2.2.0:
ms "^2.1.1" ms "^2.1.1"
triple-beam "^1.3.0" triple-beam "^1.3.0"
long-timeout@0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/long-timeout/-/long-timeout-0.1.1.tgz#9721d788b47e0bcb5a24c2e2bee1a0da55dab514"
integrity sha1-lyHXiLR+C8taJMLivuGg2lXatRQ=
longest@^2.0.1: longest@^2.0.1:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-2.0.1.tgz#781e183296aa94f6d4d916dc335d0d17aefa23f8" resolved "https://registry.yarnpkg.com/longest/-/longest-2.0.1.tgz#781e183296aa94f6d4d916dc335d0d17aefa23f8"
@ -6972,6 +6999,18 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
moment-timezone@^0.5.31:
version "0.5.31"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.31.tgz#9c40d8c5026f0c7ab46eda3d63e49c155148de05"
integrity sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==
dependencies:
moment ">= 2.9.0"
"moment@>= 2.9.0":
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
move-concurrently@^1.0.1: move-concurrently@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
@ -7257,6 +7296,15 @@ node-releases@^1.1.58, node-releases@^1.1.60:
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.60.tgz#6948bdfce8286f0b5d0e5a88e8384e954dfe7084" resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.60.tgz#6948bdfce8286f0b5d0e5a88e8384e954dfe7084"
integrity sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA== integrity sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA==
node-schedule@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/node-schedule/-/node-schedule-1.3.2.tgz#d774b383e2a6f6ade59eecc62254aea07cd758cb"
integrity sha512-GIND2pHMHiReSZSvS6dpZcDH7pGPGFfWBIEud6S00Q8zEIzAs9ommdyRK1ZbQt8y1LyZsJYZgPnyi7gpU2lcdw==
dependencies:
cron-parser "^2.7.3"
long-timeout "0.1.1"
sorted-array-functions "^1.0.0"
nodemon@^2.0.4: nodemon@^2.0.4:
version "2.0.4" version "2.0.4"
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.4.tgz#55b09319eb488d6394aa9818148c0c2d1c04c416" resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.4.tgz#55b09319eb488d6394aa9818148c0c2d1c04c416"
@ -9306,6 +9354,11 @@ sort-keys@^4.0.0:
dependencies: dependencies:
is-plain-obj "^2.0.0" is-plain-obj "^2.0.0"
sorted-array-functions@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/sorted-array-functions/-/sorted-array-functions-1.3.0.tgz#8605695563294dffb2c9796d602bd8459f7a0dd5"
integrity sha512-2sqgzeFlid6N4Z2fUQ1cvFmTOLRi/sEDzSQ0OKYchqgoPmQBVyM3959qYx3fpS6Esef80KjmpgPeEr028dP3OA==
source-list-map@^2.0.0: source-list-map@^2.0.0:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34" resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"

Loading…
Cancel
Save