| @@ -28,29 +28,41 @@ export async function importFollowing(job: Bull.Job, done: any): Promise<void> { | ||||
|  | ||||
| 	const csv = await downloadTextFile(url); | ||||
|  | ||||
| 	let linenum = 0; | ||||
|  | ||||
| 	for (const line of csv.trim().split('\n')) { | ||||
| 		const { username, host } = parseAcct(line.trim()); | ||||
| 		linenum++; | ||||
|  | ||||
| 		let target = isSelfHost(host) ? await User.findOne({ | ||||
| 			host: null, | ||||
| 			usernameLower: username.toLowerCase() | ||||
| 		}) : await User.findOne({ | ||||
| 			host: toDbHost(host), | ||||
| 			usernameLower: username.toLowerCase() | ||||
| 		}); | ||||
| 		try { | ||||
| 			const { username, host } = parseAcct(line.trim()); | ||||
|  | ||||
| 		if (host == null && target == null) continue; | ||||
| 			let target = isSelfHost(host) ? await User.findOne({ | ||||
| 				host: null, | ||||
| 				usernameLower: username.toLowerCase() | ||||
| 			}) : await User.findOne({ | ||||
| 				host: toDbHost(host), | ||||
| 				usernameLower: username.toLowerCase() | ||||
| 			}); | ||||
|  | ||||
| 		if (target == null) { | ||||
| 			target = await resolveUser(username, host); | ||||
| 			if (host == null && target == null) continue; | ||||
|  | ||||
| 			if (target == null) { | ||||
| 				target = await resolveUser(username, host); | ||||
| 			} | ||||
|  | ||||
| 			if (target == null) { | ||||
| 				throw `cannot resolve user: @${username}@${host}`; | ||||
| 			} | ||||
|  | ||||
| 			// skip myself | ||||
| 			if (target._id.equals(job.data.user._id)) continue; | ||||
|  | ||||
| 			logger.info(`Follow[${linenum}] ${target._id} ...`); | ||||
|  | ||||
| 			follow(user, target); | ||||
| 		} catch (e) { | ||||
| 			logger.warn(`Error in line:${linenum} ${e}`); | ||||
| 		} | ||||
|  | ||||
| 		// skip myself | ||||
| 		if (target._id.equals(job.data.user._id)) continue; | ||||
|  | ||||
| 		logger.info(`Follow ${target._id} ...`); | ||||
|  | ||||
| 		follow(user, target); | ||||
| 	} | ||||
|  | ||||
| 	logger.succ('Imported'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 MeiMei
					MeiMei