mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Fix:RSS feed covers #1948
This commit is contained in:
		
							parent
							
								
									01b65eb678
								
							
						
					
					
						commit
						22323f606d
					
				| @ -119,6 +119,17 @@ class Database { | ||||
|     return this.sequelize.sync({ force, alter: false }) | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * Compare two server versions | ||||
|    * @param {string} v1  | ||||
|    * @param {string} v2  | ||||
|    * @returns {-1|0|1} 1 if v1 > v2 | ||||
|    */ | ||||
|   compareVersions(v1, v2) { | ||||
|     if (!v1 || !v2) return 0 | ||||
|     return v1.localeCompare(v2, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" }) | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
|    * Checks if migration to sqlite db is necessary & runs migration. | ||||
|    *  | ||||
| @ -142,8 +153,10 @@ class Database { | ||||
|     global.ServerSettings = this.serverSettings.toJSON() | ||||
| 
 | ||||
|     // Version specific migrations
 | ||||
|     if (this.serverSettings.version === '2.3.0' && packageJson.version !== '2.3.0') { | ||||
|     if (this.serverSettings.version === '2.3.0' && this.compareVersions(packageJson.version, '2.3.0') > 1) { | ||||
|       await dbMigration.migrationPatch(this) | ||||
|     } else if (this.serverSettings.version === '2.3.3' && this.compareVersions(packageJson.version, '2.3.3') >= 0) { // TODO: Update to > 1 after 2.3.4
 | ||||
|       await dbMigration.migrationPatch2(this) | ||||
|     } | ||||
| 
 | ||||
|     Logger.info(`[Database] Loading db data...`) | ||||
|  | ||||
| @ -96,6 +96,7 @@ class RssFeedManager { | ||||
| 
 | ||||
|       if (libraryItem && (!feed.entityUpdatedAt || mostRecentlyUpdatedAt > feed.entityUpdatedAt)) { | ||||
|         Logger.debug(`[RssFeedManager] Updating RSS feed for item ${libraryItem.id} "${libraryItem.media.metadata.title}"`) | ||||
| 
 | ||||
|         feed.updateFromItem(libraryItem) | ||||
|         await Database.updateFeed(feed) | ||||
|       } | ||||
|  | ||||
| @ -18,7 +18,6 @@ module.exports = (sequelize) => { | ||||
| 
 | ||||
|     static getOldFeed(feedExpanded) { | ||||
|       const episodes = feedExpanded.feedEpisodes.map((feedEpisode) => feedEpisode.getOldEpisode()) | ||||
| 
 | ||||
|       return new oldFeed({ | ||||
|         id: feedExpanded.id, | ||||
|         slug: feedExpanded.slug, | ||||
| @ -26,6 +25,7 @@ module.exports = (sequelize) => { | ||||
|         entityType: feedExpanded.entityType, | ||||
|         entityId: feedExpanded.entityId, | ||||
|         entityUpdatedAt: feedExpanded.entityUpdatedAt?.valueOf() || null, | ||||
|         coverPath: feedExpanded.coverPath || null, | ||||
|         meta: { | ||||
|           title: feedExpanded.title, | ||||
|           description: feedExpanded.description, | ||||
| @ -174,6 +174,7 @@ module.exports = (sequelize) => { | ||||
|         entityUpdatedAt: oldFeed.entityUpdatedAt, | ||||
|         serverAddress: oldFeed.serverAddress, | ||||
|         feedURL: oldFeed.feedUrl, | ||||
|         coverPath: oldFeed.coverPath || null, | ||||
|         imageURL: oldFeedMeta.imageUrl, | ||||
|         siteURL: oldFeedMeta.link, | ||||
|         title: oldFeedMeta.title, | ||||
| @ -218,7 +219,8 @@ module.exports = (sequelize) => { | ||||
|     ownerName: DataTypes.STRING, | ||||
|     ownerEmail: DataTypes.STRING, | ||||
|     explicit: DataTypes.BOOLEAN, | ||||
|     preventIndexing: DataTypes.BOOLEAN | ||||
|     preventIndexing: DataTypes.BOOLEAN, | ||||
|     coverPath: DataTypes.STRING | ||||
|   }, { | ||||
|     sequelize, | ||||
|     modelName: 'feed' | ||||
|  | ||||
| @ -822,6 +822,7 @@ function migrateFeeds(oldFeeds) { | ||||
|       entityUpdatedAt: oldFeed.entityUpdatedAt, | ||||
|       serverAddress: oldFeed.serverAddress, | ||||
|       feedURL: oldFeed.feedUrl, | ||||
|       coverPath: oldFeed.coverPath || null, | ||||
|       imageURL: oldFeedMeta.imageUrl, | ||||
|       siteURL: oldFeedMeta.link, | ||||
|       title: oldFeedMeta.title, | ||||
| @ -1308,4 +1309,33 @@ module.exports.migrationPatch = async (ctx) => { | ||||
| 
 | ||||
|   const elapsed = Date.now() - migrationStart | ||||
|   Logger.info(`[dbMigration] Migration patch 2.3.0+ finished. Elapsed ${(elapsed / 1000).toFixed(2)}s`) | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Migration from 2.3.3 to 2.3.4 | ||||
|  * Adding coverPath column to Feed model | ||||
|  * @param {/src/Database} ctx  | ||||
|  */ | ||||
| module.exports.migrationPatch2 = async (ctx) => { | ||||
|   const queryInterface = ctx.sequelize.getQueryInterface() | ||||
|   const feedTableDescription = await queryInterface.describeTable('feeds') | ||||
| 
 | ||||
|   if (feedTableDescription?.coverPath) { | ||||
|     Logger.info(`[dbMigration] Migration patch 2.3.3+ - coverPath column is already on model`) | ||||
|     return | ||||
|   } | ||||
| 
 | ||||
|   try { | ||||
|     await queryInterface.sequelize.transaction(t => { | ||||
|       return Promise.all([ | ||||
|         queryInterface.addColumn('feeds', 'coverPath', { | ||||
|           type: DataTypes.STRING | ||||
|         }, { transaction: t }) | ||||
|       ]) | ||||
|     }) | ||||
|     Logger.info(`[dbMigration] Migration patch 2.3.3+ finished`) | ||||
|   } catch (error) { | ||||
|     Logger.error(`[dbMigration] Migration from 2.3.3+ column creation failed`, error) | ||||
|     throw new Error('Migration 2.3.3+ failed ' + error) | ||||
|   } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user