Merge branch 'develop' into fix-msg-room
This commit is contained in:
		
						commit
						b96e98b0f1
					
				
					 34 changed files with 481 additions and 898 deletions
				
			
		
							
								
								
									
										8
									
								
								.github/ISSUE_TEMPLATE/01_bug-report.md
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								.github/ISSUE_TEMPLATE/01_bug-report.md
									
										
									
									
										vendored
									
									
								
							|  | @ -16,11 +16,11 @@ First, in order to avoid duplicate Issues, please search to see if the problem y | |||
| 
 | ||||
| <!-- Tell us what the bug is --> | ||||
| 
 | ||||
| ## 🙂 Expected Behavior | ||||
| ## 🥰 Expected Behavior | ||||
| 
 | ||||
| <!--- Tell us what should happen --> | ||||
| 
 | ||||
| ## ☹️ Actual Behavior | ||||
| ## 🤬 Actual Behavior | ||||
| 
 | ||||
| <!--- Tell us what happens instead of the expected behavior --> | ||||
| 
 | ||||
|  | @ -33,3 +33,7 @@ First, in order to avoid duplicate Issues, please search to see if the problem y | |||
| ## 📌 Environment | ||||
| 
 | ||||
| <!-- Tell us where on the platform it happens --> | ||||
| 
 | ||||
