Fix: Punycodeなインスタンスが重複登録される (#4667)
This commit is contained in:
		
							parent
							
								
									6abc053a48
								
							
						
					
					
						commit
						81006566a5
					
				
					 2 changed files with 6 additions and 2 deletions
				
			
		|  | @ -16,7 +16,8 @@ import discord from './service/discord'; | |||
| import github from './service/github'; | ||||
| import twitter from './service/twitter'; | ||||
| import Instance from '../../models/instance'; | ||||
| import { toASCII } from 'punycode'; | ||||
| import { toApHost } from '../../misc/convert-host'; | ||||
| import { unique } from '../../prelude/array'; | ||||
| 
 | ||||
| // Init app
 | ||||
| const app = new Koa(); | ||||
|  | @ -72,7 +73,7 @@ router.get('/v1/instance/peers', async ctx => { | |||
| 			host: 1 | ||||
| 		}); | ||||
| 
 | ||||
| 	const punyCodes = instances.map(instance => toASCII(instance.host)); | ||||
| 	const punyCodes = unique(instances.map(instance => toApHost(instance.host))); | ||||
| 
 | ||||
| 	ctx.body = punyCodes; | ||||
| }); | ||||
|  |  | |||
|  | @ -1,9 +1,12 @@ | |||
| import Instance, { IInstance } from '../models/instance'; | ||||
| import federationChart from '../services/chart/federation'; | ||||
| import { toDbHost } from '../misc/convert-host'; | ||||
| 
 | ||||
| export async function registerOrFetchInstanceDoc(host: string): Promise<IInstance> { | ||||
| 	if (host == null) return null; | ||||
| 
 | ||||
| 	host = toDbHost(host); | ||||
| 
 | ||||
| 	const index = await Instance.findOne({ host }); | ||||
| 
 | ||||
| 	if (index == null) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue