Просмотр исходного кода

Add API call for setting lax disposition settings

arvid-e 7 месяцев назад
Родитель
Сommit
4636b486fc
1 измененных файлов с 41 добавлено и 0 удалено
  1. 41 0
      apps/app/src/server/routes/apiv3/content-disposition-settings.ts

+ 41 - 0
apps/app/src/server/routes/apiv3/content-disposition-settings.ts

@@ -207,5 +207,46 @@ module.exports = (crowi) => {
     },
   );
 
+  router.put(
+    '/lax',
+    loginRequiredStrictly,
+    adminRequired,
+    addActivity,
+    apiV3FormValidator,
+
+    async(req, res) => {
+
+      try {
+        const strictMimeTypeSettings: Record<string, 'inline' | 'attachment'> = {
+          'application/pdf': 'inline',
+          'application/json': 'inline',
+          'text/csv': 'inline',
+          'font/woff2': 'inline',
+          'font/woff': 'inline',
+          'font/ttf': 'inline',
+          'font/otf': 'inline',
+        };
+
+        await configManager.updateConfigs({ 'attachments:contentDisposition:mimeTypeOverrides': strictMimeTypeSettings });
+
+        const parameters = {
+          action: SupportedAction.ACTION_ADMIN_ATTACHMENT_DISPOSITION_UPDATE,
+          contentDispositionSettings: strictMimeTypeSettings,
+          currentMode: 'lax',
+        };
+        activityEvent.emit('update', res.locals.activity._id, parameters);
+
+        return res.apiv3({ currentMode: 'lax', contentDispositionSettings: strictMimeTypeSettings });
+      }
+      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 router;
 };