|
|
@@ -20,43 +20,6 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
- * /content-disposition-settings:
|
|
|
- * get:
|
|
|
- * tags: [Content-Disposition Settings]
|
|
|
- * summary: Get content disposition settings for configurable MIME types
|
|
|
- * security:
|
|
|
- * - cookieAuth: []
|
|
|
- * responses:
|
|
|
- * 200:
|
|
|
- * description: Successfully retrieved content disposition settings.
|
|
|
- * content:
|
|
|
- * application/json:
|
|
|
- * schema:
|
|
|
- * type: object
|
|
|
- * properties:
|
|
|
- * contentDispositionSettings:
|
|
|
- * type: object
|
|
|
- * additionalProperties:
|
|
|
- * type: string
|
|
|
- * description: inline or attachment
|
|
|
- *
|
|
|
- */
|
|
|
- router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => {
|
|
|
- try {
|
|
|
- const currentDispositionSettings = configManager.getConfig('attachments:contentDisposition:mimeTypeOverrides');
|
|
|
- const contentDispositionSettings: Record<string, 'inline' | 'attachment'> = currentDispositionSettings;
|
|
|
-
|
|
|
- return res.apiv3({ contentDispositionSettings });
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- logger.error('Error retrieving content disposition settings:', err);
|
|
|
- return res.apiv3Err(new ErrorV3('Failed to retrieve content disposition settings', 'get-content-disposition-failed'));
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- /**
|
|
|
- * @swagger
|
|
|
- *
|
|
|
* /content-disposition-settings/strict:
|
|
|
* put:
|
|
|
* tags: [Content-Disposition Settings]
|
|
|
@@ -79,14 +42,24 @@ module.exports = (crowi) => {
|
|
|
*
|
|
|
*/
|
|
|
router.put(
|
|
|
- '/strict',
|
|
|
+ '/update',
|
|
|
loginRequiredStrictly,
|
|
|
adminRequired,
|
|
|
addActivity,
|
|
|
async(req, res) => {
|
|
|
|
|
|
try {
|
|
|
- await configManager.updateConfigs({ 'attachments:contentDisposition:mimeTypeOverrides': strictMimeTypeSettings });
|
|
|
+ const { newInlineMimeTypes } = req.body;
|
|
|
+
|
|
|
+ const currentSettings = await configManager.getConfig('attachments:contentDisposition:mimeTypeOverrides');
|
|
|
+ const currentInlineMimeTypes = currentSettings.inlineMimeTypes || [];
|
|
|
+
|
|
|
+ const updatedInlineMimeTypes = Array.from(new Set([
|
|
|
+ ...currentInlineMimeTypes,
|
|
|
+ ...newInlineMimeTypes,
|
|
|
+ ]));
|
|
|
+
|
|
|
+ await configManager.updateConfigs({ 'attachments:contentDisposition:mimeTypeOverrides': { inlineMimeTypes: updatedInlineMimeTypes } });
|
|
|
|
|
|
const parameters = {
|
|
|
action: SupportedAction.ACTION_ADMIN_ATTACHMENT_DISPOSITION_UPDATE,
|
|
|
@@ -95,7 +68,7 @@ module.exports = (crowi) => {
|
|
|
};
|
|
|
activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
|
|
|
- return res.apiv3({ currentMode: 'strict', contentDispositionSettings: strictMimeTypeSettings });
|
|
|
+ return res.apiv3({ currentMode: 'custom', contentDispositionSettings: strictMimeTypeSettings });
|
|
|
}
|
|
|
catch (err) {
|
|
|
const msg = 'Error occurred in updating content disposition for MIME types';
|
|
|
@@ -110,15 +83,15 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
- * /content-disposition-settings/lax:
|
|
|
- * put:
|
|
|
+ * /content-disposition-settings:
|
|
|
+ * get:
|
|
|
* tags: [Content-Disposition Settings]
|
|
|
- * summary: Set content disposition settings for configurable MIME types to lax.
|
|
|
+ * summary: Get content disposition settings for configurable MIME types
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* responses:
|
|
|
* 200:
|
|
|
- * description: Successfully set lax content disposition settings.
|
|
|
+ * description: Successfully retrieved content disposition settings.
|
|
|
* content:
|
|
|
* application/json:
|
|
|
* schema:
|
|
|
@@ -131,34 +104,18 @@ module.exports = (crowi) => {
|
|
|
* description: inline or attachment
|
|
|
*
|
|
|
*/
|
|
|
- router.put(
|
|
|
- '/lax',
|
|
|
- loginRequiredStrictly,
|
|
|
- adminRequired,
|
|
|
- addActivity,
|
|
|
- async(req, res) => {
|
|
|
-
|
|
|
- try {
|
|
|
- await configManager.updateConfigs({ 'attachments:contentDisposition:mimeTypeOverrides': laxMimeTypeSettings });
|
|
|
-
|
|
|
- const parameters = {
|
|
|
- action: SupportedAction.ACTION_ADMIN_ATTACHMENT_DISPOSITION_UPDATE,
|
|
|
- contentDispositionSettings: laxMimeTypeSettings,
|
|
|
- currentMode: 'lax',
|
|
|
- };
|
|
|
- activityEvent.emit('update', res.locals.activity._id, parameters);
|
|
|
+ router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => {
|
|
|
+ try {
|
|
|
+ const currentDispositionSettings = configManager.getConfig('attachments:contentDisposition:mimeTypeOverrides');
|
|
|
+ const contentDispositionSettings: Record<string, 'inline' | 'attachment'> = currentDispositionSettings;
|
|
|
|
|
|
- return res.apiv3({ currentMode: 'lax', contentDispositionSettings: laxMimeTypeSettings });
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- const msg = 'Error occurred in updating content disposition for MIME types';
|
|
|
- logger.error(msg, err);
|
|
|
- return res.apiv3Err(
|
|
|
- new ErrorV3(msg, 'update-content-disposition-failed'),
|
|
|
- );
|
|
|
- }
|
|
|
- },
|
|
|
- );
|
|
|
+ return res.apiv3({ contentDispositionSettings });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Error retrieving content disposition settings:', err);
|
|
|
+ return res.apiv3Err(new ErrorV3('Failed to retrieve content disposition settings', 'get-content-disposition-failed'));
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
return router;
|
|
|
};
|