mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	Fix(backend): ActivityPubでのHTMLへのシリアライズを修正 (#13752)
* devモードでもActivityPub系エンドポイントへアクセスできるように * ActivityPubでのHTMLのシリアライズを修正 * ハードコードしていたurlを`httpUrl`へ修正 * テストの追加
This commit is contained in:
		
							parent
							
								
									78e61c65be
								
							
						
					
					
						commit
						20eb4bc296
					
				
					 3 changed files with 27 additions and 3 deletions
				
			
		| 
						 | 
					@ -6,7 +6,7 @@
 | 
				
			||||||
import { URL } from 'node:url';
 | 
					import { URL } from 'node:url';
 | 
				
			||||||
import { Inject, Injectable } from '@nestjs/common';
 | 
					import { Inject, Injectable } from '@nestjs/common';
 | 
				
			||||||
import * as parse5 from 'parse5';
 | 
					import * as parse5 from 'parse5';
 | 
				
			||||||
import { Window } from 'happy-dom';
 | 
					import { Window, XMLSerializer } from 'happy-dom';
 | 
				
			||||||
import { DI } from '@/di-symbols.js';
 | 
					import { DI } from '@/di-symbols.js';
 | 
				
			||||||
import type { Config } from '@/config.js';
 | 
					import type { Config } from '@/config.js';
 | 
				
			||||||
import { intersperse } from '@/misc/prelude/array.js';
 | 
					import { intersperse } from '@/misc/prelude/array.js';
 | 
				
			||||||
| 
						 | 
					@ -247,6 +247,8 @@ export class MfmService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const doc = window.document;
 | 
							const doc = window.document;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							const body = doc.createElement('p');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		function appendChildren(children: mfm.MfmNode[], targetElement: any): void {
 | 
							function appendChildren(children: mfm.MfmNode[], targetElement: any): void {
 | 
				
			||||||
			if (children) {
 | 
								if (children) {
 | 
				
			||||||
				for (const child of children.map(x => (handlers as any)[x.type](x))) targetElement.appendChild(child);
 | 
									for (const child of children.map(x => (handlers as any)[x.type](x))) targetElement.appendChild(child);
 | 
				
			||||||
| 
						 | 
					@ -457,8 +459,8 @@ export class MfmService {
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		appendChildren(nodes, doc.body);
 | 
							appendChildren(nodes, body);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return `<p>${doc.body.innerHTML}</p>`;
 | 
							return new XMLSerializer().serializeToString(body);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,6 +39,12 @@ describe('MfmService', () => {
 | 
				
			||||||
			const output = '<p>foo <i>bar</i></p>';
 | 
								const output = '<p>foo <i>bar</i></p>';
 | 
				
			||||||
			assert.equal(mfmService.toHtml(mfm.parse(input)), output);
 | 
								assert.equal(mfmService.toHtml(mfm.parse(input)), output);
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							test('escape', () => {
 | 
				
			||||||
 | 
								const input = '```\n<p>Hello, world!</p>\n```';
 | 
				
			||||||
 | 
								const output = '<p><pre><code><p>Hello, world!</p></code></pre></p>';
 | 
				
			||||||
 | 
								assert.equal(mfmService.toHtml(mfm.parse(input)), output);
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	describe('fromHtml', () => {
 | 
						describe('fromHtml', () => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,22 @@ const devConfig = {
 | 
				
			||||||
			'/_info_card_': httpUrl,
 | 
								'/_info_card_': httpUrl,
 | 
				
			||||||
			'/bios': httpUrl,
 | 
								'/bios': httpUrl,
 | 
				
			||||||
			'/cli': httpUrl,
 | 
								'/cli': httpUrl,
 | 
				
			||||||
 | 
								'/inbox': httpUrl,
 | 
				
			||||||
 | 
								'/notes': {
 | 
				
			||||||
 | 
									target: httpUrl,
 | 
				
			||||||
 | 
									headers: {
 | 
				
			||||||
 | 
										'Accept': 'application/activity+json',
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								'/users': {
 | 
				
			||||||
 | 
									target: httpUrl,
 | 
				
			||||||
 | 
									headers: {
 | 
				
			||||||
 | 
										'Accept': 'application/activity+json',
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								'/.well-known': {
 | 
				
			||||||
 | 
									target: httpUrl,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	build: {
 | 
						build: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue