summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/common/add-file-to-drive.ts23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/api/common/add-file-to-drive.ts b/src/api/common/add-file-to-drive.ts
index b4e3773c19..77d116cb41 100644
--- a/src/api/common/add-file-to-drive.ts
+++ b/src/api/common/add-file-to-drive.ts
@@ -1,6 +1,7 @@
import * as mongodb from 'mongodb';
import * as crypto from 'crypto';
import * as gm from 'gm';
+import * as debug from 'debug';
import fileType = require('file-type');
import prominence = require('prominence');
import DriveFile from '../models/drive-file';
@@ -9,6 +10,8 @@ import serialize from '../serializers/drive-file';
import event from '../event';
import config from '../../conf';
+const log = debug('misskey:register-drive-file');
+
/**
* Add file to drive
*
@@ -29,9 +32,13 @@ export default (
folderId: mongodb.ObjectID = null,
force: boolean = false
) => new Promise<any>(async (resolve, reject) => {
+ log(`registering ${name} (user: ${user.username})`);
+
// File size
const size = data.byteLength;
+ log(`size is ${size}`);
+
// File type
let mime = 'application/octet-stream';
const type = fileType(data);
@@ -47,12 +54,16 @@ export default (
}
}
+ log(`type is ${mime}`);
+
// Generate hash
const hash = crypto
.createHash('sha256')
.update(data)
.digest('hex') as string;
+ log(`hash is ${hash}`);
+
if (!force) {
// Check if there is a file with the same hash
const much = await DriveFile.findOne({
@@ -61,8 +72,10 @@ export default (
});
if (much !== null) {
- resolve(much);
- return;
+ log('file with same hash is found');
+ return resolve(much);
+ } else {
+ log('file with same hash is not found');
}
}
@@ -78,6 +91,8 @@ export default (
// Calculate drive usage (in byte)
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);
+ log(`drive usage is ${usage}`);
+
// If usage limit exceeded
if (usage + size > user.drive_capacity) {
return reject('no-free-space');
@@ -108,6 +123,8 @@ export default (
width: size.width,
height: size.height
};
+
+ log('image width and height is calculated');
}
// Create DriveFile document
@@ -124,6 +141,8 @@ export default (
properties: properties
});
+ log(`drive file has been created ${file._id}`);
+
resolve(file);
// Serialize