良い感じにした
This commit is contained in:
parent
6372451d17
commit
ab7725ff69
|
@ -10,7 +10,7 @@ import DriveFileThumbnail, { deleteDriveFileThumbnail } from './drive-file-thumb
|
|||
|
||||
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
|
||||
DriveFile.createIndex('md5');
|
||||
DriveFile.createIndex('metadata.uri', { sparse: true, unique: true });
|
||||
DriveFile.createIndex(['metadata.uri', 'metadata.userId'], { sparse: true, unique: true });
|
||||
export default DriveFile;
|
||||
|
||||
export const DriveFileChunk = monkDb.get('driveFiles.chunks');
|
||||
|
|
|
@ -294,16 +294,35 @@ export default async function(
|
|||
metadata.uri = uri;
|
||||
}
|
||||
|
||||
const driveFile = isLink
|
||||
? await DriveFile.insert({
|
||||
let driveFile: IDriveFile;
|
||||
|
||||
if (isLink) {
|
||||
try {
|
||||
driveFile = await DriveFile.insert({
|
||||
length: 0,
|
||||
uploadDate: new Date(),
|
||||
md5: hash,
|
||||
filename: detectedName,
|
||||
metadata: metadata,
|
||||
contentType: mime
|
||||
})
|
||||
: await (save(fs.createReadStream(path), detectedName, mime, hash, size, metadata));
|
||||
});
|
||||
} catch (e) {
|
||||
// duplicate key error (when already registered)
|
||||
if (e.code === 11000) {
|
||||
log(`already registered ${metadata.uri}`);
|
||||
|
||||
driveFile = await DriveFile.findOne({
|
||||
'metadata.uri': metadata.uri,
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
} else {
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
driveFile = await (save(fs.createReadStream(path), detectedName, mime, hash, size, metadata));
|
||||
}
|
||||
|
||||
log(`drive file has been created ${driveFile._id}`);
|
||||
|
||||
|
|
Loading…
Reference in a new issue