diff options
| author | sei0o inoue <sei0okun@gmail.com> | 2018-10-07 16:51:46 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2018-10-07 16:51:46 +0900 |
| commit | 3e897727ca7c8b0b5ba11c9d1866dc87ea136c22 (patch) | |
| tree | 2bb4f17b3720bdac291dbad1b77c34a53e75cb60 /src/server | |
| parent | V10 (#2826) (diff) | |
| download | sharkey-3e897727ca7c8b0b5ba11c9d1866dc87ea136c22.tar.gz sharkey-3e897727ca7c8b0b5ba11c9d1866dc87ea136c22.tar.bz2 sharkey-3e897727ca7c8b0b5ba11c9d1866dc87ea136c22.zip | |
Fix #2773 (#2841)
* Added an API endpoint to check the existence of the file
* fix #2773: Now we can prevent users from posting the same images
* bug fix
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/api/endpoints/drive/files/check_existence.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/server/api/endpoints/drive/files/check_existence.ts b/src/server/api/endpoints/drive/files/check_existence.ts new file mode 100644 index 0000000000..73d75b7caf --- /dev/null +++ b/src/server/api/endpoints/drive/files/check_existence.ts @@ -0,0 +1,38 @@ +import $ from 'cafy'; +import DriveFile, { pack } from '../../../../../models/drive-file'; +import { ILocalUser } from '../../../../../models/user'; + +export const meta = { + desc: { + 'ja-JP': '与えられたMD5ハッシュ値を持つファイルがドライブに存在するかどうかを返します。', + 'en-US': 'Returns whether the file with the given MD5 hash exists in the user\'s drive.' + }, + + requireCredential: true, + + kind: 'drive-read', + + params: { + md5: $.str.note({ + desc: { + 'ja-JP': 'ファイルのMD5ハッシュ' + } + }) + } +}; + +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { + const [md5, md5Err] = $.str.get(params.md5); + if (md5Err) return rej('invalid md5 param'); + + const file = await DriveFile.findOne({ + md5: md5, + 'metadata.userId': user._id + }); + + if (file === null) { + res({ file: null }); + } else { + res({ file: await pack(file) }); + } +}); |