mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-30 14:03:09 +02:00
[Server] Add some debug messages
This commit is contained in:
parent
7363e3d36b
commit
36ed2c7912
1 changed files with 21 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import * as mongodb from 'mongodb';
|
import * as mongodb from 'mongodb';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import * as gm from 'gm';
|
import * as gm from 'gm';
|
||||||
|
import * as debug from 'debug';
|
||||||
import fileType = require('file-type');
|
import fileType = require('file-type');
|
||||||
import prominence = require('prominence');
|
import prominence = require('prominence');
|
||||||
import DriveFile from '../models/drive-file';
|
import DriveFile from '../models/drive-file';
|
||||||
|
@ -9,6 +10,8 @@ import serialize from '../serializers/drive-file';
|
||||||
import event from '../event';
|
import event from '../event';
|
||||||
import config from '../../conf';
|
import config from '../../conf';
|
||||||
|
|
||||||
|
const log = debug('misskey:register-drive-file');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add file to drive
|
* Add file to drive
|
||||||
*
|
*
|
||||||
|
@ -29,9 +32,13 @@ export default (
|
||||||
folderId: mongodb.ObjectID = null,
|
folderId: mongodb.ObjectID = null,
|
||||||
force: boolean = false
|
force: boolean = false
|
||||||
) => new Promise<any>(async (resolve, reject) => {
|
) => new Promise<any>(async (resolve, reject) => {
|
||||||
|
log(`registering ${name} (user: ${user.username})`);
|
||||||
|
|
||||||
// File size
|
// File size
|
||||||
const size = data.byteLength;
|
const size = data.byteLength;
|
||||||
|
|
||||||
|
log(`size is ${size}`);
|
||||||
|
|
||||||
// File type
|
// File type
|
||||||
let mime = 'application/octet-stream';
|
let mime = 'application/octet-stream';
|
||||||
const type = fileType(data);
|
const type = fileType(data);
|
||||||
|
@ -47,12 +54,16 @@ export default (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log(`type is ${mime}`);
|
||||||
|
|
||||||
// Generate hash
|
// Generate hash
|
||||||
const hash = crypto
|
const hash = crypto
|
||||||
.createHash('sha256')
|
.createHash('sha256')
|
||||||
.update(data)
|
.update(data)
|
||||||
.digest('hex') as string;
|
.digest('hex') as string;
|
||||||
|
|
||||||
|
log(`hash is ${hash}`);
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
// Check if there is a file with the same hash
|
// Check if there is a file with the same hash
|
||||||
const much = await DriveFile.findOne({
|
const much = await DriveFile.findOne({
|
||||||
|
@ -61,8 +72,10 @@ export default (
|
||||||
});
|
});
|
||||||
|
|
||||||
if (much !== null) {
|
if (much !== null) {
|
||||||
resolve(much);
|
log('file with same hash is found');
|
||||||
return;
|
return resolve(much);
|
||||||
|
} else {
|
||||||
|
log('file with same hash is not found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +91,8 @@ export default (
|
||||||
// Calculate drive usage (in byte)
|
// Calculate drive usage (in byte)
|
||||||
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);
|
const usage = files.map(file => file.datasize).reduce((x, y) => x + y, 0);
|
||||||
|
|
||||||
|
log(`drive usage is ${usage}`);
|
||||||
|
|
||||||
// If usage limit exceeded
|
// If usage limit exceeded
|
||||||
if (usage + size > user.drive_capacity) {
|
if (usage + size > user.drive_capacity) {
|
||||||
return reject('no-free-space');
|
return reject('no-free-space');
|
||||||
|
@ -108,6 +123,8 @@ export default (
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height
|
height: size.height
|
||||||
};
|
};
|
||||||
|
|
||||||
|
log('image width and height is calculated');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create DriveFile document
|
// Create DriveFile document
|
||||||
|
@ -124,6 +141,8 @@ export default (
|
||||||
properties: properties
|
properties: properties
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log(`drive file has been created ${file._id}`);
|
||||||
|
|
||||||
resolve(file);
|
resolve(file);
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
|
Loading…
Reference in a new issue