Skip to content

Node.js based forum software built for the modern web

fix: #9950, rename account export routes to remove `uid/` prefix

Julian Lam0ee85d5a0b68
diff --git a/public/openapi/read.yaml b/public/openapi/read.yaml
index 857621dd86..2adc245b18 100644
--- a/public/openapi/read.yaml
+++ b/public/openapi/read.yaml
@@ -180,12 +180,14 @@ paths:
$ref: 'read/user/username/username.yaml'
"/api/user/email/{email}":
$ref: 'read/user/email/email.yaml'
- "/api/user/uid/{userslug}/export/posts":
- $ref: 'read/user/uid/userslug/export/posts.yaml'
- "/api/user/uid/{userslug}/export/uploads":
- $ref: 'read/user/uid/userslug/export/uploads.yaml'
- "/api/user/uid/{userslug}/export/profile":
- $ref: 'read/user/uid/userslug/export/profile.yaml'
+ "/api/user/{userslug}/export/posts":
+ $ref: 'read/user/userslug/export/posts.yaml'
+ "/api/user/{userslug}/export/uploads":
+ $ref: 'read/user/userslug/export/uploads.yaml'
+ "/api/user/{userslug}/export/profile":
+ $ref: 'read/user/userslug/export/profile.yaml'
+ "/api/user/uid/{userslug}/export/{type}":
+ $ref: 'read/user/uid/userslug/export/type.yaml'
/api/categories:
$ref: 'read/categories.yaml'
"/api/categories/{cid}/moderators":
diff --git a/public/openapi/read/user/uid/userslug/export/type.yaml b/public/openapi/read/user/uid/userslug/export/type.yaml
new file mode 100644
index 0000000000..f859087247
--- /dev/null
+++ b/public/openapi/read/user/uid/userslug/export/type.yaml
@@ -0,0 +1,19 @@
+get:
+ tags:
+ - deprecated
+ summary: Export a user's posts (.csv)
+ parameters:
+ - name: userslug
+ in: path
+ required: true
+ schema:
+ type: string
+ example: admin
+ responses:
+ "200":
+ description: "A CSV file containing a user's posts"
+ content:
+ text/csv:
+ schema:
+ type: string
+ format: binary
\ No newline at end of file
diff --git a/public/openapi/read/user/uid/userslug/export/posts.yaml b/public/openapi/read/user/userslug/export/posts.yaml
similarity index 100%
rename from public/openapi/read/user/uid/userslug/export/posts.yaml
rename to public/openapi/read/user/userslug/export/posts.yaml
diff --git a/public/openapi/read/user/uid/userslug/export/profile.yaml b/public/openapi/read/user/userslug/export/profile.yaml
similarity index 100%
rename from public/openapi/read/user/uid/userslug/export/profile.yaml
rename to public/openapi/read/user/userslug/export/profile.yaml
diff --git a/public/openapi/read/user/uid/userslug/export/uploads.yaml b/public/openapi/read/user/userslug/export/uploads.yaml
similarity index 100%
rename from public/openapi/read/user/uid/userslug/export/uploads.yaml
rename to public/openapi/read/user/userslug/export/uploads.yaml
diff --git a/src/routes/api.js b/src/routes/api.js
index fa76030013..31871d1fc8 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -1,6 +1,7 @@
'use strict';
const express = require('express');
+const winston = require('winston');
const uploadsController = require('../controllers/uploads');
const helpers = require('./helpers');
@@ -17,9 +18,15 @@ module.exports = function (app, middleware, controllers) {
router.get('/user/username/:username', [...middlewares, middleware.canViewUsers], helpers.tryRoute(controllers.user.getUserByUsername));
router.get('/user/email/:email', [...middlewares, middleware.canViewUsers], helpers.tryRoute(controllers.user.getUserByEmail));
- router.get('/user/uid/:userslug/export/posts', [...middlewares, middleware.authenticateRequest, middleware.ensureLoggedIn, middleware.checkAccountPermissions, middleware.exposeUid], helpers.tryRoute(controllers.user.exportPosts));
- router.get('/user/uid/:userslug/export/uploads', [...middlewares, middleware.authenticateRequest, middleware.ensureLoggedIn, middleware.checkAccountPermissions, middleware.exposeUid], helpers.tryRoute(controllers.user.exportUploads));
- router.get('/user/uid/:userslug/export/profile', [...middlewares, middleware.authenticateRequest, middleware.ensureLoggedIn, middleware.checkAccountPermissions, middleware.exposeUid], helpers.tryRoute(controllers.user.exportProfile));
+ router.get('/user/:userslug/export/posts', [...middlewares, middleware.authenticateRequest, middleware.ensureLoggedIn, middleware.checkAccountPermissions, middleware.exposeUid], helpers.tryRoute(controllers.user.exportPosts));
+ router.get('/user/:userslug/export/uploads', [...middlewares, middleware.authenticateRequest, middleware.ensureLoggedIn, middleware.checkAccountPermissions, middleware.exposeUid], helpers.tryRoute(controllers.user.exportUploads));
+ router.get('/user/:userslug/export/profile', [...middlewares, middleware.authenticateRequest, middleware.ensureLoggedIn, middleware.checkAccountPermissions, middleware.exposeUid], helpers.tryRoute(controllers.user.exportProfile));
+
+ // Deprecated, remove in v1.20.0
+ router.get('/user/uid/:userslug/export/:type', (req, res) => {
+ winston.warn(`[router] \`/api/user/uid/${req.params.userslug}/export/${req.params.type}\` is deprecated, call it \`/api/user/${req.params.userslug}/export/${req.params.type}\`instead.`);
+ res.redirect(`/api/user/${req.params.userslug}/export/${req.params.type}`);
+ });
router.get('/categories/:cid/moderators', [...middlewares], helpers.tryRoute(controllers.api.getModerators));
router.get('/recent/posts/:term?', [...middlewares], helpers.tryRoute(controllers.posts.getRecentPosts));
diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js
index 2de4160ba5..0bce7240ff 100644
--- a/src/socket.io/user/profile.js
+++ b/src/socket.io/user/profile.js
@@ -140,7 +140,7 @@ module.exports = function (SocketUser) {
const userData = await user.getUserFields(data.uid, ['username', 'userslug']);
const n = await notifications.create({
bodyShort: `[[notifications:${type}-exported, ${userData.username}]]`,
- path: `/api/user/uid/${userData.userslug}/export/${type}`,
+ path: `/api/user/${userData.userslug}/export/${type}`,
nid: `${type}:export:${data.uid}`,
from: data.uid,
});