Skip to content

Node.js based forum software built for the modern web

Merge branch 'master' into develop

Julian Lam596db09f7eeb
diff --cc src/api/users.js
index 249eaae83c,bbb02a43bb..9b37d84c2f
--- a/src/api/users.js
+++ b/src/api/users.js
@@@ -645,38 -442,11 +645,42 @@@ usersAPI.changePicture = async (caller
}, ['picture', 'icon:bgColor']);
};
+const exportMetadata = new Map([
+ ['posts', ['csv', 'text/csv']],
+ ['uploads', ['zip', 'application/zip']],
+ ['profile', ['json', 'application/json']],
+]);
+
+const prepareExport = async ({ uid, type }) => {
+ const [extension] = exportMetadata.get(type);
+ const filename = `${uid}_${type}.${extension}`;
+ try {
+ const stat = await fs.stat(path.join(__dirname, '../../build/export', filename));
+ return stat;
+ } catch (e) {
+ return false;
+ }
+};
+
+usersAPI.checkExportByType = async (caller, { uid, type }) => await prepareExport({ uid, type });
+
+usersAPI.getExportByType = async (caller, { uid, type }) => {
+ const [extension, mime] = exportMetadata.get(type);
+ const filename = `${uid}_${type}.${extension}`;
+
+ const exists = await prepareExport({ uid, type });
+ if (exists) {
+ return { filename, mime };
+ }
+
+ return false;
+};
+
usersAPI.generateExport = async (caller, { uid, type }) => {
+ const validTypes = ['profile', 'posts', 'uploads'];
+ if (!validTypes.includes(type)) {
+ throw new Error('[[error:invalid-data]]');
+ }
const count = await db.incrObjectField('locks', `export:${uid}${type}`);
if (count > 1) {
throw new Error('[[error:already-exporting]]');
diff --cc src/topics/tags.js
index 14ddb60a67,314b5cfd84..110a8585d8
--- a/src/topics/tags.js
+++ b/src/topics/tags.js
@@@ -283,11 -283,11 +283,11 @@@ module.exports = function (Topics)
const payload = await plugins.hooks.fire('filter:tags.getAll', {
tags: tags,
});
- return await Topics.getTagData(payload.tags);
+ return Topics.getTagData(payload.tags);
}
- Topics.getTagData = async function (tags) {
+ Topics.getTagData = function (tags) {
- if (!tags.length) {
+ if (!tags || !tags.length) {
return [];
}
tags.forEach((tag) => {