2018-10-07 09:51:46 +02:00
|
|
|
import $ from 'cafy';
|
|
|
|
import DriveFile, { pack } from '../../../../../models/drive-file';
|
2018-11-02 05:47:44 +01:00
|
|
|
import define from '../../../define';
|
2018-10-07 09:51:46 +02:00
|
|
|
|
|
|
|
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: {
|
2018-11-01 19:32:24 +01:00
|
|
|
md5: {
|
|
|
|
validator: $.str,
|
2018-10-07 09:51:46 +02:00
|
|
|
desc: {
|
|
|
|
'ja-JP': 'ファイルのMD5ハッシュ'
|
|
|
|
}
|
2018-11-01 19:32:24 +01:00
|
|
|
}
|
2018-10-07 09:51:46 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-02 05:47:44 +01:00
|
|
|
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
2018-10-07 09:51:46 +02:00
|
|
|
const file = await DriveFile.findOne({
|
2018-11-02 04:49:08 +01:00
|
|
|
md5: ps.md5,
|
2018-10-10 22:26:09 +02:00
|
|
|
'metadata.userId': user._id,
|
|
|
|
'metadata.deletedAt': { $exists: false }
|
2018-10-07 09:51:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (file === null) {
|
|
|
|
res({ file: null });
|
|
|
|
} else {
|
2018-11-25 20:25:48 +01:00
|
|
|
res({ file: await pack(file, { self: true }) });
|
2018-10-07 09:51:46 +02:00
|
|
|
}
|
2018-11-02 05:47:44 +01:00
|
|
|
}));
|