|
|
@ -2,12 +2,15 @@ import Settings, { SETTINGS_FILE } from './Settings';
|
|
|
|
import Render from './Render';
|
|
|
|
import Render from './Render';
|
|
|
|
import StringUtils from '../../src/com/utils/StringUtils';
|
|
|
|
import StringUtils from '../../src/com/utils/StringUtils';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
import Auth from '../data/Auth';
|
|
|
|
|
|
|
|
import DataEvent from '../../src/com/events/DataEvent';
|
|
|
|
const settings = new Settings();
|
|
|
|
const settings = new Settings();
|
|
|
|
const render = new Render();
|
|
|
|
const render = new Render();
|
|
|
|
const stringUtils = new StringUtils();
|
|
|
|
const stringUtils = new StringUtils();
|
|
|
|
const moment = require('moment');
|
|
|
|
const moment = require('moment');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const AdmZip = require('adm-zip');
|
|
|
|
const AdmZip = require('adm-zip');
|
|
|
|
|
|
|
|
const auth = new Auth();
|
|
|
|
|
|
|
|
|
|
|
|
export default class Utils {
|
|
|
|
export default class Utils {
|
|
|
|
constructor() {}
|
|
|
|
constructor() {}
|
|
|
@ -157,39 +160,87 @@ export default class Utils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
restoreBackup(file) {
|
|
|
|
restoreBackup(file) {
|
|
|
|
//var response;
|
|
|
|
var response;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
var zip = new AdmZip(file.buffer);
|
|
|
|
var zip = new AdmZip(file.buffer);
|
|
|
|
zip.extractEntryTo('settings/settings.json', 'site', false, true);
|
|
|
|
try {
|
|
|
|
zip.extractEntryTo('settings/folks.json', 'site', false, true);
|
|
|
|
zip.extractEntryTo('settings/settings.json', 'site', false, true);
|
|
|
|
zip.extractEntryTo('settings/tags.json', 'site', false, true);
|
|
|
|
zip.extractEntryTo('settings/folks.json', 'site', false, true);
|
|
|
|
zip.getEntries().forEach(function (entry) {
|
|
|
|
zip.extractEntryTo('settings/tags.json', 'site', false, true);
|
|
|
|
var entryName = entry.entryName;
|
|
|
|
zip.getEntries().forEach(function (entry) {
|
|
|
|
var list = entryName.split('/');
|
|
|
|
var entryName = entry.entryName;
|
|
|
|
if (list[0] === 'public') {
|
|
|
|
var list = entryName.split('/');
|
|
|
|
if (list[6]) {
|
|
|
|
if (list[0] === 'public') {
|
|
|
|
zip.extractEntryTo(
|
|
|
|
if (list[6]) {
|
|
|
|
entryName,
|
|
|
|
zip.extractEntryTo(
|
|
|
|
'public/assets/images/blog/' + list[4] + '/' + list[5],
|
|
|
|
entryName,
|
|
|
|
false,
|
|
|
|
'public/assets/images/blog/' + list[4] + '/' + list[5],
|
|
|
|
true
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
true
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (list[0] === 'content') {
|
|
|
|
if (list[0] === 'content') {
|
|
|
|
if (list[4]) {
|
|
|
|
if (list[4]) {
|
|
|
|
zip.extractEntryTo(
|
|
|
|
zip.extractEntryTo(
|
|
|
|
entryName,
|
|
|
|
entryName,
|
|
|
|
'content/pages/' + list[2] + '/' + list[3],
|
|
|
|
'content/pages/' + list[2] + '/' + list[3],
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|