mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-23 17:50:19 +01:00
Use local method for md5
This commit is contained in:
parent
830dc1bc43
commit
cd3bf26dbe
1 changed files with 8 additions and 7 deletions
|
@ -2,6 +2,12 @@ const crypto = require('crypto');
|
||||||
const rethink = require('rethinkdbdash');
|
const rethink = require('rethinkdbdash');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
|
|
||||||
|
const md5 = (str) => {
|
||||||
|
const md5sum = crypto.createHash('md5');
|
||||||
|
md5sum.update(str);
|
||||||
|
return md5sum.digest('hex');
|
||||||
|
};
|
||||||
|
|
||||||
class RethinkDBStore {
|
class RethinkDBStore {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.client = rethink({
|
this.client = rethink({
|
||||||
|
@ -15,7 +21,7 @@ class RethinkDBStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
set(key, data, callback) {
|
set(key, data, callback) {
|
||||||
this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => {
|
this.client.table('uploads').insert({ id: md5(key), data: data }).run((error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
callback(false);
|
callback(false);
|
||||||
winston.error('failed to insert to table', error);
|
winston.error('failed to insert to table', error);
|
||||||
|
@ -26,7 +32,7 @@ class RethinkDBStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
get(key, callback) {
|
get(key, callback) {
|
||||||
this.client.table('uploads').get(RethinkDBStore.md5(key)).run((error, result) => {
|
this.client.table('uploads').get(md5(key)).run((error, result) => {
|
||||||
if (error || !result) {
|
if (error || !result) {
|
||||||
callback(false);
|
callback(false);
|
||||||
winston.error('failed to insert to table', error);
|
winston.error('failed to insert to table', error);
|
||||||
|
@ -38,8 +44,3 @@ class RethinkDBStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RethinkDBStore;
|
module.exports = RethinkDBStore;
|
||||||
module.exports.md5 = (str) => {
|
|
||||||
const md5sum = crypto.createHash('md5');
|
|
||||||
md5sum.update(str);
|
|
||||||
return md5sum.digest('hex');
|
|
||||||
};
|
|
Loading…
Reference in a new issue