Node.js based forum software built for the modern web
fix: #9055, non-standard API response from addThumbs route
Julian Lam340387c18a27
diff --git a/public/openapi/read/post/upload.yaml b/public/openapi/read/post/upload.yamlindex 877160d6ad..5ffdc7afbb 100644--- a/public/openapi/read/post/upload.yaml+++ b/public/openapi/read/post/upload.yaml@@ -8,52 +8,18 @@ post:description: ""content:application/json:- schema:- type: array- items:- type: object- properties:- name:- type: string- url:- type: string- text/plain:- schema:- type: array- items:- type: object- properties:- name:- type: string- url:- type: string- "403":- description: ""- content:- application/json:- schema:- type: string- example: Forbidden- text/plain:- schema:- type: string- example: Forbidden- "500":- description: ""- content:- application/json:- schema:- type: object- properties:- path:- type: string- error:- type: string- text/plain:schema:type: objectproperties:- path:- type: string- error:- type: string\ No newline at end of file+ status:+ $ref: ../components/schemas/Status.yaml#/Status+ response:+ type: object+ properties:+ images:+ type: array+ items:+ type: object+ properties:+ url:+ type: string\ No newline at end of filediff --git a/src/controllers/uploads.js b/src/controllers/uploads.jsindex e4dd6f73e3..be1ff5529e 100644--- a/src/controllers/uploads.js+++ b/src/controllers/uploads.js@@ -11,6 +11,8 @@ const plugins = require('../plugins');const image = require('../image');const privileges = require('../privileges');+const helpers = require('./helpers');+const uploadsController = module.exports;uploadsController.upload = async function (req, res, filesIterator) {@@ -18,7 +20,7 @@ uploadsController.upload = async function (req, res, filesIterator) {// These checks added because of odd behaviour by request: https://github.com/request/request/issues/2445if (!Array.isArray(files)) {- return res.status(500).json('invalid files');+ return helpers.formatApiResponse(500, res, new Error('[[error:invalid-file]]'));}if (Array.isArray(files[0])) {files = files[0];@@ -30,10 +32,10 @@ uploadsController.upload = async function (req, res, filesIterator) {/* eslint-disable no-await-in-loop */images.push(await filesIterator(fileObj));}- res.status(200).json(images);+ helpers.formatApiResponse(200, res, { images });return images;} catch (err) {- res.status(500).json({ path: req.path, error: err.message });+ return helpers.formatApiResponse(500, res, err);} finally {deleteTempFiles(files);}diff --git a/src/controllers/write/topics.js b/src/controllers/write/topics.jsindex 7c08574699..53cfbcc037 100644--- a/src/controllers/write/topics.js+++ b/src/controllers/write/topics.js@@ -100,7 +100,7 @@ Topics.addThumb = async (req, res, next) => {return;}- const files = await uploadsController.uploadThumb(req, res, next); // response is handled here, fix this?+ const files = await uploadsController.uploadThumb(req, res, next); // response is handled here// Add uploaded files to topic zsetif (files && files.length) {diff --git a/src/routes/api.js b/src/routes/api.jsindex ba6e9b31e3..3280246626 100644--- a/src/routes/api.js+++ b/src/routes/api.js@@ -33,7 +33,6 @@ module.exports = function (app, middleware, controllers) {var multipartMiddleware = multipart();var middlewares = [middleware.maintenanceMode, multipartMiddleware, middleware.validateFiles, middleware.applyCSRF];router.post('/post/upload', middlewares, uploadsController.uploadPost);- router.post('/topic/thumb/upload', middlewares, uploadsController.uploadThumb);router.post('/user/:userslug/uploadpicture', middlewares.concat([middleware.exposeUid, middleware.authenticate, middleware.canViewUsers, middleware.checkAccountPermissions]), controllers.accounts.edit.uploadPicture);};