Skip to content

Commit

Permalink
Merge branch 'docs-ui-additions' of https://github.com/ydkmlt84/Maint…
Browse files Browse the repository at this point in the history
…ainerr into docs-ui-additions
  • Loading branch information
ydkmlt84 committed Jan 25, 2024
2 parents 43645cf + cd5df98 commit 30918c7
Show file tree
Hide file tree
Showing 39 changed files with 1,291 additions and 129 deletions.
5 changes: 3 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version: 2
updates:
- package-ecosystem: npm
directory: '/'
directory: "/"
schedule:
interval: weekly
time: '20:00'
time: "20:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: "@heroicons/react"
- dependency-name: "chalk"
9 changes: 2 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,15 @@ All help is welcome and greatly appreciated! If you would like to contribute to
yarn
```

6. Initialise the database
```bash
yarn migration:run
```

7. Run the development environments:
6. Run the development commands:
```bash
yarn dev:server
yarn dev:ui
```

- If the build fails with Windows Powershell, try to use cmd instead.

8. Create your patch and test your changes.
7. Create your patch and test your changes.

- Be sure to follow both the [code](#contributing-code) and [UI text](#ui-text-style) guidelines.
- Should you need to update your fork, you can do so by rebasing from `upstream`:
Expand Down
13 changes: 2 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}

COPY server/ /opt/server/
COPY ui/ /opt/ui/
COPY tools/ /opt/tools/
COPY docs/ /opt/docs/
COPY package.json /opt/package.json
COPY yarn.lock /opt/yarn.lock
COPY datasource-config.ts /opt/datasource-config.ts
COPY ormconfig.json /opt/ormconfig.json
COPY jsdoc.json /opt/jsdoc.json
COPY start.sh /opt/start.sh
COPY .yarnrc.yml /opt/.yarnrc.yml

WORKDIR /opt/
Expand All @@ -26,10 +22,6 @@ RUN corepack install && \

RUN apk --update --no-cache add python3 make g++ curl

RUN chmod +x /opt/start.sh

RUN sed -i 's/\/server\/dist\//\/server\//g' /opt/datasource-config.ts

RUN yarn --immutable --network-timeout 99999999

RUN \
Expand Down Expand Up @@ -64,8 +56,7 @@ RUN yarn workspaces focus --production

RUN rm -rf .yarn && \
mkdir /opt/data && \
chown -R node:node /opt && \
chmod +x /opt/start.sh
chown -R node:node /opt

# Final build
FROM node:20-alpine3.19
Expand Down Expand Up @@ -98,4 +89,4 @@ USER node
EXPOSE 80

VOLUME [ "/opt/data" ]
ENTRYPOINT ["/opt/start.sh"]
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
15 changes: 0 additions & 15 deletions ormconfig.json

This file was deleted.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@
"test:e2e": "jest --config ./test/jest-e2e.json",
"docs-generate": "jsdoc -c jsdoc.json --readme ./docs/1-home/Home.md ./server/dist/",
"docs-serve": "http-server ./docs-output/ --cors",
"migration:run": "ts-node tools/typeOrmCli.ts migration:run -d ./datasource-config.ts",
"migration:revert": "ts-node tools/typeOrmCli.ts migration:revert -d ./datasource-config.ts",
"migration:generate": "ts-node tools/typeOrmCli.ts migration:generate --dataSource ./datasource-config.ts -p"
"migration:run": "ts-node node_modules/typeorm/cli.js migration:run -d ./datasource-config.ts",
"migration:revert": "ts-node node_modules/typeorm/cli.js migration:revert -d ./datasource-config.ts",
"migration:generate": "ts-node node_modules/typeorm/cli.js migration:generate --dataSource ./datasource-config.ts -p"
},
"dependencies": {
"@headlessui/react": "1.7.18",
"@heroicons/react": "^1.0.6",
"@monaco-editor/react": "^4.6.0",
"@nestjs/cli": "^10.3.0",
"@nestjs/common": "^10.3.0",
"@nestjs/core": "^10.3.0",
"@nestjs/platform-express": "^10.3.0",
"@nestjs/common": "^10.3.1",
"@nestjs/core": "^10.3.1",
"@nestjs/platform-express": "^10.3.1",
"@nestjs/schedule": "^4.0.0",
"@nestjs/typeorm": "^10.0.1",
"@types/node": "^20.10.7",
"axios": "^1.6.5",
"@types/node": "^20.11.6",
"axios": "^1.6.6",
"bowser": "^2.11.0",
"chalk": "^5.3.0",
"chalk": "^4.1.2",
"cron": "3.1.3",
"cron-validator": "^1.3.1",
"crypto": "^1.0.1",
Expand All @@ -65,7 +65,6 @@
"reflect-metadata": "^0.2.1",
"rxjs": "^7.8.1",
"sqlite3": "^5.1.6",
"ts-node": "^10.9.2",
"typeorm": "^0.3.19",
"typescript": "^5.3.3",
"web-push": "^3.6.6",
Expand All @@ -79,7 +78,7 @@
"@babel/core": "^7.23.2",
"@nestjs/cli": "^10.3.0",
"@nestjs/schematics": "^10.1.0",
"@nestjs/testing": "^10.2.10",
"@nestjs/testing": "^10.3.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^11.1.0",
"@semantic-release/exec": "^6.0.3",
Expand Down Expand Up @@ -114,6 +113,7 @@
"source-map-support": "^0.5.21",
"tailwindcss": "^3.4.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0"
},
"jest": {
Expand Down
9 changes: 2 additions & 7 deletions server/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@ import { RulesModule } from '../modules/rules/rules.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { getConnectionOptions } from 'typeorm';
import { OverseerrApiModule } from '../modules/api/overseerr-api/overseerr-api.module';
import { CollectionsModule } from '../modules/collections/collections.module';
import { SettingsModule } from '../modules/settings/settings.module';
import { SettingsService } from '../modules/settings/settings.service';
import { PlexApiService } from '../modules/api/plex-api/plex-api.service';
import { OverseerrApiService } from '../modules/api/overseerr-api/overseerr-api.service';
import { ServarrService } from '../modules/api/servarr-api/servarr.service';
import ormConfig from './config/typeOrmConfig';

@Module({
imports: [
TypeOrmModule.forRootAsync({
useFactory: async () =>
Object.assign(await getConnectionOptions(), {
autoLoadEntities: true,
}),
}),
TypeOrmModule.forRoot(ormConfig),
SettingsModule,
PlexApiModule,
ExternalApiModule,
Expand Down
18 changes: 18 additions & 0 deletions server/src/app/config/typeOrmConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TypeOrmModuleOptions } from '@nestjs/typeorm';

const ormConfig: TypeOrmModuleOptions = {
type: 'sqlite',
logging: false,
database:
process.env.NODE_ENV === 'production'
? '/opt/data/maintainerr.sqlite'
: '../data/maintainerr.sqlite',
subscribers: ['./**/*.subscriber{.ts,.js}'],
migrations:
process.env.NODE_ENV === 'production'
? ['/opt/server/database/migrations/**/*{.js,.ts}']
: ['./dist/database/migrations/**/*{.js,.ts}'],
autoLoadEntities: true,
migrationsRun: true,
};
export = ormConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CollectionAddInfoFields1705919105309
implements MigrationInterface
{
name = 'CollectionAddInfoFields1705919105309';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
'ALTER TABLE collection ADD COLUMN "addDate" datetime',
); // for postgress: ALTER TABLE collection ADD COLUMN "addDate" timestamp with(out) time zone NOT NULL DEFAULT now()

await queryRunner.query(
'ALTER TABLE collection ADD COLUMN "handledMediaAmount" INTEGER NOT NULL DEFAULT 0',
);

await queryRunner.query(
'ALTER TABLE collection ADD COLUMN "lastDurationInSeconds" INTEGER NOT NULL DEFAULT 0',
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE collection DROP "addDate"`);
await queryRunner.query(`ALTER TABLE collection DROP "handledMediaAmount"`);
await queryRunner.query(
`ALTER TABLE collection DROP "lastDurationInSeconds"`,
);
}
}
36 changes: 36 additions & 0 deletions server/src/database/migrations/1705930583532-Collection_Log_add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CollectionLogAdd1705930583532 implements MigrationInterface {
name = 'CollectionLogAdd1705930583532';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE "collection_log" (
"id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
"collectionId" integer NOT NULL,
"timestamp" datetime NOT NULL,
"message" varchar NOT NULL,
"type" integer NOT NULL
)
`);
await queryRunner.query(`
CREATE INDEX "idx_collection_log_collection_id" ON "collection_log" ("collectionId")
`);

await queryRunner.query(`
CREATE INDEX "idx_collection_media_collection_id" ON "collection_media" ("collectionId")
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "idx_collection_log_collection_id"
`);
await queryRunner.query(`
DROP INDEX "idx_collection_media_collection_id"
`);
await queryRunner.query(`
DROP TABLE "collection_log"
`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CollectionAddKeepLogsMonths1706016592389
implements MigrationInterface
{
name = 'CollectionAddKeepLogsMonths1706016592389';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
'ALTER TABLE collection ADD COLUMN "keepLogsForMonths" INTEGER NOT NULL DEFAULT 6',
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE collection DROP "keepLogsForMonths"`);
}
}
2 changes: 2 additions & 0 deletions server/src/modules/api/plex-api/interfaces/media.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface PlexMetadata {
originallyAvailableAt: string;
Media: Media[];
Genre?: PlexGenre[];
parentTitle?: string;
grandparentTitle?: string;
}

export interface Media {
Expand Down
25 changes: 19 additions & 6 deletions server/src/modules/collections/collection-worker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ export class CollectionWorkerService implements OnApplicationBootstrap {
onApplicationBootstrap() {
this.jobCreationAttempts++;
const state = this.taskService.createJob(
'CollectionHandler',
'Collection Handler',
this.settings.collection_handler_job_cron,
this.handle.bind(this),
);
if (state.code === 0) {
if (this.jobCreationAttempts <= 3) {
this.logger.log(
'Creation of job CollectionHandler failed. Retrying in 10s..',
'Creation of job Collection Handler failed. Retrying in 10s..',
);
setTimeout(() => {
this.onApplicationBootstrap();
}, 10000);
} else {
this.logger.error(`Creation of job CollectionHandler failed.`);
this.logger.error(`Creation of job Collection Handler failed.`);
}
}
}

public updateJob(cron: string) {
return this.taskService.updateJob(
'CollectionHandler',
'Collection Handler',
cron,
this.handle.bind(this),
);
Expand Down Expand Up @@ -100,6 +100,7 @@ export class CollectionWorkerService implements OnApplicationBootstrap {
handledCollections++;
}
}

this.infoLogger(`Handling collection '${collection.title}' finished`);
}
if (handledCollections > 0) {
Expand Down Expand Up @@ -137,6 +138,18 @@ export class CollectionWorkerService implements OnApplicationBootstrap {
},
]);

