2021-01-21 21:06:52 +00:00
|
|
|
'use strict';
|
2014-12-29 21:13:49 +01:00
|
|
|
/**
|
2014-12-30 00:12:26 +01:00
|
|
|
* 2014 John McLear (Etherpad Foundation / McLear Ltd)
|
2014-12-29 21:13:49 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-11-23 13:24:19 -05:00
|
|
|
const db = require('../db/DB');
|
2021-01-21 21:06:52 +00:00
|
|
|
const hooks = require('../../static/js/pluginfw/hooks');
|
2014-12-29 21:13:49 +01:00
|
|
|
|
2021-06-29 19:13:10 +02:00
|
|
|
exports.getPadRaw = async (padId, readOnlyId) => {
|
|
|
|
const keyPrefixRead = `pad:${padId}`;
|
|
|
|
const keyPrefixWrite = readOnlyId ? `pad:${readOnlyId}` : keyPrefixRead;
|
2022-04-13 04:21:15 -04:00
|
|
|
const data = {[keyPrefixWrite]: await db.get(keyPrefixRead)};
|
|
|
|
for (const [k, v] of Object.values(data[keyPrefixWrite].pool.numToAttrib)) {
|
|
|
|
if (k !== 'author') continue;
|
|
|
|
const authorEntry = await db.get(`globalAuthor:${v}`);
|
|
|
|
if (!authorEntry) continue;
|
|
|
|
data[`globalAuthor:${v}`] = authorEntry;
|
|
|
|
if (!authorEntry.padIDs) continue;
|
|
|
|
authorEntry.padIDs = readOnlyId || padId;
|
|
|
|
}
|
|
|
|
const keySuffixes = [];
|
|
|
|
for (let i = 0; i <= data[keyPrefixWrite].head; i++) keySuffixes.push(`:revs:${i}`);
|
|
|
|
for (let i = 0; i <= data[keyPrefixWrite].chatHead; i++) keySuffixes.push(`:chat:${i}`);
|
2021-06-29 19:13:10 +02:00
|
|
|
for (const keySuffix of keySuffixes) {
|
2022-04-13 04:21:15 -04:00
|
|
|
data[keyPrefixWrite + keySuffix] = await db.get(keyPrefixRead + keySuffix);
|
2014-12-29 22:51:31 +01:00
|
|
|
}
|
2019-01-31 08:55:36 +00:00
|
|
|
|
2020-11-10 01:20:05 -05:00
|
|
|
// get content that has a different prefix IE comments:padId:foo
|
|
|
|
// a plugin would return something likle ['comments', 'cakes']
|
|
|
|
const prefixes = await hooks.aCallAll('exportEtherpadAdditionalContent');
|
|
|
|
await Promise.all(prefixes.map(async (prefix) => {
|
|
|
|
const key = `${prefix}:${padId}`;
|
2021-06-29 19:13:10 +02:00
|
|
|
const writeKey = readOnlyId ? `${prefix}:${readOnlyId}` : key;
|
|
|
|
data[writeKey] = await db.get(key);
|
2020-11-10 01:20:05 -05:00
|
|
|
}));
|
2020-11-06 13:48:25 +00:00
|
|
|
|
2019-01-31 08:55:36 +00:00
|
|
|
return data;
|
2020-11-23 13:24:19 -05:00
|
|
|
};
|