embed.jsをサーバーから提供
This commit is contained in:
		
							
								
								
									
										31
									
								
								packages/backend/assets/embed.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								packages/backend/assets/embed.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-FileCopyrightText: syuilo and misskey-project
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: MIT
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					//@ts-check
 | 
				
			||||||
 | 
					(() => {
 | 
				
			||||||
 | 
						/** @type {NodeListOf<HTMLIFrameElement>} */
 | 
				
			||||||
 | 
						const els = document.querySelectorAll('iframe[data-misskey-embed-id]');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						window.addEventListener('message', function (event) {
 | 
				
			||||||
 | 
							els.forEach((el) => {
 | 
				
			||||||
 | 
								if (event.source !== el.contentWindow) {
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const id = el.dataset.misskeyEmbedId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (event.data.type === 'misskey:embed:ready') {
 | 
				
			||||||
 | 
									el.contentWindow?.postMessage({
 | 
				
			||||||
 | 
										type: 'misskey:embedParent:registerIframeId',
 | 
				
			||||||
 | 
										payload: {
 | 
				
			||||||
 | 
											iframeId: id,
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}, '*');
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (event.data.type === 'misskey:embed:changeHeight' && event.data.iframeId === id) {
 | 
				
			||||||
 | 
									el.style.height = event.data.payload.height + 'px';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
@@ -425,6 +425,13 @@ export class ClientServerService {
 | 
				
			|||||||
		// Manifest
 | 
							// Manifest
 | 
				
			||||||
		fastify.get('/manifest.json', async (request, reply) => await this.manifestHandler(reply));
 | 
							fastify.get('/manifest.json', async (request, reply) => await this.manifestHandler(reply));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Embed Javascript
 | 
				
			||||||
 | 
							fastify.get('/embed.js', async (request, reply) => {
 | 
				
			||||||
 | 
								return await reply.sendFile('/embed.js', staticAssets, {
 | 
				
			||||||
 | 
									maxAge: ms('1 day'),
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fastify.get('/robots.txt', async (request, reply) => {
 | 
							fastify.get('/robots.txt', async (request, reply) => {
 | 
				
			||||||
			return await reply.sendFile('/robots.txt', staticAssets);
 | 
								return await reply.sendFile('/robots.txt', staticAssets);
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,6 +40,8 @@ const devConfig = {
 | 
				
			|||||||
				ws: true,
 | 
									ws: true,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			'/favicon.ico': httpUrl,
 | 
								'/favicon.ico': httpUrl,
 | 
				
			||||||
 | 
								'/robots.txt': httpUrl,
 | 
				
			||||||
 | 
								'/embed.js': httpUrl,
 | 
				
			||||||
			'/identicon': {
 | 
								'/identicon': {
 | 
				
			||||||
				target: httpUrl,
 | 
									target: httpUrl,
 | 
				
			||||||
				rewrite(path) {
 | 
									rewrite(path) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user