add networks + random changes

This commit is contained in:
X4Lo committed 2025-02-15 23:40:34 +01:00
1 parent bb36b2bd44
commit 5dc5a023b8
26 files changed
+1387 -1963

No files matched your search

+3
View File
@@ -4,6 +4,9 @@
settings.json settings.json
sequelize.log sequelize.log
showy.log showy.log
environment.prod.ts
environment.ts
.env
# Compiled output # Compiled output
.angular .angular
+18
View File
@@ -12,6 +12,8 @@ const EpisodeSeen = require('../models/EpisodeSeen');
const Genre = require('../models/Genre'); const Genre = require('../models/Genre');
const EntryGenre = require('../models/EntryGenre'); const EntryGenre = require('../models/EntryGenre');
const Media = require('../models/Media'); const Media = require('../models/Media');
const Network = require('../models/Network');
const EntryNetwork = require('../models/EntryNetwork');
// ? one to one // ? one to one
@@ -84,6 +86,22 @@ EntryGenre.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' }); Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' });
EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' }); EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
// * ENTRY & NETWORK - MANY TO MANY
Entry.belongsToMany(Network, {
through: EntryNetwork,
foreignKey: 'entry_id',
otherKey: 'network_id',
onDelete: 'CASCADE',
as: 'networks',
});
Network.belongsToMany(Entry, {
through: EntryNetwork,
foreignKey: 'network_id',
otherKey: 'entry_id',
onDelete: 'CASCADE',
as: 'entries',
});
// * ENTRY & MEDIA - ONE TO MANY // * ENTRY & MEDIA - ONE TO MANY
// Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', }); // Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
-1
View File
@@ -1,4 +1,3 @@
const CustomError = require('../errors/CustomError'); const CustomError = require('../errors/CustomError');
const { logToFile } = require('../services/logService'); const { logToFile } = require('../services/logService');
+31
View File
@@ -0,0 +1,31 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const EntryNetwork = sequelize.define('entryNetwork',
{
network_id: {
type: DataTypes.INTEGER,
primaryKey: true,
references: {
model: 'Networks',
key: 'id'
}
},
entry_id: {
type: DataTypes.INTEGER,
primaryKey: true,
references: {
model: 'Entries',
key: 'id'
}
},
order: {
type: DataTypes.INTEGER
}
},
{
primaryKey: ['network_id', 'entry_id'],
}
);
module.exports = EntryNetwork;
+18
View File
@@ -0,0 +1,18 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Network = sequelize.define("network",
{
id: { type: DataTypes.INTEGER, primaryKey: true },
name: { type: DataTypes.STRING(30) },
originCountry: { type: DataTypes.STRING(100), field: 'origin_country' },
homepage: { type: DataTypes.STRING(100), field: 'homepage' },
logoPath: { type: DataTypes.STRING(200), field: 'logo_path' },
posterPath: { type: DataTypes.STRING(200), field: 'poster_path' },
backdropPath: { type: DataTypes.STRING(200), field: 'backdrop_path' },
}
);
module.exports = Network;
@@ -546,8 +546,8 @@ async function refrechEntry(entryId) {
// ? fetch collection // ? fetch collection
if (entryData.belongs_to_collection) { if (entryData.belongs_to_collection) {
const collectionService = require('./collectionService.js'); const collectionService = require('../collectionService.js');
await collectionService.upsertOfficialCollection(entryData.belongs_to_collection.id); await collectionService.createOrUpdateCollection(entryData.belongs_to_collection.id);
} }
// + end of: refrech logic // + end of: refrech logic
+70
View File
@@ -0,0 +1,70 @@
const Collection = require("../models/Collection");
const Entry = require("../models/Entry");
const EntryId = require("../models/EntryId");
const EntryRating = require("../models/EntryRating");
const Genre = require("../models/Genre");
const Media = require("../models/Media");
const Network = require("../models/Network");
const Season = require("../models/Season");
class NetworkService {
constructor() {
if (!NetworkService.instance) {
NetworkService.instance = this;
}
return NetworkService.instance;
}
async getNetworks() {
const networks = await Network.findAll({
include: [
{
model: Entry, as: 'entries',
include: { model: Media, as: 'medias' }
}
],
order: [['name', 'ASC']]
});
return networks;
}
async getNetworkById(id) {
const network = await Network.findByPk(id, {
include: [{
model: Entry,
as: 'entries',
include: [
{ model: EntryId, as: 'entryId' },
{ model: EntryRating, as: 'entryRating' },
{ model: Season, as: 'seasons' },
{ model: Media, as: 'medias' },
{ model: Genre, as: 'genres' },
]
}]
});
return network;
}
async createOrUpdateNetwork(networkData) {
return await Network.findOrCreate({
where: { id: networkData.id },
defaults: {
id: networkData.id,
name: networkData.name,
originCountry: networkData.originCountry,
homepage: networkData.homepage,
logoPath: networkData.logoPath,
posterPath: networkData.posterPath,
backdropPath: networkData.backdropPath,
}
});
}
}
module.exports = new NetworkService();
+2 -4
View File
@@ -88,7 +88,7 @@ function createWindow() {
mainWindow.loadURL( mainWindow.loadURL(
url.format({ url.format({
pathname: path.join(__dirname, 'dist', 'showy', 'browser', 'index.html'), pathname: path.join(__dirname, 'frontend_build', 'browser', 'index.html'),
protocol: 'file:', protocol: 'file:',
slashes: true slashes: true
}) })
@@ -99,14 +99,12 @@ function createWindow() {
}); });
mainWindow.webContents.on('will-navigate', (event, url) => { mainWindow.webContents.on('will-navigate', (event, url) => {
event.preventDefault(); event.preventDefault();;
console.log('hiiiiiiiii');
mainWindow.loadURL(`file://${path.join(__dirname, 'dist/showy/index.html')}`); mainWindow.loadURL(`file://${path.join(__dirname, 'dist/showy/index.html')}`);
}); });
mainWindow.webContents.on('did-fail-load', (event, url) => { mainWindow.webContents.on('did-fail-load', (event, url) => {
// event.preventDefault(); // event.preventDefault();
console.log('yoooo');
mainWindow.loadURL(`file://${path.join(__dirname, 'dist/showy/browser/index.html')}`); mainWindow.loadURL(`file://${path.join(__dirname, 'dist/showy/browser/index.html')}`);
}); });
} }
+18 -6
View File
@@ -7,32 +7,44 @@
"electron": "electron .", "electron": "electron .",
"build-front": "ng build --configuration=production --base-href ./", "build-front": "ng build --configuration=production --base-href ./",
"copy-front": "", "copy-front": "",
"copy-back": "copyfiles backend/**/* dist/showy", "copy-back": "copyfiles ../backend/**/* ./frontend_build/",
"generate-exe": "electron-builder" "generate-exe": "electron-builder"
}, },
"portable": true,
"singleInstance": false,
"build": { "build": {
"appId": "xalo.showy", "appId": "x4lo.showy",
"productName": "Showy", "productName": "Showy",
"win": { "win": {
"target": [ "target": [
{ {
"target": "dir", "target": "dir",
"arch": [ "arch": [
"x64" "x64",
"win32"
] ]
} }
], ],
"icon": "src/assets/images/showy.ico" "icon": "../frontend/src/assets/images/showy.ico"
}, },
"directories": { "directories": {
"output": "dist" "output": "../dist/electron"
} }
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^1.7.9",
"body-parser": "^1.20.3",
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"dotenv": "^16.4.7",
"electron": "^34.0.1", "electron": "^34.0.1",
"electron-builder": "^25.1.8" "electron-builder": "^25.1.8",
"express": "^4.21.2",
"multer": "1.4.5-lts.1",
"mysql2": "^3.12.0",
"sequelize": "^6.37.5",
"sharp": "^0.33.5",
"uuid": "^11.0.5"
} }
} }
+1089 -6
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -13,7 +13,7 @@
"build": { "build": {
"builder": "@angular-devkit/build-angular:application", "builder": "@angular-devkit/build-angular:application",
"options": { "options": {
"outputPath": "dist/showy", "outputPath": "../dist/frontend",
"index": "src/index.html", "index": "src/index.html",
"browser": "src/main.ts", "browser": "src/main.ts",
"polyfills": ["zone.js"], "polyfills": ["zone.js"],
+2 -2
View File
@@ -6,6 +6,7 @@
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"frontend": "ng serve", "frontend": "ng serve",
"bundle-to-electron": "ng build --output-path=../electron/frontend_build --configuration production --base-href ./",
"Check Circular": "madge --circular --image circular-dependencies.png backend/server.js", "Check Circular": "madge --circular --image circular-dependencies.png backend/server.js",
"build-and-copy": "ng build --configuration production --base-href ./ && copyfiles backend/**/* dist/showy", "build-and-copy": "ng build --configuration production --base-href ./ && copyfiles backend/**/* dist/showy",
"watch": "ng build --watch --configuration development", "watch": "ng build --watch --configuration development",
@@ -17,8 +18,6 @@
"prod-cp-BE": "copyfiles backend/**/* dist_electron/win-unpacked", "prod-cp-BE": "copyfiles backend/**/* dist_electron/win-unpacked",
"prod-cp-settings": "copyfiles settings.json dist_electron/win-unpacked/" "prod-cp-settings": "copyfiles settings.json dist_electron/win-unpacked/"
}, },
"portable": true,
"singleInstance": false,
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/animations": "^17.0.0", "@angular/animations": "^17.0.0",
@@ -39,6 +38,7 @@
"apexcharts": "^3.49.0", "apexcharts": "^3.49.0",
"axios": "^1.6.8", "axios": "^1.6.8",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"chart.js": "^4.4.7",
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"flatpickr": "^4.6.13", "flatpickr": "^4.6.13",
"html2canvas": "^1.4.1", "html2canvas": "^1.4.1",
+40 -1909
View File
File diff suppressed because it is too large. Load diff
+5
View File
@@ -84,6 +84,11 @@ export class AppComponent implements OnInit, AfterViewInit {
onScroll(): void { onScroll(): void {
const container = this.scrollContainer.nativeElement; const container = this.scrollContainer.nativeElement;
this.scrollService.notifyScrollChange({
scrollTop: container.scrollTop,
clientHeight: container.clientHeight,
});
// Check if the scrollbar is near the bottom // Check if the scrollbar is near the bottom
if ( if (
container.scrollTop + container.clientHeight >= container.scrollTop + container.clientHeight >=
@@ -9,7 +9,7 @@ import { Media } from '../../shared/models/media.model';
}) })
export class CustomMediaService { export class CustomMediaService {
private backend_apiUrl = environment.API_URL; private backend_apiUrl = environment.API_URL;
private apiAction = 'custom-media'; private apiAction = 'media';
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
@@ -20,10 +20,4 @@ export class EntryRatingsService {
} }
); );
} }
getEntrySeenById(id: string) {
return this.http.get<EntryRating[]>(
`${this.backend_apiUrl}/${this.apiAction}/${id}`
);
}
} }
@@ -64,6 +64,24 @@ export class EntryService {
); );
} }
updateEntryRatings(entryId: number, entryRatings: EntryRating) {
return this.http.put<EntryRating>(
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/ratings`,
{
entryRatings: entryRatings,
}
);
}
updateEntryIds(entryId: number, entryIds: EntryId) {
return this.http.put<EntryId>(
`${this.backend_apiUrl}/${this.apiAction}/${entryId}/ids`,
{
entryIds: entryIds,
}
);
}
// update entry // update entry
refrechEntryById(entryId: number) { refrechEntryById(entryId: number) {
return this.http.put<Entry>( return this.http.put<Entry>(
@@ -20,7 +20,7 @@ export class MaintenanceService {
getMissingFiles() { getMissingFiles() {
return this.http.get<MaintenanceResult>( return this.http.get<MaintenanceResult>(
`${this.backend_apiUrl}/${this.apiAction}/missing-files` `${this.backend_apiUrl}/${this.apiAction}/orphan-media-records`
); );
} }
@@ -32,7 +32,7 @@ export class MaintenanceService {
deleteMissingFiles() { deleteMissingFiles() {
return this.http.delete<MaintenanceResult>( return this.http.delete<MaintenanceResult>(
`${this.backend_apiUrl}/${this.apiAction}/missing-files` `${this.backend_apiUrl}/${this.apiAction}/orphan-media-records`
); );
} }
} }
@@ -6,12 +6,18 @@ import { Subject } from 'rxjs';
}) })
export class ScrollService { export class ScrollService {
private scrollEndSubject = new Subject<void>(); private scrollEndSubject = new Subject<void>();
private scrollChangeSubject = new Subject<object>();
// Observable for subcomponents to subscribe // Observable for subcomponents to subscribe
scrollEnd$ = this.scrollEndSubject.asObservable(); scrollEnd$ = this.scrollEndSubject.asObservable();
scrollChange$ = this.scrollChangeSubject.asObservable();
// Emit scroll end event // Emit scroll end event
notifyScrollEnd(): void { notifyScrollEnd(): void {
this.scrollEndSubject.next(); this.scrollEndSubject.next();
} }
notifyScrollChange(data: object): void {
this.scrollChangeSubject.next(data);
}
} }
@@ -33,7 +33,7 @@ export class CalendarPageComponent implements OnInit {
dateClick: this.handleDateClick.bind(this), // Bind the date click event handler dateClick: this.handleDateClick.bind(this), // Bind the date click event handler
datesSet: this.handleDatesSet.bind(this), // month change datesSet: this.handleDatesSet.bind(this), // month change
eventClick: this.handleEventClick.bind(this), // Handle event clicks eventClick: this.handleEventClick.bind(this), // Handle event clicks
dayMaxEvents: 4, // Limit the number of events displayed per day dayMaxEvents: 3, // Limit the number of events displayed per day
height: 'auto', height: 'auto',
}; };
@@ -45,13 +45,13 @@ export class CalendarPageComponent implements OnInit {
) {} ) {}
ngOnInit() { ngOnInit() {
const today = new Date(); // const today = new Date();
const firstDayOfFirstWeek = this.getFirstMondayOfMonth(today) // const firstDayOfFirstWeek = this.getFirstMondayOfMonth(today)
.toISOString() // .toISOString()
.split('T')[0]; // .split('T')[0];
const lastDayOfLastWeek = this.getLastSundayOfMonth(today) // const lastDayOfLastWeek = this.getLastSundayOfMonth(today)
.toISOString() // .toISOString()
.split('T')[0]; // .split('T')[0];
// console.log('First Day of First Week:', firstDayOfFirstWeek); // console.log('First Day of First Week:', firstDayOfFirstWeek);
// console.log('Last Day of Last Week:', lastDayOfLastWeek); // console.log('Last Day of Last Week:', lastDayOfLastWeek);
@@ -49,7 +49,7 @@
<div *ngIf="isLoading" class="loading-indicator"> <div *ngIf="isLoading" class="loading-indicator">
Loading... Loading...
</div> </div>
<button class="loading-button" (click)="loadNext()">Load More</button> <button class="loading-button" (click)="loadNext()" *ngIf="maxPage > currentPage">Load More</button>
<!-- Pagination --> <!-- Pagination -->
<!-- <div class="pagination-container d-flex justify-content-end" *ngIf="maxPage > 1"> <!-- <div class="pagination-container d-flex justify-content-end" *ngIf="maxPage > 1">
@@ -43,7 +43,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {
searchControl = new FormControl(); searchControl = new FormControl();
private scrollSubscription!: Subscription; private scrollSubscription!: Subscription;
private queryParamsSubscription!: Subscription;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private tmdbService: TmdbService, private tmdbService: TmdbService,
@@ -62,12 +62,14 @@ export class SearchPageComponent implements OnInit, OnDestroy {
// this.search(value); // Call your API search function here // this.search(value); // Call your API search function here
}); });
this.route.queryParams.subscribe((params: any) => { this.queryParamsSubscription = this.route.queryParams.subscribe(
if (params && params['title']) { (params: any) => {
let title = params['title']; if (params && params['title']) {
this.searchControl.setValue(title); let title = params['title'];
this.searchControl.setValue(title);
}
} }
}); );
this.scrollSubscription = this.scrollService.scrollEnd$.subscribe(() => { this.scrollSubscription = this.scrollService.scrollEnd$.subscribe(() => {
if (!this.isLoading) { if (!this.isLoading) {
@@ -81,6 +83,10 @@ export class SearchPageComponent implements OnInit, OnDestroy {
if (this.scrollSubscription) { if (this.scrollSubscription) {
this.scrollSubscription.unsubscribe(); this.scrollSubscription.unsubscribe();
} }
if (this.queryParamsSubscription) {
this.queryParamsSubscription.unsubscribe();
}
} }
setEntryType(entryType: boolean) { setEntryType(entryType: boolean) {
@@ -150,6 +156,8 @@ export class SearchPageComponent implements OnInit, OnDestroy {
.getByKeywordMulti(this.keyword, this.currentPage) .getByKeywordMulti(this.keyword, this.currentPage)
.subscribe({ .subscribe({
next: (result) => { next: (result) => {
this.maxPage = result.total_pages;
console.log(this.maxPage);
this.entries = this.entries.concat(result.entries as Entry[]); this.entries = this.entries.concat(result.entries as Entry[]);
this.isLoading = false; this.isLoading = false;
}, },
@@ -303,10 +303,17 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
// ! Match all criteria logic // ! Match all criteria logic
if (this.filterCriteria.matchAll) { if (this.filterCriteria.matchAll) {
return ( return (
(formattedTitle ((formattedTitle
? entry.title.toLowerCase().includes(formattedTitle) || ? entry.title.toLowerCase().includes(formattedTitle) ||
entry.original_title.toLowerCase().includes(formattedTitle) entry.original_title.toLowerCase().includes(formattedTitle)
: true) && : true) ||
entry.networks
.map((network) => network.name.toLowerCase())
.some((networkName) =>
networkName.includes(
formattedTitle.replace('network:', '').toLowerCase().trim()
)
)) &&
(this.filterCriteria.genres?.length (this.filterCriteria.genres?.length
? this.filterCriteria.genres.every((genre) => ? this.filterCriteria.genres.every((genre) =>
entry.genres.includes(genre) entry.genres.includes(genre)
@@ -327,10 +334,13 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
? entry.title.toLowerCase().includes(formattedTitle) || ? entry.title.toLowerCase().includes(formattedTitle) ||
entry.original_title.toLowerCase().includes(formattedTitle) entry.original_title.toLowerCase().includes(formattedTitle)
: true) || : true) ||
(entry.network_studio entry.networks
? entry.network_studio.toLowerCase() == .map((network) => network.name.toLowerCase())
formattedTitle.replace('studio:', '') .some(
: true) || (networkName) =>
networkName ==
formattedTitle.replace('network:', '').toLowerCase()
) ||
(this.filterCriteria.genres?.length && (this.filterCriteria.genres?.length &&
this.filterCriteria.genres.some((genre) => this.filterCriteria.genres.some((genre) =>
entry.genres.includes(genre) entry.genres.includes(genre)
@@ -374,8 +384,6 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
const startIndex = (this.currentPage - 1) * this.pageSize; const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize; const endIndex = startIndex + this.pageSize;
console.log(this.pageSize, startIndex, endIndex);
this.entriesToDisplay = this.entriesList.slice(startIndex, endIndex); this.entriesToDisplay = this.entriesList.slice(startIndex, endIndex);
} }
@@ -4,6 +4,7 @@ import { EntrySeen } from './entry-seen.model';
import { Media } from './media.model'; import { Media } from './media.model';
import { Season } from './season.model'; import { Season } from './season.model';
import { Collection } from './collection.model'; import { Collection } from './collection.model';
import { Network } from './network.model';
export interface Entry { export interface Entry {
id: number; id: number;
@@ -44,6 +45,7 @@ export interface Entry {
genres: string[]; genres: string[];
medias: Media[]; medias: Media[];
networks: Network[];
poster_path: string; poster_path: string;
banner_path: string; banner_path: string;
@@ -0,0 +1,14 @@
export interface Network {
id: number;
name: string;
originCountry: string;
homepage: string;
logoPath: string;
posterPath: string;
backdropPath: string;
createdAt: Date;
updatedAt: Date;
}
@@ -0,0 +1,6 @@
export const environment = {
production: false,
API_URL: 'http://localhost:4000/api/v1',
TMDB_API_URL: 'https://api.themoviedb.org/3',
TMDB_API_KEY: 'YOUR_API_KEY',
};