Browse Source

Use native MD5 to prevent out of memory

master
Menci 8 years ago
parent
commit
ac5ce16747
  1. 3
      models/problem.js
  2. 1
      package.json
  3. 6
      utility.js

3
models/problem.js

@ -117,8 +117,7 @@ class Problem extends Model {
let fs = Promise.promisifyAll(require('fs')); let fs = Promise.promisifyAll(require('fs'));
let buf = await fs.readFileAsync(path); let buf = await fs.readFileAsync(path);
let md5 = require('md5'); let key = syzoj.utils.md5(buf);
let key = md5(buf);
await fs.rename(path, TestData.resolvePath(key)); await fs.rename(path, TestData.resolvePath(key));
let file = await TestData.create({ let file = await TestData.create({

1
package.json

@ -32,7 +32,6 @@
"express-session": "^1.14.1", "express-session": "^1.14.1",
"file-size": "^1.0.0", "file-size": "^1.0.0",
"gravatar": "^1.5.2", "gravatar": "^1.5.2",
"md5": "^2.2.1",
"moemark-renderer": "^1.2.0", "moemark-renderer": "^1.2.0",
"moment": "^2.15.0", "moment": "^2.15.0",
"multer": "^1.2.0", "multer": "^1.2.0",

6
utility.js

@ -220,6 +220,12 @@ module.exports = {
removeTitleTag(s) { removeTitleTag(s) {
return s.replace(/「[\S\s]+?」/, ''); return s.replace(/「[\S\s]+?」/, '');
}, },
md5(data) {
let crypto = require('crypto');
let md5 = crypto.createHash('md5');
md5.update(data);
return md5.digest('hex');
},
async hitokoto() { async hitokoto() {
let request = require('request-promise'); let request = require('request-promise');
return await request({ return await request({

Loading…
Cancel
Save