|
|
|
@ -2,12 +2,15 @@ import Settings, { SETTINGS_FILE } from './Settings';
|
|
|
|
|
import Render from './Render';
|
|
|
|
|
import StringUtils from '../../src/com/utils/StringUtils';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import Auth from '../data/Auth';
|
|
|
|
|
import DataEvent from '../../src/com/events/DataEvent';
|
|
|
|
|
const settings = new Settings();
|
|
|
|
|
const render = new Render();
|
|
|
|
|
const stringUtils = new StringUtils();
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const AdmZip = require('adm-zip');
|
|
|
|
|
const auth = new Auth();
|
|
|
|
|
|
|
|
|
|
export default class Utils {
|
|
|
|
|
constructor() {}
|
|
|
|
@ -157,39 +160,87 @@ export default class Utils {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restoreBackup(file) {
|
|
|
|
|
//var response;
|
|
|
|
|
var response;
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
var zip = new AdmZip(file.buffer);
|
|
|
|
|
zip.extractEntryTo('settings/settings.json', 'site', false, true);
|
|
|
|
|
zip.extractEntryTo('settings/folks.json', 'site', false, true);
|
|
|
|
|
zip.extractEntryTo('settings/tags.json', 'site', false, true);
|
|
|
|
|
zip.getEntries().forEach(function (entry) {
|
|
|
|
|
var entryName = entry.entryName;
|
|
|
|
|
var list = entryName.split('/');
|
|
|
|
|
if (list[0] === 'public') {
|
|
|
|
|
if (list[6]) {
|
|
|
|
|
zip.extractEntryTo(
|
|
|
|
|
entryName,
|
|
|
|
|
'public/assets/images/blog/' + list[4] + '/' + list[5],
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
try {
|
|
|
|
|
zip.extractEntryTo('settings/settings.json', 'site', false, true);
|
|
|
|
|
zip.extractEntryTo('settings/folks.json', 'site', false, true);
|
|
|
|
|
zip.extractEntryTo('settings/tags.json', 'site', false, true);
|
|
|
|
|
zip.getEntries().forEach(function (entry) {
|
|
|
|
|
var entryName = entry.entryName;
|
|
|
|
|
var list = entryName.split('/');
|
|
|
|
|
if (list[0] === 'public') {
|
|
|
|
|
if (list[6]) {
|
|
|
|
|
zip.extractEntryTo(
|
|
|
|
|
entryName,
|
|
|
|
|
'public/assets/images/blog/' + list[4] + '/' + list[5],
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (list[0] === 'content') {
|
|
|
|
|
if (list[4]) {
|
|
|
|
|
zip.extractEntryTo(
|
|
|
|
|
entryName,
|
|
|
|
|
'content/pages/' + list[2] + '/' + list[3],
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
if (list[0] === 'content') {
|
|
|
|
|
if (list[4]) {
|
|
|
|
|
zip.extractEntryTo(
|
|
|
|
|
entryName,
|
|
|
|
|
'content/pages/' + list[2] + '/' + list[3],
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
zip.extractEntryTo('content/pages/index.md', 'content/pages', false, true);
|
|
|
|
|
}
|
|
|
|
|
zip.extractEntryTo('content/pages/index.md', 'content/pages', false, true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
|
resolve();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response = {
|
|
|
|
|
type: error,
|
|
|
|
|
message: 'ERROR READING BACKUP'
|
|
|
|
|
};
|
|
|
|
|
reject(response);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
verifyBackup(file, body) {
|
|
|
|
|
var response;
|
|
|
|
|
var zip = new AdmZip(file.buffer);
|
|
|
|
|
var credentials = { handle: body.restore_member_handle, pass: body.restore_member_pass };
|
|
|
|
|
var self = this;
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
try {
|
|
|
|
|
let folks = JSON.parse(zip.readAsText('settings/folks.json'));
|
|
|
|
|
auth.verifyCredentials(folks, credentials)
|
|
|
|
|
.then(r => {
|
|
|
|
|
//resolve(r);
|
|
|
|
|
self.restoreBackup(file)
|
|
|
|
|
.then(() => {
|
|
|
|
|
response = {
|
|
|
|
|
type: '',
|
|
|
|
|
message: 'RESTORE COMPLETE'
|
|
|
|
|
};
|
|
|
|
|
resolve(response);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
response = {
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: 'ERROR RESTORING BACKUP'
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
response = {
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: 'ERROR READING BACKUP FILE'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reject(response);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|