mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
fix: #9055, non-standard API response from addThumbs route
Also removed old thumb upload router handler, and updated uploadPost handling in composer to match new response schema
This commit is contained in:
@@ -5,55 +5,21 @@ post:
|
||||
description: Provided by NodeBB core and used mainly by the composer, this route allows you to upload an image or file to a post.
|
||||
responses:
|
||||
"200":
|
||||
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: object
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
error:
|
||||
type: string
|
||||
status:
|
||||
$ref: ../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
type: object
|
||||
properties:
|
||||
images:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
url:
|
||||
type: string
|
||||
@@ -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/2445
|
||||
if (!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);
|
||||
}
|
||||
|
||||
@@ -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 zset
|
||||
if (files && files.length) {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user