path-exists.ts 772 B

12345678910111213141516171819202122232425262728
  1. import { verifyAccessToken } from '~/utils/jwt-utils';
  2. import { MOCK_MENU_LIST } from '~/utils/mock-data';
  3. import { unAuthorizedResponse } from '~/utils/response';
  4. const pathMap: Record<string, any> = { '/': 0 };
  5. function getPaths(menus: any[]) {
  6. menus.forEach((menu) => {
  7. pathMap[menu.path] = String(menu.id);
  8. if (menu.children) {
  9. getPaths(menu.children);
  10. }
  11. });
  12. }
  13. getPaths(MOCK_MENU_LIST);
  14. export default eventHandler(async (event) => {
  15. const userinfo = verifyAccessToken(event);
  16. if (!userinfo) {
  17. return unAuthorizedResponse(event);
  18. }
  19. const { id, path } = getQuery(event);
  20. return (path as string) in pathMap &&
  21. (!id || pathMap[path as string] !== String(id))
  22. ? useResponseSuccess(true)
  23. : useResponseSuccess(false);
  24. });