Implement #2983
This commit is contained in:
		@@ -42,6 +42,11 @@ export type IMetadata = {
 | 
			
		||||
	storageProps?: any;
 | 
			
		||||
	isSensitive?: boolean;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * このファイルが添付された投稿のID一覧
 | 
			
		||||
	 */
 | 
			
		||||
	attachedNoteIds?: mongo.ObjectID[];
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * 外部の(信頼されていない)URLへの直リンクか否か
 | 
			
		||||
	 */
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										48
									
								
								src/server/api/endpoints/drive/files/attached_notes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/server/api/endpoints/drive/files/attached_notes.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
 | 
			
		||||
import DriveFile from '../../../../../models/drive-file';
 | 
			
		||||
import { ILocalUser } from '../../../../../models/user';
 | 
			
		||||
import getParams from '../../../get-params';
 | 
			
		||||
import { packMany } from '../../../../../models/note';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定したドライブのファイルが添付されている投稿一覧を取得します。',
 | 
			
		||||
		'en-US': 'Get the notes that specified file of drive attached.'
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	requireCredential: true,
 | 
			
		||||
 | 
			
		||||
	kind: 'drive-read',
 | 
			
		||||
 | 
			
		||||
	params: {
 | 
			
		||||
		fileId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象のファイルID',
 | 
			
		||||
				'en-US': 'Target file ID'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	const [ps, psErr] = getParams(meta, params);
 | 
			
		||||
	if (psErr) return rej(psErr);
 | 
			
		||||
 | 
			
		||||
	// Fetch file
 | 
			
		||||
	const file = await DriveFile
 | 
			
		||||
		.findOne({
 | 
			
		||||
			_id: ps.fileId,
 | 
			
		||||
			'metadata.userId': user._id,
 | 
			
		||||
			'metadata.deletedAt': { $exists: false }
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
	if (file === null) {
 | 
			
		||||
		return rej('file-not-found');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	res(await packMany(file.metadata.attachedNoteIds || [], user, {
 | 
			
		||||
		detail: true
 | 
			
		||||
	}));
 | 
			
		||||
});
 | 
			
		||||
@@ -8,7 +8,7 @@ import renderNote from '../../remote/activitypub/renderer/note';
 | 
			
		||||
import renderCreate from '../../remote/activitypub/renderer/create';
 | 
			
		||||
import renderAnnounce from '../../remote/activitypub/renderer/announce';
 | 
			
		||||
import packAp from '../../remote/activitypub/renderer';
 | 
			
		||||
import { IDriveFile } from '../../models/drive-file';
 | 
			
		||||
import DriveFile, { IDriveFile } from '../../models/drive-file';
 | 
			
		||||
import notify from '../../notify';
 | 
			
		||||
import NoteWatching from '../../models/note-watching';
 | 
			
		||||
import watch from './watch';
 | 
			
		||||
@@ -173,6 +173,17 @@ export default async (user: IUser, data: Option, silent = false) => new Promise<
 | 
			
		||||
	// ハッシュタグ登録
 | 
			
		||||
	tags.map(tag => registerHashtag(user, tag));
 | 
			
		||||
 | 
			
		||||
	// ファイルが添付されていた場合ドライブのファイルの「このファイルが添付された投稿一覧」プロパティにこの投稿を追加
 | 
			
		||||
	if (data.files) {
 | 
			
		||||
		data.files.forEach(file => {
 | 
			
		||||
			DriveFile.update({ _id: file._id }, {
 | 
			
		||||
				$push: {
 | 
			
		||||
					'metadata.attachedNoteIds': note._id
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Increment notes count
 | 
			
		||||
	incNotesCount(user);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ import perUserNotesChart from '../../chart/per-user-notes';
 | 
			
		||||
import config from '../../config';
 | 
			
		||||
import NoteUnread from '../../models/note-unread';
 | 
			
		||||
import read from './read';
 | 
			
		||||
import DriveFile from '../../models/drive-file';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 投稿を削除します。
 | 
			
		||||
@@ -48,6 +49,17 @@ export default async function(user: IUser, note: INote) {
 | 
			
		||||
		});
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	// ファイルが添付されていた場合ドライブのファイルの「このファイルが添付された投稿一覧」プロパティからこの投稿を削除
 | 
			
		||||
	if (note.fileIds) {
 | 
			
		||||
		note.fileIds.forEach(fileId => {
 | 
			
		||||
			DriveFile.update({ _id: fileId }, {
 | 
			
		||||
				$pull: {
 | 
			
		||||
					'metadata.attachedNoteIds': note._id
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//#region ローカルの投稿なら削除アクティビティを配送
 | 
			
		||||
	if (isLocalUser(user)) {
 | 
			
		||||
		const content = pack(renderDelete(renderTombstone(`${config.url}/notes/${note._id}`), user));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user