Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Container, Service} from "typedi";
import {Connection} from "typeorm";
import {InjectConnection} from "typeorm-typedi-extensions";
import {User} from "../../entity/User";
import {UserEpisode} from "../../entity/UserEpisode";
import {UserMetaData} from "../../entity/UserMetaData";
import * as path from "path";
import * as fs from "fs";
import AppGlobal from "../helpers/AppGlobal";
@Service()
export class UserRepository {
@InjectConnection("reading")
private connection: Connection;
public getAllUsers() {
const userRepo = this.connection.manager.getRepository(User);
return userRepo.find();
}
public getUser(id) {
console.log("find user by id", id);
const userRepo = this.connection.manager.getRepository(User);
return userRepo.findOne(id);
}
public createUser(payload: User) {
console.log(payload);
const userRepo = this.connection.manager.getRepository(User);
import {MetaData} from "../../entity/MetaData";
import RoRest from "../services/RoRest";
import {HTMLElement, parse} from "node-html-parser";
import {TorrentFile} from "../../entity/TorrentFile";
import {IMediaEntry} from "../../common/models/IMediaEntry";
import * as ptn from "../../common/lib/parse-torrent-name";
import {MediaRepository} from "./MediaRepository";
import IMDBController from "../controllers/IMDBController";
import {Alias} from "../../entity/Alias";
type TorrentLinks = Array<{title: string, magnet: string, timestamp: number}>;
@Service()
export class TorrentsRepository {
@InjectConnection("reading")
private connection: Connection;
public static startTorrentsWatch(): void {
setInterval(() => {
const d = new Date();
const minutes = d.getMinutes();
const hours = d.getHours();
if (hours === 18 && minutes >= 15 && minutes < 45) {
Container.get(TorrentsRepository).reprocessTorrents()
.catch(console.error);
}
}, 1800 * 1000);
}
public async getAllTorrents() {
const metaRepo = this.connection.manager.getRepository(MetaData);
import {Container, Service} from "typedi";
import {Connection} from "typeorm";
import {InjectConnection} from "typeorm-typedi-extensions";
import {Genre} from "../../entity/Genre";
import {MetaData} from "../../entity/MetaData";
import MediaController from "../controllers/MediaController";
@Service()
export class GenreRepository {
@InjectConnection("reading")
private connection: Connection;
public getAllGenres() {
const userRepo = this.connection.manager.getRepository(Genre);
return userRepo.find();
}
public async reprocessAllGenres() {
const metaRepo = this.connection.manager.getRepository(MetaData);
const allMeta = await metaRepo.find();
let allGenres: string[] = [];
if (allMeta) {
for (const meta of allMeta) {
if (meta && meta.genres) {
const genres = meta.genres.split(", ") as string[];
if (genres) {
constructor(
@InjectConnection("reading") private connection: Connection,
) {
this.episodeRepo = this.connection.getRepository(Episode);
this.metaRepo = this.connection.getRepository(MetaData);
this.aliasRepo = this.connection.getRepository(Alias);
this.filesRepo = this.connection.getRepository(MediaFile);
this.torrentFileRepo = this.connection.getRepository(TorrentFile);
}
constructor(
@InjectConnection("reading") private connection: Connection,
) {
this.filesRepo = this.connection.getRepository(MediaFile);
this.metaDataRepo = this.connection.getRepository(MetaData);
this.episodeRepo = this.connection.getRepository(Episode);
this.aliasRepo = this.connection.getRepository(Alias);
}