feat(server): add emoji publicUrl
This commit is contained in:
		
							parent
							
								
									7627c43dee
								
							
						
					
					
						commit
						fe5e6709a5
					
				
					 11 changed files with 40 additions and 15 deletions
				
			
		
							
								
								
									
										15
									
								
								packages/backend/migration/1642611822809-emoji-url.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								packages/backend/migration/1642611822809-emoji-url.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | ||||||
|  | const { MigrationInterface, QueryRunner } = require("typeorm"); | ||||||
|  | 
 | ||||||
|  | module.exports = class emojiUrl1642611822809 { | ||||||
|  | 		name = 'emojiUrl1642611822809' | ||||||
|  | 
 | ||||||
|  | 		async up(queryRunner) { | ||||||
|  | 			await queryRunner.query(`ALTER TABLE "emoji" RENAME COLUMN "url" TO "originalUrl"`); | ||||||
|  | 			await queryRunner.query(`ALTER TABLE "emoji" ADD "publicUrl" character varying(512) NOT NULL DEFAULT ''`); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		async down(queryRunner) { | ||||||
|  | 			await queryRunner.query(`ALTER TABLE "emoji" DROP COLUMN "originalUrl"`); | ||||||
|  | 			await queryRunner.query(`ALTER TABLE "emoji" RENAME COLUMN "originalUrl" TO "url"`); | ||||||
|  | 		} | ||||||
|  | } | ||||||
|  | @ -62,7 +62,7 @@ export async function populateEmoji(emojiName: string, noteUserHost: string | nu | ||||||
| 	if (emoji == null) return null; | 	if (emoji == null) return null; | ||||||
| 
 | 
 | ||||||
| 	const isLocal = emoji.host == null; | 	const isLocal = emoji.host == null; | ||||||
| 	const url = isLocal ? emoji.url : `${config.url}/proxy/image.png?${query({ url: emoji.url })}`; | 	const url = isLocal ? emoji.publicUrl : `${config.url}/proxy/image.png?${query({ url: emoji.publicUrl })}`; | ||||||
| 
 | 
 | ||||||
| 	return { | 	return { | ||||||
| 		name: emojiName, | 		name: emojiName, | ||||||
|  |  | ||||||
|  | @ -32,13 +32,19 @@ export class Emoji { | ||||||
| 	@Column('varchar', { | 	@Column('varchar', { | ||||||
| 		length: 512, | 		length: 512, | ||||||
| 	}) | 	}) | ||||||
| 	public url: string; | 	public originalUrl: string; | ||||||
|  | 
 | ||||||
|  | 	@Column('varchar', { | ||||||
|  | 		length: 512, | ||||||
|  | 	}) | ||||||
|  | 	public publicUrl: string; | ||||||
| 
 | 
 | ||||||
| 	@Column('varchar', { | 	@Column('varchar', { | ||||||
| 		length: 512, nullable: true, | 		length: 512, nullable: true, | ||||||
| 	}) | 	}) | ||||||
| 	public uri: string | null; | 	public uri: string | null; | ||||||
| 
 | 
 | ||||||
|  | 	// publicUrlの方のtypeが入る
 | ||||||
| 	@Column('varchar', { | 	@Column('varchar', { | ||||||
| 		length: 64, nullable: true, | 		length: 64, nullable: true, | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
|  | @ -15,7 +15,8 @@ export class EmojiRepository extends Repository<Emoji> { | ||||||
| 			name: emoji.name, | 			name: emoji.name, | ||||||
| 			category: emoji.category, | 			category: emoji.category, | ||||||
| 			host: emoji.host, | 			host: emoji.host, | ||||||
| 			url: emoji.url, | 			// || emoji.originalUrl してるのは後方互換性のため
 | ||||||
|  | 			url: emoji.publicUrl || emoji.originalUrl, | ||||||
| 		}; | 		}; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -71,7 +71,7 @@ export async function exportCustomEmojis(job: Bull.Job, done: () => void): Promi | ||||||
| 		let downloaded = false; | 		let downloaded = false; | ||||||
| 
 | 
 | ||||||
| 		try { | 		try { | ||||||
| 			await downloadUrl(emoji.url, emojiPath); | 			await downloadUrl(emoji.originalUrl, emojiPath); | ||||||
| 			downloaded = true; | 			downloaded = true; | ||||||
| 		} catch (e) { // TODO: 何度か再試行
 | 		} catch (e) { // TODO: 何度か再試行
 | ||||||
| 			logger.error(e); | 			logger.error(e); | ||||||
|  |  | ||||||
|  | @ -67,8 +67,9 @@ export async function importCustomEmojis(job: Bull.Job<DbUserImportJobData>, don | ||||||
| 				category: emojiInfo.category, | 				category: emojiInfo.category, | ||||||
| 				host: null, | 				host: null, | ||||||
| 				aliases: emojiInfo.aliases, | 				aliases: emojiInfo.aliases, | ||||||
| 				url: driveFile.url, | 				originalUrl: driveFile.url, | ||||||
| 				type: driveFile.type, | 				publicUrl: driveFile.webpublicUrl ?? driveFile.url, | ||||||
|  | 				type: driveFile.webpublicType ?? driveFile.type, | ||||||
| 			}).then(x => Emojis.findOneOrFail(x.identifiers[0])); | 			}).then(x => Emojis.findOneOrFail(x.identifiers[0])); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -347,7 +347,8 @@ export async function extractEmojis(tags: IObject | IObject[], host: string): Pr | ||||||
| 			host, | 			host, | ||||||
| 			name, | 			name, | ||||||
| 			uri: tag.id, | 			uri: tag.id, | ||||||
| 			url: tag.icon!.url, | 			originalUrl: tag.icon!.url, | ||||||
|  | 			publicUrl: tag.icon!.url, | ||||||
| 			updatedAt: new Date(), | 			updatedAt: new Date(), | ||||||
| 			aliases: [], | 			aliases: [], | ||||||
| 		} as Partial<Emoji>).then(x => Emojis.findOneOrFail(x.identifiers[0])); | 		} as Partial<Emoji>).then(x => Emojis.findOneOrFail(x.identifiers[0])); | ||||||
|  |  | ||||||
|  | @ -9,6 +9,6 @@ export default (emoji: Emoji) => ({ | ||||||
| 	icon: { | 	icon: { | ||||||
| 		type: 'Image', | 		type: 'Image', | ||||||
| 		mediaType: emoji.type || 'image/png', | 		mediaType: emoji.type || 'image/png', | ||||||
| 		url: emoji.url, | 		url: emoji.publicUrl, | ||||||
| 	}, | 	}, | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -45,8 +45,9 @@ export default define(meta, async (ps, me) => { | ||||||
| 		category: null, | 		category: null, | ||||||
| 		host: null, | 		host: null, | ||||||
| 		aliases: [], | 		aliases: [], | ||||||
| 		url: file.url, | 		originalUrl: file.url, | ||||||
| 		type: file.type, | 		publicUrl: file.webpublicUrl ?? file.url, | ||||||
|  | 		type: file.webpublicType ?? file.type, | ||||||
| 	}).then(x => Emojis.findOneOrFail(x.identifiers[0])); | 	}).then(x => Emojis.findOneOrFail(x.identifiers[0])); | ||||||
| 
 | 
 | ||||||
| 	await getConnection().queryResultCache!.remove(['meta_emojis']); | 	await getConnection().queryResultCache!.remove(['meta_emojis']); | ||||||
|  |  | ||||||
|  | @ -54,7 +54,7 @@ export default define(meta, async (ps, me) => { | ||||||
| 
 | 
 | ||||||
| 	try { | 	try { | ||||||
| 		// Create file
 | 		// Create file
 | ||||||
| 		driveFile = await uploadFromUrl(emoji.url, null, null, null, false, true); | 		driveFile = await uploadFromUrl(emoji.originalUrl, null, null, null, false, true); | ||||||
| 	} catch (e) { | 	} catch (e) { | ||||||
| 		throw new ApiError(); | 		throw new ApiError(); | ||||||
| 	} | 	} | ||||||
|  | @ -65,9 +65,9 @@ export default define(meta, async (ps, me) => { | ||||||
| 		name: emoji.name, | 		name: emoji.name, | ||||||
| 		host: null, | 		host: null, | ||||||
| 		aliases: [], | 		aliases: [], | ||||||
| 		url: driveFile.url, | 		originalUrl: driveFile.url, | ||||||
| 		type: driveFile.type, | 		publicUrl: driveFile.webpublicUrl ?? driveFile.url, | ||||||
| 		fileId: driveFile.id, | 		type: driveFile.webpublicType ?? driveFile.type, | ||||||
| 	}).then(x => Emojis.findOneOrFail(x.identifiers[0])); | 	}).then(x => Emojis.findOneOrFail(x.identifiers[0])); | ||||||
| 
 | 
 | ||||||
| 	await getConnection().queryResultCache!.remove(['meta_emojis']); | 	await getConnection().queryResultCache!.remove(['meta_emojis']); | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ export default async (user: { id: User['id']; host: User['host']; }, note: Note, | ||||||
| 	if (emoji) { | 	if (emoji) { | ||||||
| 		emoji = { | 		emoji = { | ||||||
| 			name: emoji.host ? `${emoji.name}@${emoji.host}` : `${emoji.name}@.`, | 			name: emoji.host ? `${emoji.name}@${emoji.host}` : `${emoji.name}@.`, | ||||||
| 			url: emoji.url, | 			url: emoji.publicUrl, | ||||||
| 		} as any; | 		} as any; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue