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.
|
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:
|
responses:
|
||||||
"200":
|
"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: ""
|
description: ""
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
path:
|
status:
|
||||||
type: string
|
$ref: ../components/schemas/Status.yaml#/Status
|
||||||
error:
|
response:
|
||||||
type: string
|
type: object
|
||||||
text/plain:
|
properties:
|
||||||
schema:
|
images:
|
||||||
type: object
|
type: array
|
||||||
properties:
|
items:
|
||||||
path:
|
type: object
|
||||||
type: string
|
properties:
|
||||||
error:
|
url:
|
||||||
type: string
|
type: string
|
||||||
@@ -11,6 +11,8 @@ const plugins = require('../plugins');
|
|||||||
const image = require('../image');
|
const image = require('../image');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
|
|
||||||
|
const helpers = require('./helpers');
|
||||||
|
|
||||||
const uploadsController = module.exports;
|
const uploadsController = module.exports;
|
||||||
|
|
||||||
uploadsController.upload = async function (req, res, filesIterator) {
|
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
|
// These checks added because of odd behaviour by request: https://github.com/request/request/issues/2445
|
||||||
if (!Array.isArray(files)) {
|
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])) {
|
if (Array.isArray(files[0])) {
|
||||||
files = files[0];
|
files = files[0];
|
||||||
@@ -30,10 +32,10 @@ uploadsController.upload = async function (req, res, filesIterator) {
|
|||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
images.push(await filesIterator(fileObj));
|
images.push(await filesIterator(fileObj));
|
||||||
}
|
}
|
||||||
res.status(200).json(images);
|
helpers.formatApiResponse(200, res, { images });
|
||||||
return images;
|
return images;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(500).json({ path: req.path, error: err.message });
|
return helpers.formatApiResponse(500, res, err);
|
||||||
} finally {
|
} finally {
|
||||||
deleteTempFiles(files);
|
deleteTempFiles(files);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ Topics.addThumb = async (req, res, next) => {
|
|||||||
return;
|
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
|
// Add uploaded files to topic zset
|
||||||
if (files && files.length) {
|
if (files && files.length) {
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ module.exports = function (app, middleware, controllers) {
|
|||||||
var multipartMiddleware = multipart();
|
var multipartMiddleware = multipart();
|
||||||
var middlewares = [middleware.maintenanceMode, multipartMiddleware, middleware.validateFiles, middleware.applyCSRF];
|
var middlewares = [middleware.maintenanceMode, multipartMiddleware, middleware.validateFiles, middleware.applyCSRF];
|
||||||
router.post('/post/upload', middlewares, uploadsController.uploadPost);
|
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);
|
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