| Misskey version: | ||||
| Your OS: | ||||
| Your browser: | ||||
|  |  | |||
|  | @ -19,12 +19,12 @@ | |||
| 		"@koa/cors": "3.1.0", | ||||
| 		"@koa/multer": "3.0.0", | ||||
| 		"@koa/router": "9.0.1", | ||||
| 		"@sinonjs/fake-timers": "7.1.2", | ||||
| 		"@sinonjs/fake-timers": "9.1.0", | ||||
| 		"@syuilo/aiscript": "0.11.1", | ||||
| 		"@types/bcryptjs": "2.4.2", | ||||
| 		"@types/bull": "3.15.7", | ||||
| 		"@types/cbor": "6.0.0", | ||||
| 		"@types/dateformat": "3.0.1", | ||||
| 		"@types/dateformat": "5.0.0", | ||||
| 		"@types/escape-regexp": "0.0.1", | ||||
| 		"@types/glob": "7.2.0", | ||||
| 		"@types/is-url": "1.2.30", | ||||
|  | @ -43,7 +43,7 @@ | |||
| 		"@types/koa__multer": "2.0.4", | ||||
| 		"@types/koa__router": "8.0.11", | ||||
| 		"@types/mocha": "8.2.3", | ||||
| 		"@types/node": "17.0.10", | ||||
| 		"@types/node": "17.0.14", | ||||
| 		"@types/node-fetch": "3.0.3", | ||||
| 		"@types/nodemailer": "6.4.4", | ||||
| 		"@types/oauth": "0.9.1", | ||||
|  | @ -58,54 +58,52 @@ | |||
| 		"@types/rename": "1.0.4", | ||||
| 		"@types/request-stats": "3.0.0", | ||||
| 		"@types/sanitize-html": "2.6.2", | ||||
| 		"@types/seedrandom": "2.4.28", | ||||
| 		"@types/seedrandom": "3.0.1", | ||||
| 		"@types/sharp": "0.29.5", | ||||
| 		"@types/sinonjs__fake-timers": "6.0.4", | ||||
| 		"@types/sinonjs__fake-timers": "8.1.1", | ||||
| 		"@types/speakeasy": "2.0.7", | ||||
| 		"@types/throttle-debounce": "2.1.0", | ||||
| 		"@types/tinycolor2": "1.4.3", | ||||
| 		"@types/tmp": "0.2.3", | ||||
| 		"@types/uuid": "8.3.4", | ||||
| 		"@types/web-push": "3.3.2", | ||||
| 		"@types/webpack": "5.28.0", | ||||
| 		"@types/webpack-stream": "3.2.12", | ||||
| 		"@types/websocket": "1.0.4", | ||||
| 		"@types/websocket": "1.0.5", | ||||
| 		"@types/ws": "8.2.2", | ||||
| 		"@typescript-eslint/eslint-plugin": "5.10.0", | ||||
| 		"@typescript-eslint/parser": "5.10.0", | ||||
| 		"@typescript-eslint/eslint-plugin": "5.10.2", | ||||
| 		"@typescript-eslint/parser": "5.10.2", | ||||
| 		"abort-controller": "3.0.0", | ||||
| 		"archiver": "5.3.0", | ||||
| 		"autobind-decorator": "2.4.0", | ||||
| 		"autwh": "0.1.0", | ||||
| 		"aws-sdk": "2.1061.0", | ||||
| 		"aws-sdk": "2.1067.0", | ||||
| 		"bcryptjs": "2.4.3", | ||||
| 		"blurhash": "1.1.4", | ||||
| 		"broadcast-channel": "4.9.0", | ||||
| 		"bull": "4.2.1", | ||||
| 		"bull": "4.5.0", | ||||
| 		"cacheable-lookup": "6.0.4", | ||||
| 		"cafy": "15.2.1", | ||||
| 		"cbor": "8.1.0", | ||||
| 		"chalk": "4.1.2", | ||||
| 		"cli-highlight": "2.1.11", | ||||
| 		"content-disposition": "0.5.4", | ||||
| 		"crc-32": "1.2.0", | ||||
| 		"crc-32": "1.2.1", | ||||
| 		"dateformat": "4.5.1", | ||||
| 		"deep-email-validator": "0.1.21", | ||||
| 		"escape-regexp": "0.0.1", | ||||
| 		"eslint": "8.7.0", | ||||
| 		"eslint": "8.8.0", | ||||
| 		"eslint-plugin-import": "2.25.4", | ||||
| 		"eventemitter3": "4.0.7", | ||||
| 		"feed": "4.2.2", | ||||
| 		"file-type": "16.5.3", | ||||
| 		"fluent-ffmpeg": "2.1.2", | ||||
| 		"glob": "7.2.0", | ||||
| 		"got": "11.8.2", | ||||
| 		"got": "12.0.1", | ||||
| 		"hpagent": "0.1.2", | ||||
| 		"http-signature": "1.3.6", | ||||
| 		"ip-cidr": "3.0.4", | ||||
| 		"is-svg": "4.3.2", | ||||
| 		"js-yaml": "4.1.0", | ||||
| 		"jsdom": "16.7.0", | ||||
| 		"jsdom": "19.0.0", | ||||
| 		"json5": "2.2.0", | ||||
| 		"json5-loader": "4.0.1", | ||||
| 		"jsonld": "5.2.0", | ||||
|  | @ -134,7 +132,7 @@ | |||
| 		"pg": "8.7.1", | ||||
| 		"portscanner": "2.2.0", | ||||
| 		"private-ip": "2.3.3", | ||||
| 		"probe-image-size": "7.2.2", | ||||
| 		"probe-image-size": "7.2.3", | ||||
| 		"promise-limit": "2.7.0", | ||||
| 		"pug": "3.0.2", | ||||
| 		"punycode": "2.1.1", | ||||
|  | @ -153,14 +151,14 @@ | |||
| 		"s-age": "1.1.2", | ||||
| 		"sanitize-html": "2.6.1", | ||||
| 		"seedrandom": "3.0.5", | ||||
| 		"sharp": "0.29.3", | ||||
| 		"sharp": "0.30.0", | ||||
| 		"speakeasy": "2.0.0", | ||||
| 		"strict-event-emitter-types": "2.0.0", | ||||
| 		"stringz": "2.1.0", | ||||
| 		"style-loader": "3.3.1", | ||||
| 		"summaly": "2.5.0", | ||||
| 		"syslog-pro": "1.0.0", | ||||
| 		"systeminformation": "5.9.9", | ||||
| 		"systeminformation": "5.11.0", | ||||
| 		"throttle-debounce": "3.0.1", | ||||
| 		"tinycolor2": "1.4.2", | ||||
| 		"tmp": "0.2.1", | ||||
|  |  | |||
|  | @ -38,7 +38,9 @@ export async function downloadUrl(url: string, path: string): Promise<void> { | |||
| 			https: httpsAgent, | ||||
| 		}, | ||||
| 		http2: false,	// default
 | ||||
