This commit is contained in:
		| @@ -58,7 +58,7 @@ export default async (ctx: Router.IRouterContext) => { | ||||
| 				$or: [{ | ||||
| 					text: { $ne: null } | ||||
| 				}, { | ||||
| 					mediaIds: { $ne: [] } | ||||
| 					fileIds: { $ne: [] } | ||||
| 				}] | ||||
| 			}] | ||||
| 		} as any; | ||||
|   | ||||
| @@ -20,9 +20,9 @@ export default (params: any) => new Promise(async (res, rej) => { | ||||
| 	const [renote, renoteErr] = $.bool.optional.get(params.renote); | ||||
| 	if (renoteErr) return rej('invalid renote param'); | ||||
|  | ||||
| 	// Get 'media' parameter | ||||
| 	const [media, mediaErr] = $.bool.optional.get(params.media); | ||||
| 	if (mediaErr) return rej('invalid media param'); | ||||
| 	// Get 'files' parameter | ||||
| 	const [files, filesErr] = $.bool.optional.get(params.files); | ||||
| 	if (filesErr) return rej('invalid files param'); | ||||
|  | ||||
| 	// Get 'poll' parameter | ||||
| 	const [poll, pollErr] = $.bool.optional.get(params.poll); | ||||
| @@ -79,8 +79,8 @@ export default (params: any) => new Promise(async (res, rej) => { | ||||
| 		query.renoteId = renote ? { $exists: true, $ne: null } : null; | ||||
| 	} | ||||
|  | ||||
| 	if (media != undefined) { | ||||
| 		query.mediaIds = media ? { $exists: true, $ne: null } : []; | ||||
| 	if (files != undefined) { | ||||
| 		query.fileIds = files ? { $exists: true, $ne: null } : []; | ||||
| 	} | ||||
|  | ||||
| 	if (poll != undefined) { | ||||
|   | ||||
| @@ -71,9 +71,15 @@ export const meta = { | ||||
| 			ref: 'geo' | ||||
| 		}), | ||||
|  | ||||
| 		fileIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({ | ||||
| 			desc: { | ||||
| 				'ja-JP': '添付するファイル' | ||||
| 			} | ||||
| 		}), | ||||
|  | ||||
| 		mediaIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({ | ||||
| 			desc: { | ||||
| 				'ja-JP': '添付するメディア' | ||||
| 				'ja-JP': '添付するファイル (このパラメータは廃止予定です。代わりに fileIds を使ってください。)' | ||||
| 			} | ||||
| 		}), | ||||
|  | ||||
| @@ -124,15 +130,16 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async ( | ||||
| 	} | ||||
|  | ||||
| 	let files: IDriveFile[] = []; | ||||
| 	if (ps.mediaIds !== undefined) { | ||||
| 	const fileIds = ps.fileIds != null ? ps.fileIds : ps.mediaIds != null ? ps.mediaIds : null; | ||||
| 	if (fileIds != null) { | ||||
| 		// Fetch files | ||||
| 		// forEach だと途中でエラーなどがあっても return できないので | ||||
| 		// 敢えて for を使っています。 | ||||
| 		for (const mediaId of ps.mediaIds) { | ||||
| 		for (const fileId of fileIds) { | ||||
| 			// Fetch file | ||||
| 			// SELECT _id | ||||
| 			const entity = await DriveFile.findOne({ | ||||
| 				_id: mediaId, | ||||
| 				_id: fileId, | ||||
| 				'metadata.userId': user._id | ||||
| 			}); | ||||
|  | ||||
| @@ -155,7 +162,7 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async ( | ||||
|  | ||||
| 		if (renote == null) { | ||||
| 			return rej('renoteee is not found'); | ||||
| 		} else if (renote.renoteId && !renote.text && !renote.mediaIds) { | ||||
| 		} else if (renote.renoteId && !renote.text && !renote.fileIds) { | ||||
| 			return rej('cannot renote to renote'); | ||||
| 		} | ||||
| 	} | ||||
| @@ -176,7 +183,7 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async ( | ||||
| 		} | ||||
|  | ||||
| 		// 返信対象が引用でないRenoteだったらエラー | ||||
| 		if (reply.renoteId && !reply.text && !reply.mediaIds) { | ||||
| 		if (reply.renoteId && !reply.text && !reply.fileIds) { | ||||
| 			return rej('cannot reply to renote'); | ||||
| 		} | ||||
| 	} | ||||
| @@ -191,13 +198,13 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async ( | ||||
|  | ||||
| 	// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー | ||||
| 	if ((ps.text === undefined || ps.text === null) && files === null && renote === null && ps.poll === undefined) { | ||||
| 		return rej('text, mediaIds, renoteId or poll is required'); | ||||
| 		return rej('text, fileIds, renoteId or poll is required'); | ||||
| 	} | ||||
|  | ||||
| 	// 投稿を作成 | ||||
| 	const note = await create(user, { | ||||
| 		createdAt: new Date(), | ||||
| 		media: files, | ||||
| 		files: files, | ||||
| 		poll: ps.poll, | ||||
| 		text: ps.text, | ||||
| 		reply, | ||||
|   | ||||
| @@ -33,9 +33,9 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 		throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified'; | ||||
| 	} | ||||
|  | ||||
| 	// Get 'mediaOnly' parameter | ||||
| 	const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly); | ||||
| 	if (mediaOnlyErr) throw 'invalid mediaOnly param'; | ||||
| 	// Get 'withFiles' parameter | ||||
| 	const [withFiles, withFilesErr] = $.bool.optional.get(params.withFiles); | ||||
| 	if (withFilesErr) throw 'invalid withFiles param'; | ||||
|  | ||||
| 	// ミュートしているユーザーを取得 | ||||
| 	const mutedUserIds = user ? (await Mute.find({ | ||||
| @@ -68,8 +68,8 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| 	if (mediaOnly) { | ||||
| 		query.mediaIds = { $exists: true, $ne: [] }; | ||||
| 	if (withFiles) { | ||||
| 		query.fileIds = { $exists: true, $ne: [] }; | ||||
| 	} | ||||
|  | ||||
| 	if (sinceId) { | ||||
|   | ||||
| @@ -66,7 +66,7 @@ export const meta = { | ||||
| 			} | ||||
| 		}), | ||||
|  | ||||
| 		mediaOnly: $.bool.optional.note({ | ||||
| 		withFiles: $.bool.optional.note({ | ||||
| 			desc: { | ||||
| 				'ja-JP': 'true にすると、メディアが添付された投稿だけ取得します' | ||||
| 			} | ||||
| @@ -164,7 +164,7 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| @@ -180,7 +180,7 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| @@ -196,16 +196,16 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	if (ps.mediaOnly) { | ||||
| 	if (ps.withFiles) { | ||||
| 		query.$and.push({ | ||||
| 			mediaIds: { $exists: true, $ne: [] } | ||||
| 			fileIds: { $exists: true, $ne: [] } | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -33,9 +33,9 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 		throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified'; | ||||
| 	} | ||||
|  | ||||
| 	// Get 'mediaOnly' parameter | ||||
| 	const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly); | ||||
| 	if (mediaOnlyErr) throw 'invalid mediaOnly param'; | ||||
| 	// Get 'withFiles' parameter | ||||
| 	const [withFiles, withFilesErr] = $.bool.optional.get(params.withFiles); | ||||
| 	if (withFilesErr) throw 'invalid withFiles param'; | ||||
|  | ||||
| 	// ミュートしているユーザーを取得 | ||||
| 	const mutedUserIds = user ? (await Mute.find({ | ||||
| @@ -69,8 +69,8 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| 	if (mediaOnly) { | ||||
| 		query.mediaIds = { $exists: true, $ne: [] }; | ||||
| 	if (withFiles) { | ||||
| 		query.fileIds = { $exists: true, $ne: [] }; | ||||
| 	} | ||||
|  | ||||
| 	if (sinceId) { | ||||
|   | ||||
| @@ -247,7 +247,7 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => | ||||
| 	if (media != null) { | ||||
| 		if (media) { | ||||
| 			push({ | ||||
| 				mediaIds: { | ||||
| 				fileIds: { | ||||
| 					$exists: true, | ||||
| 					$ne: null | ||||
| 				} | ||||
| @@ -255,11 +255,11 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => | ||||
| 		} else { | ||||
| 			push({ | ||||
| 				$or: [{ | ||||
| 					mediaIds: { | ||||
| 					fileIds: { | ||||
| 						$exists: false | ||||
| 					} | ||||
| 				}, { | ||||
| 					mediaIds: null | ||||
| 					fileIds: null | ||||
| 				}] | ||||
| 			}); | ||||
| 		} | ||||
|   | ||||
| @@ -67,7 +67,7 @@ export const meta = { | ||||
| 			} | ||||
| 		}), | ||||
|  | ||||
| 		mediaOnly: $.bool.optional.note({ | ||||
| 		withFiles: $.bool.optional.note({ | ||||
| 			desc: { | ||||
| 				'ja-JP': 'true にすると、メディアが添付された投稿だけ取得します' | ||||
| 			} | ||||
| @@ -154,7 +154,7 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| @@ -170,7 +170,7 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| @@ -186,16 +186,16 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	if (ps.mediaOnly) { | ||||
| 	if (ps.withFiles) { | ||||
| 		query.$and.push({ | ||||
| 			mediaIds: { $exists: true, $ne: [] } | ||||
| 			fileIds: { $exists: true, $ne: [] } | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -52,7 +52,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = | ||||
| 	} | ||||
|  | ||||
| 	if (media != undefined) { | ||||
| 		query.mediaIds = media ? { $exists: true, $ne: null } : null; | ||||
| 		query.fileIds = media ? { $exists: true, $ne: null } : null; | ||||
| 	} | ||||
|  | ||||
| 	if (poll != undefined) { | ||||
|   | ||||
| @@ -73,7 +73,7 @@ export const meta = { | ||||
| 			} | ||||
| 		}), | ||||
|  | ||||
| 		mediaOnly: $.bool.optional.note({ | ||||
| 		withFiles: $.bool.optional.note({ | ||||
| 			desc: { | ||||
| 				'ja-JP': 'true にすると、メディアが添付された投稿だけ取得します' | ||||
| 			} | ||||
| @@ -160,7 +160,7 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| @@ -176,7 +176,7 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| @@ -192,16 +192,16 @@ export default async (params: any, user: ILocalUser) => { | ||||
| 			}, { | ||||
| 				text: { $ne: null } | ||||
| 			}, { | ||||
| 				mediaIds: { $ne: [] } | ||||
| 				fileIds: { $ne: [] } | ||||
| 			}, { | ||||
| 				poll: { $ne: null } | ||||
| 			}] | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	if (ps.mediaOnly) { | ||||
| 	if (ps.withFiles) { | ||||
| 		query.$and.push({ | ||||
| 			mediaIds: { $exists: true, $ne: [] } | ||||
| 			fileIds: { $exists: true, $ne: [] } | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -27,9 +27,9 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => | ||||
| 	const [includeReplies = true, includeRepliesErr] = $.bool.optional.get(params.includeReplies); | ||||
| 	if (includeRepliesErr) return rej('invalid includeReplies param'); | ||||
|  | ||||
| 	// Get 'withMedia' parameter | ||||
| 	const [withMedia = false, withMediaErr] = $.bool.optional.get(params.withMedia); | ||||
| 	if (withMediaErr) return rej('invalid withMedia param'); | ||||
| 	// Get 'withFiles' parameter | ||||
| 	const [withFiles = false, withFilesErr] = $.bool.optional.get(params.withFiles); | ||||
| 	if (withFilesErr) return rej('invalid withFiles param'); | ||||
|  | ||||
| 	// Get 'limit' parameter | ||||
| 	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); | ||||
| @@ -104,8 +104,8 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => | ||||
| 		query.replyId = null; | ||||
| 	} | ||||
|  | ||||
| 	if (withMedia) { | ||||
| 		query.mediaIds = { | ||||
| 	if (withFiles) { | ||||
| 		query.fileIds = { | ||||
| 			$exists: true, | ||||
| 			$ne: [] | ||||
| 		}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo