mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-05-07 21:19:08 -05:00
Use upsert when importing libraries.
This commit is contained in:
@@ -3,6 +3,7 @@ import plexService from '../../../services/plexApi';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// users
|
||||
router.get('/users', plexService.getUsers);
|
||||
router.get('/most-watched', plexService.getMostWatched);
|
||||
router.get('/sections', plexService.getSections);
|
||||
|
||||
@@ -7,7 +7,7 @@ const sequelize = new Sequelize(
|
||||
{
|
||||
dialect: 'postgres',
|
||||
host: 'localhost',
|
||||
logging: false,
|
||||
// logging: false,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const plexLibrary = (sequelize, DataTypes) => {
|
||||
const plexLibrary = sequelize.define('plex_library', {
|
||||
title: DataTypes.STRING,
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
unique: true,
|
||||
},
|
||||
type: DataTypes.STRING,
|
||||
views: DataTypes.INTEGER,
|
||||
rating_key: DataTypes.INTEGER,
|
||||
|
||||
@@ -39,18 +39,25 @@ const importLibrary = async sectionId => {
|
||||
const createLibrary = libraryData => {
|
||||
console.log(libraryData[1]);
|
||||
libraryData.forEach(async data => {
|
||||
await models.PlexLibrary.create({
|
||||
userId: 1,
|
||||
title: data.title,
|
||||
type: data.type,
|
||||
views: data.views,
|
||||
rating_key: data.ratingKey,
|
||||
metadata_path: data.key,
|
||||
summary: data.summary,
|
||||
rating: data.rating,
|
||||
year: data.year,
|
||||
genre: JSON.stringify(data.Genre),
|
||||
});
|
||||
await models.PlexLibrary.upsert(
|
||||
{
|
||||
userId: 1,
|
||||
title: data.title,
|
||||
type: data.type,
|
||||
views: data.views,
|
||||
rating_key: data.ratingKey,
|
||||
metadata_path: data.key,
|
||||
summary: data.summary,
|
||||
rating: data.rating,
|
||||
year: data.year,
|
||||
genre: JSON.stringify(data.Genre),
|
||||
},
|
||||
{
|
||||
where: {
|
||||
title: data.title,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -45,9 +45,10 @@ PlexApiClient.prototype.mostWatchedUrlParams = function(req) {
|
||||
};
|
||||
|
||||
PlexApiClient.prototype.getLibraryDataBySectionUrlParams = function(req) {
|
||||
const sectionId = req.sectionId || req.params.id;
|
||||
return {
|
||||
host: config.plex.plexServerUrl,
|
||||
path: `/library/sections/${req.params.id}/all`,
|
||||
path: `/library/sections/${sectionId}/all`,
|
||||
queryParams: {
|
||||
'X-Plex-Token': this.options.token || config.plex.token,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user