| 		retry: 0, | ||||
| 		retry: { | ||||
| 			limit: 0, | ||||
| 		}, | ||||
| 	}).on('response', (res: Got.Response) => { | ||||
| 		if ((process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') && !config.proxy && res.ip) { | ||||
| 			if (isPrivateIp(res.ip)) { | ||||
|  | @ -75,7 +77,7 @@ export async function downloadUrl(url: string, path: string): Promise<void> { | |||
| 	logger.succ(`Download finished: ${chalk.cyan(url)}`); | ||||
| } | ||||
| 
 | ||||
| function isPrivateIp(ip: string) { | ||||
| function isPrivateIp(ip: string): boolean { | ||||
| 	for (const net of config.allowedPrivateNetworks || []) { | ||||
| 		const cidr = new IPCIDR(net); | ||||
| 		if (cidr.contains(ip)) { | ||||
|  |  | |||
|  | @ -39,7 +39,7 @@ const sideN = Math.floor(n / 2); | |||
|  */ | ||||
| export function genIdenticon(seed: string, stream: WriteStream): Promise<void> { | ||||
| 	const rand = gen.create(seed); | ||||
| 	const canvas = p.make(size, size); | ||||
| 	const canvas = p.make(size, size, undefined); | ||||
| 	const ctx = canvas.getContext('2d'); | ||||
| 
 | ||||
| 	ctx.fillStyle = bg; | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ export class AbuseUserReportRepository extends Repository<AbuseUserReport> { | |||
| 
 | ||||
| 		return await awaitAll({ | ||||
| 			id: report.id, | ||||
| 			createdAt: report.createdAt, | ||||
| 			createdAt: report.createdAt.toISOString(), | ||||
| 			comment: report.comment, | ||||
| 			resolved: report.resolved, | ||||
| 			reporterId: report.reporterId, | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ export class ModerationLogRepository extends Repository<ModerationLog> { | |||
| 
 | ||||
| 		return await awaitAll({ | ||||
| 			id: log.id, | ||||
| 			createdAt: log.createdAt, | ||||
| 			createdAt: log.createdAt.toISOString(), | ||||
| 			type: log.type, | ||||
| 			info: log.info, | ||||
| 			userId: log.userId, | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ export class NoteFavoriteRepository extends Repository<NoteFavorite> { | |||
| 
 | ||||
| 		return { | ||||
| 			id: favorite.id, | ||||
| 			createdAt: favorite.createdAt, | ||||
| 			createdAt: favorite.createdAt.toISOString(), | ||||
| 			noteId: favorite.noteId, | ||||
| 			note: await Notes.pack(favorite.note || favorite.noteId, me), | ||||
| 		}; | ||||
|  |  | |||
|  | @ -51,7 +51,6 @@ export async function importUserLists(job: Bull.Job<DbUserImportJobData>, done: | |||
| 					createdAt: new Date(), | ||||
| 					userId: user.id, | ||||
| 					name: listName, | ||||
| 					userIds: [], | ||||
| 				}).then(x => UserLists.findOneOrFail(x.identifiers[0])); | ||||
| 			} | ||||
| 
 | ||||
|  | @ -67,9 +66,9 @@ export async function importUserLists(job: Bull.Job<DbUserImportJobData>, done: | |||
| 				target = await resolveUser(username, host); | ||||
| 			} | ||||
| 
 | ||||
| 			if (await UserListJoinings.findOne({ userListId: list.id, userId: target.id }) != null) continue; | ||||
| 			if (await UserListJoinings.findOne({ userListId: list!.id, userId: target.id }) != null) continue; | ||||
| 
 | ||||
| 			pushUserToUserList(target, list); | ||||
| 			pushUserToUserList(target, list!); | ||||
| 		} catch (e) { | ||||
| 			logger.warn(`Error in line:${linenum} ${e}`); | ||||
| 		} | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ export class LdSignature { | |||
| 		} as { | ||||
| 			type: string; | ||||
| 			creator: string; | ||||
| 			domain: string; | ||||
| 			domain?: string; | ||||
| 			nonce: string; | ||||
| 			created: string; | ||||
| 		}; | ||||
|  | @ -114,7 +114,7 @@ export class LdSignature { | |||
| 				Accept: 'application/ld+json, application/json', | ||||
| 			}, | ||||
| 			timeout: this.loderTimeout, | ||||
| 			agent: u => u.protocol == 'http:' ? httpAgent : httpsAgent, | ||||
| 			agent: u => u.protocol === 'http:' ? httpAgent : httpsAgent, | ||||
| 		}).then(res => { | ||||
| 			if (!res.ok) { | ||||
| 				throw `${res.status} ${res.statusText}`; | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ import { In } from 'typeorm'; | |||
| import { Emoji } from '@/models/entities/emoji'; | ||||
| import { Poll } from '@/models/entities/poll'; | ||||
| 
 | ||||
| export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<any> { | ||||
| export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<Record<string, unknown>> { | ||||
| 	const getPromisedFiles = async (ids: string[]) => { | ||||
| 		if (!ids || ids.length === 0) return []; | ||||
| 		const items = await DriveFiles.find({ id: In(ids) }); | ||||
|  |  | |||
|  | @ -6,7 +6,14 @@ | |||
|  * @param last URL of last page (optional) | ||||
|  * @param orderedItems attached objects (optional) | ||||
|  */ | ||||
| export default function(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: Record<string, unknown>) { | ||||
| export default function(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: Record<string, unknown>[]): { | ||||
| 	id: string | null; | ||||
| 	type: 'OrderedCollection'; | ||||
| 	totalItems: any; | ||||
| 	first?: string; | ||||
| 	last?: string; | ||||
| 	orderedItems?: Record<string, unknown>[]; | ||||
| } { | ||||
| 	const page: any = { | ||||
| 		id, | ||||
| 		type: 'OrderedCollection', | ||||
|  |  | |||
|  | @ -32,7 +32,7 @@ export default async (ctx: Router.RouterContext) => { | |||
| 
 | ||||
| 	const rendered = renderOrderedCollection( | ||||
| 		`${config.url}/users/${userId}/collections/featured`, | ||||
| 		renderedNotes.length, undefined, undefined, renderedNotes | ||||
| 		renderedNotes.length, undefined, undefined, renderedNotes, | ||||
| 	); | ||||
| 
 | ||||
| 	ctx.body = renderActivity(rendered); | ||||
|  |  | |||
|  | @ -36,9 +36,9 @@ export default define(meta, async (ps, me) => { | |||
| 
 | ||||
| 	if (ps.forward && report.targetUserHost != null) { | ||||
| 		const actor = await getInstanceActor(); | ||||
| 		const targetUser = await Users.findOne(report.targetUserId); | ||||
| 		const targetUser = await Users.findOneOrFail(report.targetUserId); | ||||
| 
 | ||||
| 		deliver(actor, renderActivity(renderFlag(actor, [targetUser.uri], report.comment)), targetUser.inbox); | ||||
| 		deliver(actor, renderActivity(renderFlag(actor, [targetUser.uri!], report.comment)), targetUser.inbox); | ||||
| 	} | ||||
| 
 | ||||
| 	await AbuseUserReports.update(report.id, { | ||||
|  |  | |||
|  | @ -18,144 +18,6 @@ export const meta = { | |||
| 	res: { | ||||
| 		type: 'object', | ||||
| 		nullable: false, optional: false, | ||||
| 		properties: { | ||||
| 			id: { | ||||
| 				type: 'string', | ||||
| 				nullable: false, optional: false, | ||||
| 				format: 'id', | ||||
| 			}, | ||||
| 			createdAt: { | ||||
| 				type: 'string', | ||||
| 				nullable: false, optional: false, | ||||
| 				format: 'date-time', | ||||
| 			}, | ||||
| 			updatedAt: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 				format: 'date-time', | ||||
| 			}, | ||||
| 			lastFetchedAt: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			username: { | ||||
| 				type: 'string', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			name: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			folowersCount: { | ||||
| 				type: 'number', | ||||
| 				nullable: false, optional: true, | ||||
| 			}, | ||||
| 			followingCount: { | ||||
| 				type: 'number', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			notesCount: { | ||||
| 				type: 'number', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			avatarId: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			bannerId: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			tags: { | ||||
| 				type: 'array', | ||||
| 				nullable: false, optional: false, | ||||
| 				items: { | ||||
| 					type: 'string', | ||||
| 					nullable: false, optional: false, | ||||
| 				}, | ||||
| 			}, | ||||
| 			avatarUrl: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 				format: 'url', | ||||
| 			}, | ||||
| 			bannerUrl: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 				format: 'url', | ||||
| 			}, | ||||
| 			avatarBlurhash: { | ||||
| 				type: 'any', | ||||
| 				nullable: true, optional: false, | ||||
| 				default: null, | ||||
| 			}, | ||||
| 			bannerBlurhash: { | ||||
| 				type: 'any', | ||||
| 				nullable: true, optional: false, | ||||
| 				default: null, | ||||
| 			}, | ||||
| 			isSuspended: { | ||||
| 				type: 'boolean', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			isSilenced: { | ||||
| 				type: 'boolean', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			isLocked: { | ||||
| 				type: 'boolean', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			isBot: { | ||||
| 				type: 'boolean', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			isCat: { | ||||
| 				type: 'boolean', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			isAdmin: { | ||||
| 				type: 'boolean', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			isModerator: { | ||||
| 				type: 'boolean', | ||||
| 				nullable: false, optional: false, | ||||
| 			}, | ||||
| 			emojis: { | ||||
| 				type: 'array', | ||||
| 				nullable: false, optional: false, | ||||
| 				items: { | ||||
| 					type: 'string', | ||||
| 					nullable: false, optional: false, | ||||
| 				}, | ||||
| 			}, | ||||
| 			host: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			inbox: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			sharedInbox: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			featured: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			uri: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 			}, | ||||
| 			token: { | ||||
| 				type: 'string', | ||||
| 				nullable: true, optional: false, | ||||
| 				default: '<MASKED>', | ||||
| 			}, | ||||
| 		}, | ||||
| 	}, | ||||
| } as const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -89,5 +89,9 @@ export default define(meta, async (ps, user) => { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return ps.withUnreads ? announcements.filter((a: any) => !a.isRead) : announcements; | ||||
| 	return (ps.withUnreads ? announcements.filter((a: any) => !a.isRead) : announcements).map((a) => ({ | ||||
| 		...a, | ||||
| 		createdAt: a.createdAt.toISOString(), | ||||
| 		updatedAt: a.updatedAt?.toISOString() ?? null, | ||||
| 	})); | ||||
| }); | ||||
|  |  | |||
|  | @ -114,4 +114,6 @@ export default define(meta, async (ps, me) => { | |||
| 
 | ||||
| 		return await Users.packMany(users, me, { detail: !!ps.detail }); | ||||
| 	} | ||||
| 
 | ||||
| 	return []; | ||||
| }); | ||||
|  |  | |||
|  | @ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta'; | |||
| import { Users, UserProfiles } from '@/models/index'; | ||||
| import { ILocalUser } from '@/models/entities/user'; | ||||
| 
 | ||||
| function getUserToken(ctx: Koa.Context) { | ||||
| function getUserToken(ctx: Koa.BaseContext): string | null { | ||||
| 	return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1]; | ||||
| } | ||||
| 
 | ||||
| function compareOrigin(ctx: Koa.Context) { | ||||
| 	function normalizeUrl(url: string) { | ||||
| function compareOrigin(ctx: Koa.BaseContext): boolean { | ||||
| 	function normalizeUrl(url?: string): string { | ||||
| 		return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : ''; | ||||
| 	} | ||||
| 
 | ||||
| 	const referer = ctx.headers['referer']; | ||||
| 
 | ||||
| 	return (normalizeUrl(referer) == normalizeUrl(config.url)); | ||||
| 	return (normalizeUrl(referer) === normalizeUrl(config.url)); | ||||
| } | ||||
| 
 | ||||
| // Init router
 | ||||
|  |  | |||
|  | @ -11,18 +11,18 @@ import { fetchMeta } from '@/misc/fetch-meta'; | |||
| import { Users, UserProfiles } from '@/models/index'; | ||||
| import { ILocalUser } from '@/models/entities/user'; | ||||
| 
 | ||||
| function getUserToken(ctx: Koa.Context) { | ||||
| function getUserToken(ctx: Koa.BaseContext): string | null { | ||||
| 	return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1]; | ||||
| } | ||||
| 
 | ||||
| function compareOrigin(ctx: Koa.Context) { | ||||
| 	function normalizeUrl(url: string) { | ||||
| function compareOrigin(ctx: Koa.BaseContext): boolean { | ||||
| 	function normalizeUrl(url?: string): string { | ||||
| 		return url ? url.endsWith('/') ? url.substr(0, url.length - 1) : url : ''; | ||||
| 	} | ||||
| 
 | ||||
| 	const referer = ctx.headers['referer']; | ||||
| 
 | ||||
| 	return (normalizeUrl(referer) == normalizeUrl(config.url)); | ||||
| 	return (normalizeUrl(referer) === normalizeUrl(config.url)); | ||||
| } | ||||
| 
 | ||||
| // Init router
 | ||||
|  |  | |||
|  | @ -10,18 +10,18 @@ import { fetchMeta } from '@/misc/fetch-meta'; | |||
| import { Users, UserProfiles } from '@/models/index'; | ||||
| import { ILocalUser } from '@/models/entities/user'; | ||||
| 
 | ||||
| function getUserToken(ctx: Koa.Context) { | ||||
| function getUserToken(ctx: Koa.BaseContext): string | null { | ||||
| 	return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1]; | ||||
| } | ||||
| 
 | ||||
| function compareOrigin(ctx: Koa.Context) { | ||||
| 	function normalizeUrl(url: string) { | ||||
| 		return url.endsWith('/') ? url.substr(0, url.length - 1) : url; | ||||
| function compareOrigin(ctx: Koa.BaseContext): boolean { | ||||
| 	function normalizeUrl(url?: string): string { | ||||
| 		return url == null ? '' : url.endsWith('/') ? url.substr(0, url.length - 1) : url; | ||||
| 	} | ||||
| 
 | ||||
| 	const referer = ctx.headers['referer']; | ||||
| 
 | ||||
| 	return (normalizeUrl(referer) == normalizeUrl(config.url)); | ||||
| 	return (normalizeUrl(referer) === normalizeUrl(config.url)); | ||||
| } | ||||
| 
 | ||||
| // Init router
 | ||||
|  |  | |||
|  | @ -59,7 +59,7 @@ module.exports = (server: http.Server) => { | |||
| 		}); | ||||
| 
 | ||||
| 		connection.on('message', async (data) => { | ||||
| 			if (data.utf8Data === 'ping') { | ||||
| 			if (data.type === 'utf8' && data.utf8Data === 'ping') { | ||||
| 				connection.send('pong'); | ||||
| 			} | ||||
| 		}); | ||||
|  |  | |||
|  | @ -11,6 +11,11 @@ import { FILE_TYPE_BROWSERSAFE } from '@/const'; | |||
| export async function proxyMedia(ctx: Koa.Context) { | ||||
| 	const url = 'url' in ctx.query ? ctx.query.url : 'https://' + ctx.params.url; | ||||
| 
 | ||||
| 	if (typeof url !== 'string') { | ||||
| 		ctx.status = 400; | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	// Create temp file
 | ||||
| 	const [path, cleanup] = await createTemp(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -9,22 +9,34 @@ import { getJson } from '@/misc/fetch'; | |||
| const logger = new Logger('url-preview'); | ||||
| 
 | ||||
| module.exports = async (ctx: Koa.Context) => { | ||||
| 	const url = ctx.query.url; | ||||
| 	if (typeof url !== 'string') { | ||||
| 		ctx.status = 400; | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	const lang = ctx.query.lang; | ||||
| 	if (Array.isArray(lang)) { | ||||
| 		ctx.status = 400; | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	const meta = await fetchMeta(); | ||||
| 
 | ||||
| 	logger.info(meta.summalyProxy | ||||
| 		? `(Proxy) Getting preview of ${ctx.query.url}@${ctx.query.lang} ...` | ||||
| 		: `Getting preview of ${ctx.query.url}@${ctx.query.lang} ...`); | ||||
| 		? `(Proxy) Getting preview of ${url}@${lang} ...` | ||||
| 		: `Getting preview of ${url}@${lang} ...`); | ||||
| 
 | ||||
| 	try { | ||||
| 		const summary = meta.summalyProxy ? await getJson(`${meta.summalyProxy}?${query({ | ||||
| 			url: ctx.query.url, | ||||
| 			lang: ctx.query.lang || 'ja-JP', | ||||
| 		})}`) : await summaly(ctx.query.url, {
 | ||||
| 			url: url, | ||||
| 			lang: lang ?? 'ja-JP', | ||||
| 		})}`) : await summaly(url, {
 | ||||
| 			followRedirects: false, | ||||
| 			lang: ctx.query.lang || 'ja-JP', | ||||
| 			lang: lang ?? 'ja-JP', | ||||
| 		}); | ||||
| 
 | ||||
| 		logger.succ(`Got preview of ${ctx.query.url}: ${summary.title}`); | ||||
| 		logger.succ(`Got preview of ${url}: ${summary.title}`); | ||||
| 
 | ||||
| 		summary.icon = wrap(summary.icon); | ||||
| 		summary.thumbnail = wrap(summary.thumbnail); | ||||
|  | @ -33,8 +45,8 @@ module.exports = async (ctx: Koa.Context) => { | |||
| 		ctx.set('Cache-Control', 'max-age=604800, immutable'); | ||||
| 
 | ||||
| 		ctx.body = summary; | ||||
| 	} catch (e) { | ||||
| 		logger.warn(`Failed to get preview of ${ctx.query.url}: ${e}`); | ||||
| 	} catch (err) { | ||||
| 		logger.warn(`Failed to get preview of ${url}: ${err}`); | ||||
| 		ctx.status = 200; | ||||
| 		ctx.set('Cache-Control', 'max-age=86400, immutable'); | ||||
| 		ctx.body = '{}'; | ||||
|  |  | |||
|  | @ -160,8 +160,8 @@ export async function generateAlts(path: string, type: string, generateWeb: bool | |||
| 				webpublic: null, | ||||
| 				thumbnail, | ||||
| 			}; | ||||
| 		} catch (e) { | ||||
| 			logger.warn(`GenerateVideoThumbnail failed: ${e}`); | ||||
| 		} catch (err) { | ||||
| 			logger.warn(`GenerateVideoThumbnail failed: ${err}`); | ||||
| 			return { | ||||
| 				webpublic: null, | ||||
| 				thumbnail: null, | ||||
|  | @ -191,8 +191,8 @@ export async function generateAlts(path: string, type: string, generateWeb: bool | |||
| 				thumbnail: null, | ||||
| 			}; | ||||
| 		} | ||||
| 	} catch (e) { | ||||
| 		logger.warn(`sharp failed: ${e}`); | ||||
| 	} catch (err) { | ||||
| 		logger.warn(`sharp failed: ${err}`); | ||||
| 		return { | ||||
| 			webpublic: null, | ||||
| 			thumbnail: null, | ||||
|  | @ -215,8 +215,8 @@ export async function generateAlts(path: string, type: string, generateWeb: bool | |||
| 			} else { | ||||
| 				logger.debug(`web image not created (not an required image)`); | ||||
| 			} | ||||
| 		} catch (e) { | ||||
| 			logger.warn(`web image not created (an error occured)`, e); | ||||
| 		} catch (err) { | ||||
| 			logger.warn(`web image not created (an error occured)`, err as Error); | ||||
| 		} | ||||
| 	} else { | ||||
| 		logger.info(`web image not created (from remote)`); | ||||
|  | @ -234,8 +234,8 @@ export async function generateAlts(path: string, type: string, generateWeb: bool | |||
| 		} else { | ||||
| 			logger.debug(`thumbnail not created (not an required file)`); | ||||
| 		} | ||||
| 	} catch (e) { | ||||
| 		logger.warn(`thumbnail not created (an error occured)`, e); | ||||
| 	} catch (err) { | ||||
| 		logger.warn(`thumbnail not created (an error occured)`, err as Error); | ||||
| 	} | ||||
| 	// #endregion thumbnail
 | ||||
| 
 | ||||
|  | @ -451,9 +451,9 @@ export async function addFile({ | |||
| 			file.storedInternal = false; | ||||
| 
 | ||||
| 			file = await DriveFiles.insert(file).then(x => DriveFiles.findOneOrFail(x.identifiers[0])); | ||||
| 		} catch (e) { | ||||
| 		} catch (err) { | ||||
| 			// duplicate key error (when already registered)
 | ||||
| 			if (isDuplicateKeyValueError(e)) { | ||||
| 			if (isDuplicateKeyValueError(err)) { | ||||
| 				logger.info(`already registered ${file.uri}`); | ||||
| 
 | ||||
| 				file = await DriveFiles.findOne({ | ||||
|  | @ -461,8 +461,8 @@ export async function addFile({ | |||
| 					userId: user ? user.id : null, | ||||
| 				}) as DriveFile; | ||||
| 			} else { | ||||
| 				logger.error(e); | ||||
| 				throw e; | ||||
| 				logger.error(err as Error); | ||||
| 				throw err; | ||||
| 			} | ||||
| 		} | ||||
| 	} else { | ||||
|  |  | |||
|  | @ -30,7 +30,7 @@ | |||
| 		"outDir": "./built", | ||||
| 		"typeRoots": [ | ||||
| 			"./node_modules/@types", | ||||
| 			"./@types" | ||||
| 			"./src/@types" | ||||
| 		], | ||||
| 		"lib": [ | ||||
| 			"esnext" | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue