diff --git a/backend/models/UserCollection.js b/backend/models/UserCollection.js
index 8cfd1cd..d4c89eb 100644
--- a/backend/models/UserCollection.js
+++ b/backend/models/UserCollection.js
@@ -4,12 +4,18 @@ const sequelize = require('../db/database');
const UserCollection = sequelize.define("userCollection",
{
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
+ tmdbId: { type: DataTypes.STRING(30), field: 'tmdb_id' },
+ imdbId: { type: DataTypes.STRING(30), field: 'imdb_id' },
+ tvdbId: { type: DataTypes.STRING(30), field: 'tvdb_id' },
name: { type: DataTypes.STRING(150) },
- description: { type: DataTypes.STRING(500) },
- user_rating: { type: DataTypes.FLOAT },
+ description: { type: DataTypes.STRING(3000) },
+ isUserCollection: { type: DataTypes.BOOLEAN, defaultValue: false, field: 'is_user_collection' },
+ userRating: { type: DataTypes.FLOAT, field: 'user_rating' },
- poster_path: { type: DataTypes.STRING(200) },
+ posterPath: { type: DataTypes.STRING(200), field: 'poster_path' },
+ backdropPath: { type: DataTypes.STRING(200), field: 'backdrop_path' },
+ isLocal: { type: DataTypes.BOOLEAN, defaultValue: false, field: 'is_local' }
}
);
diff --git a/backend/routes/user-collection.routes.js b/backend/routes/user-collection.routes.js
index 09bd317..ddb05fc 100644
--- a/backend/routes/user-collection.routes.js
+++ b/backend/routes/user-collection.routes.js
@@ -13,28 +13,21 @@ const router = express.Router();
const multer = require('multer');
const { v4: uuidv4 } = require('uuid');
const path = require('path');
-const { getMediaFolder } = require('../services/mediaService');
+const { getMediaFolder, generatePreview } = require('../services/mediaService');
// ! /user-collections
-// * POST - CREATE UserCollection
-router.post('/', async (req, res) => {
- try {
- const { name, description, user_rating, poster_path } = req.body;
- const newUserCollection = await UserCollection.create({ name, description, user_rating, poster_path });
- res.status(201).json(newUserCollection);
- } catch (error) {
- res.status(400).json({ error: error.message });
- }
-});
-
// * GET - ALL UserCollections
router.get('/', async (req, res) => {
let userCollections; // Declare outside to broaden scope, albeit unnecessary in your given context
try {
userCollections = await UserCollection.findAll({
include: [
- { model: UserCollectionEntry, as: 'userCollectionEntries' },
- ]
+ {
+ model: Entry, as: 'entries',
+ include: { model: Media, as: 'medias' }
+ },
+ ],
+ order: [['name', 'ASC']]
});
res.status(200).json(userCollections);
} catch (error) {
@@ -82,6 +75,18 @@ router.get('/:id', async (req, res) => {
}
});
+// * POST - CREATE UserCollection
+router.post('/', async (req, res) => {
+ try {
+ const { name, description, userRating, posterPath } = req.body;
+ const isUserCollection = true;
+ const newUserCollection = await UserCollection.create({ name, description, userRating, posterPath, isUserCollection });
+ res.status(201).json(newUserCollection);
+ } catch (error) {
+ res.status(400).json({ error: error.message });
+ }
+});
+
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, path.join(getMediaFolder(), 'images', 'collections', 'posters'))
@@ -94,23 +99,33 @@ const storage = multer.diskStorage({
});
const upload = multer({ storage: storage });
-
// * PUT - UPDATE A UserCollection
router.put('/:id', upload.single('poster'), async (req, res) => {
try {
const userCollectionId = req.params.id;
- const { name, description, user_rating, is_poster_link } = req.body;
+ const { name, description, userRating, is_poster_link } = req.body;
- let poster_path = req.file ? req.file.filename : undefined;
+ let posterPath = req.file ? req.file.filename : undefined;
const updateData = {
name,
description,
- user_rating: parseInt(user_rating, 10)
+ userRating: parseInt(userRating, 10),
+ isLocal: false,
+
};
- if (poster_path) {
- updateData.poster_path = poster_path;
+ if (posterPath) {
+ updateData.posterPath = posterPath;
+ updateData.isLocal = true;
+
+ // ? generating preview
+ const fileNameWithoutExt = req.file.filename.split('.')[0];
+ const originalPath = req.file.path;
+
+ let previewWidth = 342; // ? poster preview width
+ const previewPath = path.join(req.file.destination, `${fileNameWithoutExt}_preview.jpg`);
+ generatePreview(originalPath, previewPath, previewWidth);
}
const updated = await UserCollection.update(updateData, {
@@ -122,13 +137,16 @@ router.put('/:id', upload.single('poster'), async (req, res) => {
}
if (updated) {
- const updatedUserCollection = await UserCollection.findByPk(req.params.id, {
+ const updatedUserCollection = await UserCollection.findByPk(userCollectionId, {
include: [{
model: Entry,
as: 'entries',
include: [
{ model: EntryId, as: 'entryId' },
- { model: EntryRating, as: 'entryRating' }
+ { model: EntryRating, as: 'entryRating' },
+ { model: Season, as: 'seasons' },
+ { model: Media, as: 'medias' },
+ { model: Genre, as: 'genres' },
],
through: {
model: UserCollectionEntry,
@@ -162,7 +180,6 @@ router.delete('/:id', async (req, res) => {
}
});
-
// * POST - ADD ENTRY TO A UserCollection
router.post('/:userCollectionId/entries/:entryId', async (req, res) => {
try {
diff --git a/frontend/src/app/features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component.html b/frontend/src/app/features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component.html
index 8c62745..140baf8 100644
--- a/frontend/src/app/features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component.html
+++ b/frontend/src/app/features/collections/user-collection-info/collection-edit-modal/collection-edit-modal.component.html
@@ -1,15 +1,15 @@
-
+
Created - {{createdAt}} | Updated - {{updatedAt}}
-
+
diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts
index 51ec8f5..2d008d0 100644
--- a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts
+++ b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts
@@ -109,8 +109,8 @@ export class UserCollectionInfoPageComponent implements OnInit {
data: {
name: this.collection.name,
description: this.collection.description,
- user_rating: this.collection.user_rating || 0,
- poster: this.collection.poster_path,
+ userRating: this.collection.userRating || 0,
+ poster: this.collection.posterPath,
},
});
@@ -179,11 +179,14 @@ export class UserCollectionInfoPageComponent implements OnInit {
const oldViewMode = this.viewMode;
this.viewMode = 'grid';
- this.screenshotService.capture('gridDiv').then(dataUrl => {
- this.copyToClipboard(dataUrl);
- }).catch(error => {
- console.error('Error capturing screenshot:', error);
- });
+ this.screenshotService
+ .capture('gridDiv')
+ .then((dataUrl) => {
+ this.copyToClipboard(dataUrl);
+ })
+ .catch((error) => {
+ console.error('Error capturing screenshot:', error);
+ });
this.screenMode = false;
this.viewMode = oldViewMode;
@@ -198,10 +201,17 @@ export class UserCollectionInfoPageComponent implements OnInit {
canvas.width = img.width;
canvas.height = img.height;
ctx!.drawImage(img, 0, 0);
- canvas.toBlob(blob => {
+ canvas.toBlob((blob) => {
const item = new ClipboardItem({ 'image/png': blob as Blob });
navigator.clipboard.write([item]);
});
};
}
+
+ redirectToTMDB() {
+ window.open(
+ `https://www.themoviedb.org/collection/${this.collection.tmdbId}`,
+ '_blank'
+ );
+ }
}
diff --git a/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.html b/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.html
index 146f456..437fc68 100644
--- a/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.html
+++ b/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.html
@@ -1,6 +1,6 @@
-
![List poster]()
+
{{list.name}}
diff --git a/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.ts b/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.ts
index eb40340..6f59bc9 100644
--- a/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.ts
+++ b/frontend/src/app/features/collections/user-collections/userCollection-list-item/userCollections-list-item.component.ts
@@ -3,6 +3,8 @@ import { UserCollection } from '../../../../shared/models/userCollection.model';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { Router } from '@angular/router';
import { trigger, transition, style, animate } from '@angular/animations';
+import { environment } from '../../../../../environments/environment.prod';
+import { Entry } from '../../../../shared/models/entry.model';
@Component({
selector: 'app-userCollections-list-item',
@@ -30,15 +32,51 @@ export class UserCollectionsListItemComponent {
private router: Router
) {}
- getPostPath() {
- if (this.list.poster_path == null) return 'https://pic.pnnet.dev/256x256';
- if (this.list.poster_path.startsWith('/'))
- return `https://image.tmdb.org/t/p/w500` + this.list.poster_path;
+ getCollectionPosterPath() {
+ if (this.list.isLocal) {
+ if (this.list.posterPath == null)
+ return 'assets/images/default/default-poster.png';
- return (
- `http://localhost:4000/api/v1/media/collections/posters/` +
- this.list.poster_path
- );
+ // * use the collection custom poster
+ return (
+ environment.API_URL +
+ `/media/collections/posters/preview/` +
+ this.list.posterPath
+ );
+ } else {
+ // * use the poster of the first entry in the collection if its no empty
+ if (this.list.entries.length != 0) {
+ return this.getEntryPosterPath(this.list.entries[0]);
+ }
+
+ // * if the collection is empty
+ return 'assets/images/default/default-poster.png';
+ }
+ }
+
+ getEntryPosterPath(entry: Entry) {
+ // * Is in library: use a local poster
+ if (entry.medias) {
+ const selectedPosters = entry.medias.filter(
+ (m) => m.type == 'poster' && m.isSelected
+ );
+
+ if (
+ selectedPosters.length &&
+ selectedPosters[0] &&
+ selectedPosters[0].path
+ ) {
+ const name = selectedPosters[0].path;
+ return environment.API_URL + `/media/entries/posters/preview/${name}`;
+ }
+ }
+
+ // * No local poster available, Use TMDB poster
+ if (entry.poster_path)
+ return `https://image.tmdb.org/t/p/w300` + entry.poster_path;
+
+ // * No poster found, use default poster image as a last stand
+ return 'assets/images/default/default-poster.png';
}
getCreatedDate(): string {
diff --git a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html
index cfcd084..cf929dd 100644
--- a/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html
+++ b/frontend/src/app/features/collections/user-collections/userCollections-page/userCollections-page.component.html
@@ -15,35 +15,41 @@
-