// update handled media amount
collection.handledMediaAmount++;

// save a log record for the handled media item
this.collectionService.CollectionLogRecordForChild(
media.plexId,
collection.id,
'handle',
);

this.collectionService.saveCollection(collection);

if (plexLibrary.type === 'movie') {
if (this.settings.radarrConfigured()) {
// find tmdbid
Expand Down Expand Up @@ -465,8 +478,8 @@ export class CollectionWorkerService implements OnApplicationBootstrap {
plexData.grandparentRatingKey.toString(),
)
: plexData.parentRatingKey
? await this.plexApi.getMetadata(plexData.parentRatingKey.toString())
: plexData;
? await this.plexApi.getMetadata(plexData.parentRatingKey.toString())
: plexData;

const tvdbidPlex = plexData?.Guid?.find((el) => el.id.includes('tvdb'));
if (tvdbidPlex) {
Expand Down
24 changes: 24 additions & 0 deletions server/src/modules/collections/collections.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AddCollectionMedia,
IAlterableMediaDto,
} from './interfaces/collection-media.interface';
import { ECollectionLogType } from 'src/modules/collections/entities/collection_log.entities';

@Controller('api/collections')
export class CollectionsController {
Expand Down Expand Up @@ -170,4 +171,27 @@ export class CollectionsController {
},
);
}

@Get('/logs/:id/content/:page')
getCollectionLogs(
@Param('id') id: number,
@Param('page', new ParseIntPipe()) page: number,
@Query('size') amount: number,
@Query('search') search: string,
@Query('sort') sort: 'ASC' | 'DESC' = 'DESC',
@Query('filter') filter: ECollectionLogType,
) {
const size = amount ? amount : 25;
const offset = (page - 1) * size;
return this.collectionService.getCollectionLogsWithhPaging(
id,
{
offset: offset,
size: size,
},
search,
sort,
filter,
);
}
}
Loading

0 comments on commit 30918c7

Please sign in to comment.