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
+1384 -1960

No files matched your search

+3
View File
@@ -4,6 +4,9 @@
settings.json
sequelize.log
showy.log
environment.prod.ts
environment.ts
.env
# Compiled output
.angular
+18
View File
@@ -12,6 +12,8 @@ const EpisodeSeen = require('../models/EpisodeSeen');
const Genre = require('../models/Genre');
const EntryGenre = require('../models/EntryGenre');
const Media = require('../models/Media');
const Network = require('../models/Network');
const EntryNetwork = require('../models/EntryNetwork');
// ? one to one
@@ -84,6 +86,22 @@ EntryGenre.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' });
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.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
-1
View File
@@ -1,4 +1,3 @@
const CustomError = require('../errors/CustomError');
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
if (entryData.belongs_to_collection) {
const collectionService = require('./collectionService.js');
await collectionService.upsertOfficialCollection(entryData.belongs_to_collection.id);
const collectionService = require('../collectionService.js');
await collectionService.createOrUpdateCollection(entryData.belongs_to_collection.id);
}
// + 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(
url.format({
pathname: path.join(__dirname, 'dist', 'showy', 'browser', 'index.html'),
pathname: path.join(__dirname, 'frontend_build', 'browser', 'index.html'),
protocol: 'file:',
slashes: true
})
@@ -99,14 +99,12 @@ function createWindow() {
});
mainWindow.webContents.on('will-navigate', (event, url) => {
event.preventDefault();
console.log('hiiiiiiiii');
event.preventDefault();;
mainWindow.loadURL(`file://${path.join(__dirname, 'dist/showy/index.html')}`);
});
mainWindow.webContents.on('did-fail-load', (event, url) => {
// event.preventDefault();
console.log('yoooo');
mainWindow.loadURL(`file://${path.join(__dirname, 'dist/showy/browser/index.html')}`);
});
}
+18 -6
View File
@@ -7,32 +7,44 @@
"electron": "electron .",
"build-front": "ng build --configuration=production --base-href ./",
"copy-front": "",
"copy-back": "copyfiles backend/**/* dist/showy",
"copy-back": "copyfiles ../backend/**/* ./frontend_build/",
"generate-exe": "electron-builder"
},
"portable": true,
"singleInstance": false,
"build": {
"appId": "xalo.showy",
"appId": "x4lo.showy",
"productName": "Showy",
"win": {
"target": [
{
"target": "dir",
"arch": [
"x64"
"x64",
"win32"
]
}
],
"icon": "src/assets/images/showy.ico"
"icon": "../frontend/src/assets/images/showy.ico"
},
"directories": {
"output": "dist"
"output": "../dist/electron"
}
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.7.9",
"body-parser": "^1.20.3",
"copyfiles": "^2.4.1",
"dotenv": "^16.4.7",
"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": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/showy",
"outputPath": "../dist/frontend",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": ["zone.js"],
+2 -2
View File
@@ -6,6 +6,7 @@
"main": "main.js",
"scripts": {
"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",
"build-and-copy": "ng build --configuration production --base-href ./ && copyfiles backend/**/* dist/showy",
"watch": "ng build --watch --configuration development",
@@ -17,8 +18,6 @@
"prod-cp-BE": "copyfiles backend/**/* dist_electron/win-unpacked",
"prod-cp-settings": "copyfiles settings.json dist_electron/win-unpacked/"
},
"portable": true,
"singleInstance": false,
"private": true,
"dependencies": {
"@angular/animations": "^17.0.0",
@@ -39,6 +38,7 @@
"apexcharts": "^3.49.0",
"axios": "^1.6.8",
"bootstrap": "^5.3.3",
"chart.js": "^4.4.7",
"date-fns": "^3.6.0",
"flatpickr": "^4.6.13",
"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 {
const container = this.scrollContainer.nativeElement;
this.scrollService.notifyScrollChange({
scrollTop: container.scrollTop,
clientHeight: container.clientHeight,
});
// Check if the scrollbar is near the bottom
if (
container.scrollTop + container.clientHeight >=
@@ -9,7 +9,7 @@ import { Media } from '../../shared/models/media.model';
})
export class CustomMediaService {
private backend_apiUrl = environment.API_URL;
private apiAction = 'custom-media';
private apiAction = 'media';
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
refrechEntryById(entryId: number) {
return this.http.put<Entry>(
@@ -20,7 +20,7 @@ export class MaintenanceService {
getMissingFiles() {
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() {
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 {
private scrollEndSubject = new Subject<void>();
private scrollChangeSubject = new Subject<object>();
// Observable for subcomponents to subscribe
scrollEnd$ = this.scrollEndSubject.asObservable();
scrollChange$ = this.scrollChangeSubject.asObservable();
// Emit scroll end event
notifyScrollEnd(): void {
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
datesSet: this.handleDatesSet.bind(this), // month change
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',
};
@@ -45,13 +45,13 @@ export class CalendarPageComponent implements OnInit {
) {}
ngOnInit() {
const today = new Date();
const firstDayOfFirstWeek = this.getFirstMondayOfMonth(today)
.toISOString()
.split('T')[0];
const lastDayOfLastWeek = this.getLastSundayOfMonth(today)
.toISOString()
.split('T')[0];
// const today = new Date();
// const firstDayOfFirstWeek = this.getFirstMondayOfMonth(today)
// .toISOString()
// .split('T')[0];
// const lastDayOfLastWeek = this.getLastSundayOfMonth(today)
// .toISOString()
// .split('T')[0];
// console.log('First Day of First Week:', firstDayOfFirstWeek);
// console.log('Last Day of Last Week:', lastDayOfLastWeek);
@@ -49,7 +49,7 @@
<div *ngIf="isLoading" class="loading-indicator">
Loading...
</div>
<button class="loading-button" (click)="loadNext()">Load More</button>
<button class="loading-button" (click)="loadNext()" *ngIf="maxPage > currentPage">Load More</button>
<!-- Pagination -->
<!-- <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();
private scrollSubscription!: Subscription;
private queryParamsSubscription!: Subscription;
constructor(
private route: ActivatedRoute,
private tmdbService: TmdbService,
@@ -62,12 +62,14 @@ export class SearchPageComponent implements OnInit, OnDestroy {
// this.search(value); // Call your API search function here
});
this.route.queryParams.subscribe((params: any) => {
this.queryParamsSubscription = this.route.queryParams.subscribe(
(params: any) => {
if (params && params['title']) {
let title = params['title'];
this.searchControl.setValue(title);
}
});
}
);
this.scrollSubscription = this.scrollService.scrollEnd$.subscribe(() => {
if (!this.isLoading) {
@@ -81,6 +83,10 @@ export class SearchPageComponent implements OnInit, OnDestroy {
if (this.scrollSubscription) {
this.scrollSubscription.unsubscribe();
}
if (this.queryParamsSubscription) {
this.queryParamsSubscription.unsubscribe();
}
}
setEntryType(entryType: boolean) {
@@ -150,6 +156,8 @@ export class SearchPageComponent implements OnInit, OnDestroy {
.getByKeywordMulti(this.keyword, this.currentPage)
.subscribe({
next: (result) => {
this.maxPage = result.total_pages;
console.log(this.maxPage);
this.entries = this.entries.concat(result.entries as Entry[]);
this.isLoading = false;
},
@@ -303,10 +303,17 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
// ! Match all criteria logic
if (this.filterCriteria.matchAll) {
return (
(formattedTitle
((formattedTitle
? entry.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.every((genre) =>
entry.genres.includes(genre)
@@ -327,10 +334,13 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
? entry.title.toLowerCase().includes(formattedTitle) ||
entry.original_title.toLowerCase().includes(formattedTitle)
: true) ||
(entry.network_studio
? entry.network_studio.toLowerCase() ==
formattedTitle.replace('studio:', '')
: true) ||
entry.networks
.map((network) => network.name.toLowerCase())
.some(
(networkName) =>
networkName ==
formattedTitle.replace('network:', '').toLowerCase()
) ||
(this.filterCriteria.genres?.length &&
this.filterCriteria.genres.some((genre) =>
entry.genres.includes(genre)
@@ -374,8 +384,6 @@ export class LibraryPageComponent implements OnInit, AfterViewInit {
const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize;
console.log(this.pageSize, 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 { Season } from './season.model';
import { Collection } from './collection.model';
import { Network } from './network.model';
export interface Entry {
id: number;
@@ -44,6 +45,7 @@ export interface Entry {
genres: string[];
medias: Media[];
networks: Network[];
poster_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',
};