From ac5ce167473a76d63cbae91248bede400c69d1c3 Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 16 Jan 2017 20:08:03 +0800 Subject: [PATCH] Use native MD5 to prevent out of memory --- models/problem.js | 3 +-- package.json | 1 - utility.js | 6 ++++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/models/problem.js b/models/problem.js index 51fceb3..ffe77e7 100644 --- a/models/problem.js +++ b/models/problem.js @@ -117,8 +117,7 @@ class Problem extends Model { let fs = Promise.promisifyAll(require('fs')); let buf = await fs.readFileAsync(path); - let md5 = require('md5'); - let key = md5(buf); + let key = syzoj.utils.md5(buf); await fs.rename(path, TestData.resolvePath(key)); let file = await TestData.create({ diff --git a/package.json b/package.json index cc165ed..bdbd4bb 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "express-session": "^1.14.1", "file-size": "^1.0.0", "gravatar": "^1.5.2", - "md5": "^2.2.1", "moemark-renderer": "^1.2.0", "moment": "^2.15.0", "multer": "^1.2.0", diff --git a/utility.js b/utility.js index 2e47c24..f176508 100644 --- a/utility.js +++ b/utility.js @@ -220,6 +220,12 @@ module.exports = { removeTitleTag(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() { let request = require('request-promise'); return await request({