@reglow/reglow 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/reglow/common/errors.d.ts +92 -0
- package/dist/reglow/common/errors.js +127 -0
- package/dist/reglow/common/errors.js.map +1 -0
- package/dist/reglow/common/exception_handler.d.ts +14 -0
- package/dist/reglow/common/exception_handler.js +135 -0
- package/dist/reglow/common/exception_handler.js.map +1 -0
- package/dist/reglow/common/i18n.d.ts +15 -0
- package/dist/reglow/common/i18n.js +61 -0
- package/dist/reglow/common/i18n.js.map +1 -0
- package/dist/reglow/common/middleware.d.ts +5 -0
- package/dist/reglow/common/middleware.js +131 -0
- package/dist/reglow/common/middleware.js.map +1 -0
- package/dist/reglow/common/response.d.ts +28 -0
- package/dist/reglow/common/response.js +42 -0
- package/dist/reglow/common/response.js.map +1 -0
- package/dist/reglow/common/serialize.d.ts +6 -0
- package/dist/reglow/common/serialize.js +39 -0
- package/dist/reglow/common/serialize.js.map +1 -0
- package/dist/reglow/common/utils/date_utils.d.ts +10 -0
- package/dist/reglow/common/utils/date_utils.js +30 -0
- package/dist/reglow/common/utils/date_utils.js.map +1 -0
- package/dist/reglow/common/utils/parse-user-agent.d.ts +11 -0
- package/dist/reglow/common/utils/parse-user-agent.js +80 -0
- package/dist/reglow/common/utils/parse-user-agent.js.map +1 -0
- package/dist/reglow/common/utils/string_utils.d.ts +14 -0
- package/dist/reglow/common/utils/string_utils.js +31 -0
- package/dist/reglow/common/utils/string_utils.js.map +1 -0
- package/dist/reglow/core/auth.d.ts +15 -0
- package/dist/reglow/core/auth.js +184 -0
- package/dist/reglow/core/auth.js.map +1 -0
- package/dist/reglow/core/cache.d.ts +6 -0
- package/dist/reglow/core/cache.js +15 -0
- package/dist/reglow/core/cache.js.map +1 -0
- package/dist/reglow/core/config.d.ts +45 -0
- package/dist/reglow/core/config.js +83 -0
- package/dist/reglow/core/config.js.map +1 -0
- package/dist/reglow/core/data_scope.d.ts +21 -0
- package/dist/reglow/core/data_scope.js +20 -0
- package/dist/reglow/core/data_scope.js.map +1 -0
- package/dist/reglow/core/database.d.ts +4 -0
- package/dist/reglow/core/database.js +43 -0
- package/dist/reglow/core/database.js.map +1 -0
- package/dist/reglow/core/email.d.ts +12 -0
- package/dist/reglow/core/email.js +277 -0
- package/dist/reglow/core/email.js.map +1 -0
- package/dist/reglow/core/entities.d.ts +462 -0
- package/dist/reglow/core/entities.js +6 -0
- package/dist/reglow/core/entities.js.map +1 -0
- package/dist/reglow/core/fastify.d.ts +21 -0
- package/dist/reglow/core/fastify.js +2 -0
- package/dist/reglow/core/fastify.js.map +1 -0
- package/dist/reglow/core/logging.d.ts +8 -0
- package/dist/reglow/core/logging.js +32 -0
- package/dist/reglow/core/logging.js.map +1 -0
- package/dist/reglow/core/models.d.ts +98 -0
- package/dist/reglow/core/models.js +57 -0
- package/dist/reglow/core/models.js.map +1 -0
- package/dist/reglow/core/observability.d.ts +17 -0
- package/dist/reglow/core/observability.js +92 -0
- package/dist/reglow/core/observability.js.map +1 -0
- package/dist/reglow/core/payment.d.ts +107 -0
- package/dist/reglow/core/payment.js +1177 -0
- package/dist/reglow/core/payment.js.map +1 -0
- package/dist/reglow/core/plugin.d.ts +19 -0
- package/dist/reglow/core/plugin.js +85 -0
- package/dist/reglow/core/plugin.js.map +1 -0
- package/dist/reglow/core/rate_limit.d.ts +2 -0
- package/dist/reglow/core/rate_limit.js +28 -0
- package/dist/reglow/core/rate_limit.js.map +1 -0
- package/dist/reglow/core/redis.d.ts +30 -0
- package/dist/reglow/core/redis.js +278 -0
- package/dist/reglow/core/redis.js.map +1 -0
- package/dist/reglow/core/redis_keys.d.ts +22 -0
- package/dist/reglow/core/redis_keys.js +59 -0
- package/dist/reglow/core/redis_keys.js.map +1 -0
- package/dist/reglow/core/security.d.ts +25 -0
- package/dist/reglow/core/security.js +64 -0
- package/dist/reglow/core/security.js.map +1 -0
- package/dist/reglow/core/session.d.ts +17 -0
- package/dist/reglow/core/session.js +194 -0
- package/dist/reglow/core/session.js.map +1 -0
- package/dist/reglow/core/sms.d.ts +19 -0
- package/dist/reglow/core/sms.js +33 -0
- package/dist/reglow/core/sms.js.map +1 -0
- package/dist/reglow/core/storage.d.ts +45 -0
- package/dist/reglow/core/storage.js +249 -0
- package/dist/reglow/core/storage.js.map +1 -0
- package/dist/reglow/modules/agreement/controller.d.ts +7 -0
- package/dist/reglow/modules/agreement/controller.js +242 -0
- package/dist/reglow/modules/agreement/controller.js.map +1 -0
- package/dist/reglow/modules/agreement/repository.d.ts +30 -0
- package/dist/reglow/modules/agreement/repository.js +160 -0
- package/dist/reglow/modules/agreement/repository.js.map +1 -0
- package/dist/reglow/modules/agreement/router.d.ts +13 -0
- package/dist/reglow/modules/agreement/router.js +10 -0
- package/dist/reglow/modules/agreement/router.js.map +1 -0
- package/dist/reglow/modules/agreement/schema.d.ts +30 -0
- package/dist/reglow/modules/agreement/schema.js +27 -0
- package/dist/reglow/modules/agreement/schema.js.map +1 -0
- package/dist/reglow/modules/agreement/service.d.ts +42 -0
- package/dist/reglow/modules/agreement/service.js +349 -0
- package/dist/reglow/modules/agreement/service.js.map +1 -0
- package/dist/reglow/modules/ai/controller.d.ts +25 -0
- package/dist/reglow/modules/ai/controller.js +1143 -0
- package/dist/reglow/modules/ai/controller.js.map +1 -0
- package/dist/reglow/modules/ai/router.d.ts +9 -0
- package/dist/reglow/modules/ai/router.js +7 -0
- package/dist/reglow/modules/ai/router.js.map +1 -0
- package/dist/reglow/modules/ai/schema.d.ts +48 -0
- package/dist/reglow/modules/ai/schema.js +40 -0
- package/dist/reglow/modules/ai/schema.js.map +1 -0
- package/dist/reglow/modules/ai/service.d.ts +8 -0
- package/dist/reglow/modules/ai/service.js +137 -0
- package/dist/reglow/modules/ai/service.js.map +1 -0
- package/dist/reglow/modules/article/controller.d.ts +6 -0
- package/dist/reglow/modules/article/controller.js +204 -0
- package/dist/reglow/modules/article/controller.js.map +1 -0
- package/dist/reglow/modules/article/repository.d.ts +37 -0
- package/dist/reglow/modules/article/repository.js +184 -0
- package/dist/reglow/modules/article/repository.js.map +1 -0
- package/dist/reglow/modules/article/router.d.ts +10 -0
- package/dist/reglow/modules/article/router.js +8 -0
- package/dist/reglow/modules/article/router.js.map +1 -0
- package/dist/reglow/modules/article/schema.d.ts +66 -0
- package/dist/reglow/modules/article/schema.js +66 -0
- package/dist/reglow/modules/article/schema.js.map +1 -0
- package/dist/reglow/modules/article/service.d.ts +81 -0
- package/dist/reglow/modules/article/service.js +254 -0
- package/dist/reglow/modules/article/service.js.map +1 -0
- package/dist/reglow/modules/auth/controller.d.ts +6 -0
- package/dist/reglow/modules/auth/controller.js +127 -0
- package/dist/reglow/modules/auth/controller.js.map +1 -0
- package/dist/reglow/modules/auth/router.d.ts +9 -0
- package/dist/reglow/modules/auth/router.js +7 -0
- package/dist/reglow/modules/auth/router.js.map +1 -0
- package/dist/reglow/modules/auth/schema.d.ts +59 -0
- package/dist/reglow/modules/auth/schema.js +56 -0
- package/dist/reglow/modules/auth/schema.js.map +1 -0
- package/dist/reglow/modules/auth/service.d.ts +69 -0
- package/dist/reglow/modules/auth/service.js +492 -0
- package/dist/reglow/modules/auth/service.js.map +1 -0
- package/dist/reglow/modules/config/controller.d.ts +7 -0
- package/dist/reglow/modules/config/controller.js +297 -0
- package/dist/reglow/modules/config/controller.js.map +1 -0
- package/dist/reglow/modules/config/repository.d.ts +17 -0
- package/dist/reglow/modules/config/repository.js +88 -0
- package/dist/reglow/modules/config/repository.js.map +1 -0
- package/dist/reglow/modules/config/router.d.ts +13 -0
- package/dist/reglow/modules/config/router.js +8 -0
- package/dist/reglow/modules/config/router.js.map +1 -0
- package/dist/reglow/modules/config/schema.d.ts +37 -0
- package/dist/reglow/modules/config/schema.js +25 -0
- package/dist/reglow/modules/config/schema.js.map +1 -0
- package/dist/reglow/modules/customer_service/controller.d.ts +3 -0
- package/dist/reglow/modules/customer_service/controller.js +443 -0
- package/dist/reglow/modules/customer_service/controller.js.map +1 -0
- package/dist/reglow/modules/customer_service/document_parser.d.ts +5 -0
- package/dist/reglow/modules/customer_service/document_parser.js +84 -0
- package/dist/reglow/modules/customer_service/document_parser.js.map +1 -0
- package/dist/reglow/modules/customer_service/repository.d.ts +72 -0
- package/dist/reglow/modules/customer_service/repository.js +376 -0
- package/dist/reglow/modules/customer_service/repository.js.map +1 -0
- package/dist/reglow/modules/customer_service/router.d.ts +14 -0
- package/dist/reglow/modules/customer_service/router.js +9 -0
- package/dist/reglow/modules/customer_service/router.js.map +1 -0
- package/dist/reglow/modules/customer_service/schema.d.ts +97 -0
- package/dist/reglow/modules/customer_service/schema.js +91 -0
- package/dist/reglow/modules/customer_service/schema.js.map +1 -0
- package/dist/reglow/modules/customer_service/sdk_template.html +666 -0
- package/dist/reglow/modules/customer_service/service.d.ts +92 -0
- package/dist/reglow/modules/customer_service/service.js +1642 -0
- package/dist/reglow/modules/customer_service/service.js.map +1 -0
- package/dist/reglow/modules/customer_service/ws.d.ts +29 -0
- package/dist/reglow/modules/customer_service/ws.js +182 -0
- package/dist/reglow/modules/customer_service/ws.js.map +1 -0
- package/dist/reglow/modules/dept/controller.d.ts +6 -0
- package/dist/reglow/modules/dept/controller.js +122 -0
- package/dist/reglow/modules/dept/controller.js.map +1 -0
- package/dist/reglow/modules/dept/repository.d.ts +24 -0
- package/dist/reglow/modules/dept/repository.js +140 -0
- package/dist/reglow/modules/dept/repository.js.map +1 -0
- package/dist/reglow/modules/dept/router.d.ts +9 -0
- package/dist/reglow/modules/dept/router.js +7 -0
- package/dist/reglow/modules/dept/router.js.map +1 -0
- package/dist/reglow/modules/dept/schema.d.ts +37 -0
- package/dist/reglow/modules/dept/schema.js +33 -0
- package/dist/reglow/modules/dept/schema.js.map +1 -0
- package/dist/reglow/modules/dept/service.d.ts +33 -0
- package/dist/reglow/modules/dept/service.js +88 -0
- package/dist/reglow/modules/dept/service.js.map +1 -0
- package/dist/reglow/modules/dict/controller.d.ts +5 -0
- package/dist/reglow/modules/dict/controller.js +87 -0
- package/dist/reglow/modules/dict/controller.js.map +1 -0
- package/dist/reglow/modules/dict/model.d.ts +7 -0
- package/dist/reglow/modules/dict/model.js +8 -0
- package/dist/reglow/modules/dict/model.js.map +1 -0
- package/dist/reglow/modules/dict/repository.d.ts +16 -0
- package/dist/reglow/modules/dict/repository.js +103 -0
- package/dist/reglow/modules/dict/repository.js.map +1 -0
- package/dist/reglow/modules/dict/router.d.ts +9 -0
- package/dist/reglow/modules/dict/router.js +7 -0
- package/dist/reglow/modules/dict/router.js.map +1 -0
- package/dist/reglow/modules/dict/schema.d.ts +38 -0
- package/dist/reglow/modules/dict/schema.js +37 -0
- package/dist/reglow/modules/dict/schema.js.map +1 -0
- package/dist/reglow/modules/dict/service.d.ts +15 -0
- package/dist/reglow/modules/dict/service.js +88 -0
- package/dist/reglow/modules/dict/service.js.map +1 -0
- package/dist/reglow/modules/employee/controller.d.ts +6 -0
- package/dist/reglow/modules/employee/controller.js +167 -0
- package/dist/reglow/modules/employee/controller.js.map +1 -0
- package/dist/reglow/modules/employee/repository.d.ts +22 -0
- package/dist/reglow/modules/employee/repository.js +129 -0
- package/dist/reglow/modules/employee/repository.js.map +1 -0
- package/dist/reglow/modules/employee/router.d.ts +9 -0
- package/dist/reglow/modules/employee/router.js +7 -0
- package/dist/reglow/modules/employee/router.js.map +1 -0
- package/dist/reglow/modules/employee/schema.d.ts +57 -0
- package/dist/reglow/modules/employee/schema.js +58 -0
- package/dist/reglow/modules/employee/schema.js.map +1 -0
- package/dist/reglow/modules/employee/service.d.ts +30 -0
- package/dist/reglow/modules/employee/service.js +193 -0
- package/dist/reglow/modules/employee/service.js.map +1 -0
- package/dist/reglow/modules/log/controller.d.ts +6 -0
- package/dist/reglow/modules/log/controller.js +137 -0
- package/dist/reglow/modules/log/controller.js.map +1 -0
- package/dist/reglow/modules/log/data-scope.d.ts +9 -0
- package/dist/reglow/modules/log/data-scope.js +108 -0
- package/dist/reglow/modules/log/data-scope.js.map +1 -0
- package/dist/reglow/modules/log/router.d.ts +9 -0
- package/dist/reglow/modules/log/router.js +7 -0
- package/dist/reglow/modules/log/router.js.map +1 -0
- package/dist/reglow/modules/material/controller.d.ts +3 -0
- package/dist/reglow/modules/material/controller.js +400 -0
- package/dist/reglow/modules/material/controller.js.map +1 -0
- package/dist/reglow/modules/material/repository.d.ts +37 -0
- package/dist/reglow/modules/material/repository.js +183 -0
- package/dist/reglow/modules/material/repository.js.map +1 -0
- package/dist/reglow/modules/material/router.d.ts +14 -0
- package/dist/reglow/modules/material/router.js +11 -0
- package/dist/reglow/modules/material/router.js.map +1 -0
- package/dist/reglow/modules/material/schema.d.ts +40 -0
- package/dist/reglow/modules/material/schema.js +34 -0
- package/dist/reglow/modules/material/schema.js.map +1 -0
- package/dist/reglow/modules/material/service.d.ts +85 -0
- package/dist/reglow/modules/material/service.js +292 -0
- package/dist/reglow/modules/material/service.js.map +1 -0
- package/dist/reglow/modules/menu/controller.d.ts +6 -0
- package/dist/reglow/modules/menu/controller.js +69 -0
- package/dist/reglow/modules/menu/controller.js.map +1 -0
- package/dist/reglow/modules/menu/repository.d.ts +14 -0
- package/dist/reglow/modules/menu/repository.js +37 -0
- package/dist/reglow/modules/menu/repository.js.map +1 -0
- package/dist/reglow/modules/menu/router.d.ts +9 -0
- package/dist/reglow/modules/menu/router.js +7 -0
- package/dist/reglow/modules/menu/router.js.map +1 -0
- package/dist/reglow/modules/menu/schema.d.ts +39 -0
- package/dist/reglow/modules/menu/schema.js +37 -0
- package/dist/reglow/modules/menu/schema.js.map +1 -0
- package/dist/reglow/modules/menu/service.d.ts +31 -0
- package/dist/reglow/modules/menu/service.js +89 -0
- package/dist/reglow/modules/menu/service.js.map +1 -0
- package/dist/reglow/modules/message/controller.d.ts +7 -0
- package/dist/reglow/modules/message/controller.js +260 -0
- package/dist/reglow/modules/message/controller.js.map +1 -0
- package/dist/reglow/modules/message/repository.d.ts +27 -0
- package/dist/reglow/modules/message/repository.js +145 -0
- package/dist/reglow/modules/message/repository.js.map +1 -0
- package/dist/reglow/modules/message/router.d.ts +13 -0
- package/dist/reglow/modules/message/router.js +8 -0
- package/dist/reglow/modules/message/router.js.map +1 -0
- package/dist/reglow/modules/message/schema.d.ts +39 -0
- package/dist/reglow/modules/message/schema.js +37 -0
- package/dist/reglow/modules/message/schema.js.map +1 -0
- package/dist/reglow/modules/message/service.d.ts +70 -0
- package/dist/reglow/modules/message/service.js +199 -0
- package/dist/reglow/modules/message/service.js.map +1 -0
- package/dist/reglow/modules/notice/controller.d.ts +6 -0
- package/dist/reglow/modules/notice/controller.js +123 -0
- package/dist/reglow/modules/notice/controller.js.map +1 -0
- package/dist/reglow/modules/notice/repository.d.ts +25 -0
- package/dist/reglow/modules/notice/repository.js +145 -0
- package/dist/reglow/modules/notice/repository.js.map +1 -0
- package/dist/reglow/modules/notice/router.d.ts +9 -0
- package/dist/reglow/modules/notice/router.js +7 -0
- package/dist/reglow/modules/notice/router.js.map +1 -0
- package/dist/reglow/modules/notice/schema.d.ts +23 -0
- package/dist/reglow/modules/notice/schema.js +22 -0
- package/dist/reglow/modules/notice/schema.js.map +1 -0
- package/dist/reglow/modules/notice/service.d.ts +45 -0
- package/dist/reglow/modules/notice/service.js +149 -0
- package/dist/reglow/modules/notice/service.js.map +1 -0
- package/dist/reglow/modules/payment/controller.d.ts +6 -0
- package/dist/reglow/modules/payment/controller.js +186 -0
- package/dist/reglow/modules/payment/controller.js.map +1 -0
- package/dist/reglow/modules/payment/router.d.ts +10 -0
- package/dist/reglow/modules/payment/router.js +8 -0
- package/dist/reglow/modules/payment/router.js.map +1 -0
- package/dist/reglow/modules/payment/schema.d.ts +52 -0
- package/dist/reglow/modules/payment/schema.js +43 -0
- package/dist/reglow/modules/payment/schema.js.map +1 -0
- package/dist/reglow/modules/payment/service.d.ts +28 -0
- package/dist/reglow/modules/payment/service.js +219 -0
- package/dist/reglow/modules/payment/service.js.map +1 -0
- package/dist/reglow/modules/photo/controller.d.ts +2 -0
- package/dist/reglow/modules/photo/controller.js +323 -0
- package/dist/reglow/modules/photo/controller.js.map +1 -0
- package/dist/reglow/modules/photo/controller_client.d.ts +2 -0
- package/dist/reglow/modules/photo/controller_client.js +293 -0
- package/dist/reglow/modules/photo/controller_client.js.map +1 -0
- package/dist/reglow/modules/photo/repository.d.ts +50 -0
- package/dist/reglow/modules/photo/repository.js +240 -0
- package/dist/reglow/modules/photo/repository.js.map +1 -0
- package/dist/reglow/modules/photo/router.d.ts +15 -0
- package/dist/reglow/modules/photo/router.js +10 -0
- package/dist/reglow/modules/photo/router.js.map +1 -0
- package/dist/reglow/modules/photo/schema.d.ts +69 -0
- package/dist/reglow/modules/photo/schema.js +66 -0
- package/dist/reglow/modules/photo/schema.js.map +1 -0
- package/dist/reglow/modules/photo/service.d.ts +98 -0
- package/dist/reglow/modules/photo/service.js +295 -0
- package/dist/reglow/modules/photo/service.js.map +1 -0
- package/dist/reglow/modules/post/controller.d.ts +6 -0
- package/dist/reglow/modules/post/controller.js +61 -0
- package/dist/reglow/modules/post/controller.js.map +1 -0
- package/dist/reglow/modules/post/repository.d.ts +12 -0
- package/dist/reglow/modules/post/repository.js +46 -0
- package/dist/reglow/modules/post/repository.js.map +1 -0
- package/dist/reglow/modules/post/router.d.ts +9 -0
- package/dist/reglow/modules/post/router.js +7 -0
- package/dist/reglow/modules/post/router.js.map +1 -0
- package/dist/reglow/modules/post/schema.d.ts +19 -0
- package/dist/reglow/modules/post/schema.js +18 -0
- package/dist/reglow/modules/post/schema.js.map +1 -0
- package/dist/reglow/modules/post/service.d.ts +18 -0
- package/dist/reglow/modules/post/service.js +44 -0
- package/dist/reglow/modules/post/service.js.map +1 -0
- package/dist/reglow/modules/role/controller.d.ts +6 -0
- package/dist/reglow/modules/role/controller.js +103 -0
- package/dist/reglow/modules/role/controller.js.map +1 -0
- package/dist/reglow/modules/role/repository.d.ts +22 -0
- package/dist/reglow/modules/role/repository.js +84 -0
- package/dist/reglow/modules/role/repository.js.map +1 -0
- package/dist/reglow/modules/role/router.d.ts +9 -0
- package/dist/reglow/modules/role/router.js +7 -0
- package/dist/reglow/modules/role/router.js.map +1 -0
- package/dist/reglow/modules/role/schema.d.ts +32 -0
- package/dist/reglow/modules/role/schema.js +29 -0
- package/dist/reglow/modules/role/schema.js.map +1 -0
- package/dist/reglow/modules/role/service.d.ts +22 -0
- package/dist/reglow/modules/role/service.js +72 -0
- package/dist/reglow/modules/role/service.js.map +1 -0
- package/dist/reglow/modules/user/controller.d.ts +6 -0
- package/dist/reglow/modules/user/controller.js +126 -0
- package/dist/reglow/modules/user/controller.js.map +1 -0
- package/dist/reglow/modules/user/controller_client.d.ts +2 -0
- package/dist/reglow/modules/user/controller_client.js +291 -0
- package/dist/reglow/modules/user/controller_client.js.map +1 -0
- package/dist/reglow/modules/user/repository.d.ts +12 -0
- package/dist/reglow/modules/user/repository.js +71 -0
- package/dist/reglow/modules/user/repository.js.map +1 -0
- package/dist/reglow/modules/user/router.d.ts +16 -0
- package/dist/reglow/modules/user/router.js +11 -0
- package/dist/reglow/modules/user/router.js.map +1 -0
- package/dist/reglow/modules/user/schema.d.ts +92 -0
- package/dist/reglow/modules/user/schema.js +82 -0
- package/dist/reglow/modules/user/schema.js.map +1 -0
- package/dist/reglow/modules/user/service.d.ts +43 -0
- package/dist/reglow/modules/user/service.js +311 -0
- package/dist/reglow/modules/user/service.js.map +1 -0
- package/dist/reglow/modules/video/controller.d.ts +2 -0
- package/dist/reglow/modules/video/controller.js +254 -0
- package/dist/reglow/modules/video/controller.js.map +1 -0
- package/dist/reglow/modules/video/repository.d.ts +38 -0
- package/dist/reglow/modules/video/repository.js +186 -0
- package/dist/reglow/modules/video/repository.js.map +1 -0
- package/dist/reglow/modules/video/router.d.ts +10 -0
- package/dist/reglow/modules/video/router.js +8 -0
- package/dist/reglow/modules/video/router.js.map +1 -0
- package/dist/reglow/modules/video/schema.d.ts +62 -0
- package/dist/reglow/modules/video/schema.js +61 -0
- package/dist/reglow/modules/video/schema.js.map +1 -0
- package/dist/reglow/modules/video/service.d.ts +80 -0
- package/dist/reglow/modules/video/service.js +251 -0
- package/dist/reglow/modules/video/service.js.map +1 -0
- package/dist/reglow/scripts/init-data.d.ts +44 -0
- package/dist/reglow/scripts/init-data.js +472 -0
- package/dist/reglow/scripts/init-data.js.map +1 -0
- package/dist/reglow/scripts/remove-business-menu.d.ts +1 -0
- package/dist/reglow/scripts/remove-business-menu.js +124 -0
- package/dist/reglow/scripts/remove-business-menu.js.map +1 -0
- package/dist/reglow/scripts/schema.d.ts +9 -0
- package/dist/reglow/scripts/schema.js +746 -0
- package/dist/reglow/scripts/schema.js.map +1 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.d.ts +1 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js +304 -0
- package/dist/reglow/scripts/sync-menu-mysql-to-sqlite.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +162 -0
- package/dist/server.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 角色 Service - 业务逻辑层
|
|
3
|
+
* 对应 backend-python 的 reglow/modules/role/service.py
|
|
4
|
+
*/
|
|
5
|
+
import { RoleRepository } from "./repository.js";
|
|
6
|
+
import { AppException, ErrorCode } from "../../common/errors.js";
|
|
7
|
+
export class RoleService {
|
|
8
|
+
repo = new RoleRepository();
|
|
9
|
+
async getRole(roleId) {
|
|
10
|
+
const role = await this.repo.findById(roleId);
|
|
11
|
+
if (!role)
|
|
12
|
+
throw new AppException(ErrorCode.ROLE_NOT_FOUND, "角色不存在", 404);
|
|
13
|
+
return role;
|
|
14
|
+
}
|
|
15
|
+
async createRole(data) {
|
|
16
|
+
if (await this.repo.findByCode(data.code)) {
|
|
17
|
+
throw new AppException(ErrorCode.ROLE_CODE_EXISTS, "角色编码已存在");
|
|
18
|
+
}
|
|
19
|
+
return await this.repo.create({
|
|
20
|
+
name: data.name,
|
|
21
|
+
code: data.code,
|
|
22
|
+
description: data.description ?? null,
|
|
23
|
+
data_scope: data.data_scope ?? 1,
|
|
24
|
+
sort: data.sort ?? 0,
|
|
25
|
+
status: data.status ?? 1,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async updateRole(roleId, data) {
|
|
29
|
+
await this.getRole(roleId);
|
|
30
|
+
const updateData = {};
|
|
31
|
+
for (const field of [
|
|
32
|
+
"name",
|
|
33
|
+
"code",
|
|
34
|
+
"description",
|
|
35
|
+
"data_scope",
|
|
36
|
+
"sort",
|
|
37
|
+
"status",
|
|
38
|
+
]) {
|
|
39
|
+
const v = data[field];
|
|
40
|
+
if (v !== undefined && v !== null)
|
|
41
|
+
updateData[field] = v;
|
|
42
|
+
}
|
|
43
|
+
return await this.repo.update(roleId, updateData);
|
|
44
|
+
}
|
|
45
|
+
async deleteRole(roleId) {
|
|
46
|
+
await this.getRole(roleId);
|
|
47
|
+
if (await this.repo.hasAdmins(roleId)) {
|
|
48
|
+
throw new AppException(ErrorCode.ROLE_IN_USE, "角色下有管理员,无法删除");
|
|
49
|
+
}
|
|
50
|
+
await this.repo.softDelete(roleId);
|
|
51
|
+
}
|
|
52
|
+
async listRoles(page, size, keyword, status) {
|
|
53
|
+
return await this.repo.findAll(page, size, keyword, status);
|
|
54
|
+
}
|
|
55
|
+
async assignMenus(roleId, menuIds) {
|
|
56
|
+
await this.getRole(roleId);
|
|
57
|
+
await this.repo.assignMenus(roleId, menuIds);
|
|
58
|
+
}
|
|
59
|
+
async setDataScope(roleId, dataScope, deptIds) {
|
|
60
|
+
await this.getRole(roleId);
|
|
61
|
+
return await this.repo.setDataScope(roleId, dataScope, deptIds);
|
|
62
|
+
}
|
|
63
|
+
async getRoleMenuIds(roleId) {
|
|
64
|
+
await this.getRole(roleId);
|
|
65
|
+
return await this.repo.getRoleMenuIds(roleId);
|
|
66
|
+
}
|
|
67
|
+
async getRoleDeptIds(roleId) {
|
|
68
|
+
await this.getRole(roleId);
|
|
69
|
+
return await this.repo.getRoleDeptIds(roleId);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../reglow/modules/role/service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAIjE,MAAM,OAAO,WAAW;IACtB,IAAI,GAAG,IAAI,cAAc,EAAE,CAAC;IAE5B,KAAK,CAAC,OAAO,CAAC,MAAc;QAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI;YACP,MAAM,IAAI,YAAY,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAoB;QACnC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,YAAY,CAAC,SAAS,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;YAC5B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,CAAC;YAChC,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;YACpB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,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C,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,MAAc,EACd,SAAiB,EACjB,OAAiB;QAEjB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAc;QACjC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAc;QACjC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3B,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ApiResponse, PageData } from "../../common/response.js";
|
|
2
|
+
import { mapTimestamp } from "../../common/serialize.js";
|
|
3
|
+
import { UserService } from "./service.js";
|
|
4
|
+
import { UpdateUserSchema, PasswordResetSchema, } from "./schema.js";
|
|
5
|
+
function int(v, def) {
|
|
6
|
+
const n = parseInt(String(v), 10);
|
|
7
|
+
return Number.isNaN(n) ? def : n;
|
|
8
|
+
}
|
|
9
|
+
function intOrNull(v) {
|
|
10
|
+
if (v === undefined || v === null || v === "")
|
|
11
|
+
return null;
|
|
12
|
+
const n = parseInt(String(v), 10);
|
|
13
|
+
return Number.isNaN(n) ? null : n;
|
|
14
|
+
}
|
|
15
|
+
function toBoolOrNull(v) {
|
|
16
|
+
if (v === undefined || v === null || v === "")
|
|
17
|
+
return null;
|
|
18
|
+
return v === true || v === "true" || v === "1" || v === 1;
|
|
19
|
+
}
|
|
20
|
+
const USER_TIME_FIELDS = [
|
|
21
|
+
"created_at",
|
|
22
|
+
"updated_at",
|
|
23
|
+
"registered_at",
|
|
24
|
+
"last_login_at",
|
|
25
|
+
"lock_until",
|
|
26
|
+
];
|
|
27
|
+
function toUserListDto(u) {
|
|
28
|
+
return mapTimestamp({
|
|
29
|
+
id: u.id,
|
|
30
|
+
username: u.username ?? null,
|
|
31
|
+
nickname: u.nickname ?? null,
|
|
32
|
+
real_name: u.real_name ?? null,
|
|
33
|
+
avatar: u.avatar ?? null,
|
|
34
|
+
gender: u.gender ?? 0,
|
|
35
|
+
birthday: u.birthday ?? null,
|
|
36
|
+
phone: u.phone ?? null,
|
|
37
|
+
email: u.email ?? null,
|
|
38
|
+
region: u.region ?? null,
|
|
39
|
+
bio: u.bio ?? null,
|
|
40
|
+
source: u.source ?? null,
|
|
41
|
+
status: u.status ?? 1,
|
|
42
|
+
is_verified: Boolean(u.is_verified),
|
|
43
|
+
vip_level: u.vip_level ?? 0,
|
|
44
|
+
lock_until: u.lock_until ?? null,
|
|
45
|
+
last_login_at: u.last_login_at ?? null,
|
|
46
|
+
registered_at: u.registered_at ?? null,
|
|
47
|
+
created_at: u.created_at ?? null,
|
|
48
|
+
}, USER_TIME_FIELDS);
|
|
49
|
+
}
|
|
50
|
+
function toUserDto(u) {
|
|
51
|
+
return mapTimestamp({
|
|
52
|
+
id: u.id,
|
|
53
|
+
username: u.username ?? null,
|
|
54
|
+
nickname: u.nickname ?? null,
|
|
55
|
+
real_name: u.real_name ?? null,
|
|
56
|
+
avatar: u.avatar ?? null,
|
|
57
|
+
gender: u.gender ?? 0,
|
|
58
|
+
birthday: u.birthday ?? null,
|
|
59
|
+
phone: u.phone ?? null,
|
|
60
|
+
email: u.email ?? null,
|
|
61
|
+
region: u.region ?? null,
|
|
62
|
+
bio: u.bio ?? null,
|
|
63
|
+
source: u.source ?? null,
|
|
64
|
+
status: u.status ?? 1,
|
|
65
|
+
is_verified: Boolean(u.is_verified),
|
|
66
|
+
vip_level: u.vip_level ?? 0,
|
|
67
|
+
login_fail_count: u.login_fail_count ?? 0,
|
|
68
|
+
lock_until: u.lock_until ?? null,
|
|
69
|
+
last_login_at: u.last_login_at ?? null,
|
|
70
|
+
last_login_ip: u.last_login_ip ?? null,
|
|
71
|
+
registered_at: u.registered_at ?? null,
|
|
72
|
+
remark: u.remark ?? null,
|
|
73
|
+
created_at: u.created_at ?? null,
|
|
74
|
+
updated_at: u.updated_at ?? null,
|
|
75
|
+
}, USER_TIME_FIELDS);
|
|
76
|
+
}
|
|
77
|
+
export async function userRoutes(fastify) {
|
|
78
|
+
const service = new UserService();
|
|
79
|
+
fastify.get("/", { schema: { summary: "查询用户列表" }, preHandler: [fastify.requirePermission("system:user:list")] }, async (request) => {
|
|
80
|
+
const query = request.query;
|
|
81
|
+
const page = Math.max(1, int(query.page, 1));
|
|
82
|
+
const size = Math.min(100, Math.max(1, int(query.size, 20)));
|
|
83
|
+
const { items, total } = await service.listUsers(page, size, query.keyword || null, intOrNull(query.status), query.source || null, toBoolOrNull(query.is_verified));
|
|
84
|
+
return ApiResponse.success(new PageData(items.map((u) => toUserListDto(u)), total, page, size));
|
|
85
|
+
});
|
|
86
|
+
fastify.get("/:user_id", { schema: { summary: "查询用户详情" }, preHandler: [fastify.requirePermission("system:user:list")] }, async (request) => {
|
|
87
|
+
const userId = int(request.params.user_id, 0);
|
|
88
|
+
const user = await service.getUserId(userId);
|
|
89
|
+
return ApiResponse.success(toUserDto(user));
|
|
90
|
+
});
|
|
91
|
+
fastify.put("/:user_id", {
|
|
92
|
+
preHandler: [fastify.requirePermission("system:user:update")],
|
|
93
|
+
schema: { summary: "更新用户", body: UpdateUserSchema },
|
|
94
|
+
}, async (request) => {
|
|
95
|
+
const userId = int(request.params.user_id, 0);
|
|
96
|
+
const body = request.body;
|
|
97
|
+
const user = await service.updateUser(userId, body);
|
|
98
|
+
return ApiResponse.success(toUserDto(user), "更新成功");
|
|
99
|
+
});
|
|
100
|
+
fastify.delete("/:user_id", { schema: { summary: "删除用户" }, preHandler: [fastify.requirePermission("system:user:delete")] }, async (request) => {
|
|
101
|
+
const userId = int(request.params.user_id, 0);
|
|
102
|
+
await service.deleteUser(userId);
|
|
103
|
+
return ApiResponse.success(null, "删除成功");
|
|
104
|
+
});
|
|
105
|
+
fastify.put("/:user_id/status", { schema: { summary: "更新用户" }, preHandler: [fastify.requirePermission("system:user:update")] }, async (request) => {
|
|
106
|
+
const userId = int(request.params.user_id, 0);
|
|
107
|
+
const status = int(request.query.status, 0);
|
|
108
|
+
const user = await service.updateStatus(userId, status);
|
|
109
|
+
return ApiResponse.success(toUserDto(user), "状态更新成功");
|
|
110
|
+
});
|
|
111
|
+
fastify.put("/:user_id/password-reset", {
|
|
112
|
+
preHandler: [fastify.requirePermission("system:user:reset_password")],
|
|
113
|
+
schema: { summary: "更新用户", body: PasswordResetSchema },
|
|
114
|
+
}, async (request) => {
|
|
115
|
+
const userId = int(request.params.user_id, 0);
|
|
116
|
+
const body = request.body;
|
|
117
|
+
await service.resetPassword(userId, body.new_password);
|
|
118
|
+
return ApiResponse.success(null, "密码重置成功");
|
|
119
|
+
});
|
|
120
|
+
fastify.put("/:user_id/unlock", { schema: { summary: "更新用户" }, preHandler: [fastify.requirePermission("system:user:update")] }, async (request) => {
|
|
121
|
+
const userId = int(request.params.user_id, 0);
|
|
122
|
+
await service.unlock(userId);
|
|
123
|
+
return ApiResponse.success(null, "解锁成功");
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../reglow/modules/user/controller.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAEh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
|
2
|
+
* 用户模块 Controller - 用户端认证/个人资料
|
|
3
|
+
* 对应 backend-python 的 reglow/modules/user/controller_client.py
|
|
4
|
+
*/
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import crypto from "node:crypto";
|
|
8
|
+
import { ApiResponse } from "../../common/response.js";
|
|
9
|
+
import { AppException, ErrorCode } from "../../common/errors.js";
|
|
10
|
+
import settings from "../../core/config.js";
|
|
11
|
+
import { getRedisStore } from "../../core/redis.js";
|
|
12
|
+
import * as redisKeys from "../../core/redis_keys.js";
|
|
13
|
+
import { checkRateLimit } from "../../core/rate_limit.js";
|
|
14
|
+
import { verifyToken } from "../../core/security.js";
|
|
15
|
+
import { SessionManager } from "../../core/session.js";
|
|
16
|
+
import { ClientAuthService } from "./service.js";
|
|
17
|
+
import { AuthService } from "../auth/service.js";
|
|
18
|
+
import { UserSmsLoginSchema, UserSendSmsCodeSchema, UserSlideCaptchaVerifySchema, UserEmailLoginSchema, UserPhoneLoginSchema, UserRegisterSchema, UserRefreshTokenSchema, UserUpdateProfileSchema, UserAvatarUploadSchema, ChangePasswordSchema, ChangePhoneSchema, SessionRemarkSchema, } from "./schema.js";
|
|
19
|
+
const INVITE_SALT = 6188;
|
|
20
|
+
const BASE36 = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
21
|
+
function encodeInviteCode(userId) {
|
|
22
|
+
let n = userId + INVITE_SALT;
|
|
23
|
+
if (n <= 0)
|
|
24
|
+
return "0";
|
|
25
|
+
let out = "";
|
|
26
|
+
while (n) {
|
|
27
|
+
out = BASE36[n % 36] + out;
|
|
28
|
+
n = Math.floor(n / 36);
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function clientIp(request) {
|
|
33
|
+
const forwarded = request.headers["x-forwarded-for"];
|
|
34
|
+
if (forwarded)
|
|
35
|
+
return String(forwarded).split(",")[0].trim();
|
|
36
|
+
return request.ip || "";
|
|
37
|
+
}
|
|
38
|
+
function tokenOf(request) {
|
|
39
|
+
const header = request.headers.authorization || "";
|
|
40
|
+
return header.startsWith("Bearer ") ? header.slice(7) : "";
|
|
41
|
+
}
|
|
42
|
+
const uploadDir = path.resolve(process.cwd(), settings.UPLOAD_DIR);
|
|
43
|
+
function saveAvatar(buffer, ext) {
|
|
44
|
+
const key = crypto.randomUUID() + ext;
|
|
45
|
+
const dir = path.join(uploadDir, "avatars");
|
|
46
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
47
|
+
fs.writeFileSync(path.join(dir, key), buffer);
|
|
48
|
+
return `/uploads/avatars/${key}`;
|
|
49
|
+
}
|
|
50
|
+
function decodeImage(imageBase64) {
|
|
51
|
+
let raw = imageBase64;
|
|
52
|
+
let ext = "jpg";
|
|
53
|
+
if (imageBase64.includes(",") && imageBase64.startsWith("data:")) {
|
|
54
|
+
const [header, body] = imageBase64.split(",", 2);
|
|
55
|
+
const mime = header.split(";")[0].split("/").pop()?.toLowerCase() ?? "";
|
|
56
|
+
const extMap = {
|
|
57
|
+
png: "png",
|
|
58
|
+
jpeg: "jpg",
|
|
59
|
+
jpg: "jpg",
|
|
60
|
+
webp: "webp",
|
|
61
|
+
};
|
|
62
|
+
ext = extMap[mime] || "jpg";
|
|
63
|
+
raw = body;
|
|
64
|
+
}
|
|
65
|
+
let data;
|
|
66
|
+
try {
|
|
67
|
+
data = Buffer.from(raw, "base64");
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new AppException(ErrorCode.PARAM_ERROR, "图片数据无效");
|
|
71
|
+
}
|
|
72
|
+
if (data.length > 5 * 1024 * 1024) {
|
|
73
|
+
throw new AppException(ErrorCode.PARAM_ERROR, "图片不能超过5MB");
|
|
74
|
+
}
|
|
75
|
+
return { data, ext };
|
|
76
|
+
}
|
|
77
|
+
export async function userClientRoutes(fastify) {
|
|
78
|
+
const service = new ClientAuthService();
|
|
79
|
+
const auth = new AuthService();
|
|
80
|
+
// ── 滑动验证码 ──
|
|
81
|
+
fastify.get("/slide-captcha", { schema: { summary: "获取滑动验证码" } }, async () => {
|
|
82
|
+
return ApiResponse.success(await auth.generateSlideCaptcha());
|
|
83
|
+
});
|
|
84
|
+
fastify.post("/slide-captcha/verify", { schema: { summary: "校验滑动验证码", body: UserSlideCaptchaVerifySchema } }, async (request) => {
|
|
85
|
+
const body = request.body;
|
|
86
|
+
const token = await auth.verifySlideCaptchaAndIssueToken(body.captcha_key, body.slide_x);
|
|
87
|
+
if (!token) {
|
|
88
|
+
return ApiResponse.fail("滑动验证失败,请重试", ErrorCode.PARAM_ERROR);
|
|
89
|
+
}
|
|
90
|
+
return ApiResponse.success({ verify_token: token }, "验证通过");
|
|
91
|
+
});
|
|
92
|
+
// ── 发送短信验证码 ──
|
|
93
|
+
fastify.post("/sms/send", { schema: { summary: "发送短信验证码", body: UserSendSmsCodeSchema } }, async (request) => {
|
|
94
|
+
const body = request.body;
|
|
95
|
+
const ip = clientIp(request);
|
|
96
|
+
await checkRateLimit(redisKeys.smsRateKey(ip || "client", body.phone), 5, 300);
|
|
97
|
+
if (!(await auth.consumeSlideVerifyToken(body.verify_token))) {
|
|
98
|
+
return ApiResponse.fail("滑动验证失败,请重试", ErrorCode.PARAM_ERROR);
|
|
99
|
+
}
|
|
100
|
+
const result = await auth.sendSmsCode(body.phone);
|
|
101
|
+
return ApiResponse.success(result, "验证码发送成功");
|
|
102
|
+
});
|
|
103
|
+
// ── 手机号+验证码登录 ──
|
|
104
|
+
fastify.post("/sms/login", { schema: { summary: "手机号+验证码登录", body: UserSmsLoginSchema } }, async (request) => {
|
|
105
|
+
const body = request.body;
|
|
106
|
+
const ip = clientIp(request);
|
|
107
|
+
await checkRateLimit(redisKeys.loginRateKey(ip || "client", body.phone), 10, 300);
|
|
108
|
+
const userAgent = String(request.headers["user-agent"] || "");
|
|
109
|
+
const result = await service.smsLogin(body.phone, body.code, ip, userAgent);
|
|
110
|
+
return ApiResponse.success(result, "登录成功");
|
|
111
|
+
});
|
|
112
|
+
// ── 邮箱+密码登录 ──
|
|
113
|
+
fastify.post("/email/login", { schema: { summary: "邮箱+密码登录", body: UserEmailLoginSchema } }, async (request) => {
|
|
114
|
+
const body = request.body;
|
|
115
|
+
const ip = clientIp(request);
|
|
116
|
+
await checkRateLimit(redisKeys.loginRateKey(ip || "client", body.email), 10, 300);
|
|
117
|
+
const userAgent = String(request.headers["user-agent"] || "");
|
|
118
|
+
const result = await service.emailLogin(body.email, body.password, ip, userAgent);
|
|
119
|
+
return ApiResponse.success(result, "登录成功");
|
|
120
|
+
});
|
|
121
|
+
// ── 手机号+密码登录 ──
|
|
122
|
+
fastify.post("/phone/login", { schema: { summary: "手机号+密码登录", body: UserPhoneLoginSchema } }, async (request) => {
|
|
123
|
+
const body = request.body;
|
|
124
|
+
const ip = clientIp(request);
|
|
125
|
+
await checkRateLimit(redisKeys.loginRateKey(ip || "client", body.phone), 10, 300);
|
|
126
|
+
const userAgent = String(request.headers["user-agent"] || "");
|
|
127
|
+
const result = await service.phoneLogin(body.phone, body.password, ip, userAgent);
|
|
128
|
+
return ApiResponse.success(result, "登录成功");
|
|
129
|
+
});
|
|
130
|
+
// ── 注册 ──
|
|
131
|
+
fastify.post("/register", { schema: { summary: "注册", body: UserRegisterSchema } }, async (request) => {
|
|
132
|
+
const body = request.body;
|
|
133
|
+
const ip = clientIp(request);
|
|
134
|
+
await checkRateLimit(redisKeys.registerRateKey(ip || "client", body.phone), 5, 600);
|
|
135
|
+
const userAgent = String(request.headers["user-agent"] || "");
|
|
136
|
+
const result = await service.register(body.phone, body.sms_code, body.password, body.nickname ?? null, body.source ?? "phone", body.invite_code ?? "", ip, userAgent);
|
|
137
|
+
return ApiResponse.success(result, "注册成功");
|
|
138
|
+
});
|
|
139
|
+
// ── 刷新 Token ──
|
|
140
|
+
fastify.post("/refresh-token", { schema: { summary: "刷新 Token", body: UserRefreshTokenSchema } }, async (request) => {
|
|
141
|
+
const body = request.body;
|
|
142
|
+
return ApiResponse.success(await service.refreshToken(body.refresh_token));
|
|
143
|
+
});
|
|
144
|
+
// ── 我的邀请信息 ──
|
|
145
|
+
fastify.get("/invite", { schema: { summary: "我的邀请信息" }, preHandler: [fastify.requireClientAuth] }, async (request) => {
|
|
146
|
+
const user = request.currentUser;
|
|
147
|
+
return ApiResponse.success({
|
|
148
|
+
invite_code: encodeInviteCode(user.id),
|
|
149
|
+
invite_points: 0,
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
// ── 当前用户信息 ──
|
|
153
|
+
fastify.get("/info", { schema: { summary: "当前用户信息" }, preHandler: [fastify.requireClientAuth] }, async (request) => {
|
|
154
|
+
const user = request.currentUser;
|
|
155
|
+
return ApiResponse.success({
|
|
156
|
+
id: user.id,
|
|
157
|
+
username: user.username ?? null,
|
|
158
|
+
nickname: user.nickname ?? null,
|
|
159
|
+
real_name: user.real_name ?? null,
|
|
160
|
+
avatar: user.avatar ?? null,
|
|
161
|
+
gender: user.gender ?? 0,
|
|
162
|
+
birthday: user.birthday ?? null,
|
|
163
|
+
phone: user.phone ?? null,
|
|
164
|
+
email: user.email ?? null,
|
|
165
|
+
region: user.region ?? null,
|
|
166
|
+
bio: user.bio ?? null,
|
|
167
|
+
source: user.source ?? null,
|
|
168
|
+
status: user.status ?? 1,
|
|
169
|
+
is_verified: Boolean(user.is_verified),
|
|
170
|
+
vip_level: user.vip_level ?? 0,
|
|
171
|
+
registered_at: user.registered_at ?? null,
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
// ── 更新个人资料 ──
|
|
175
|
+
fastify.put("/profile", {
|
|
176
|
+
preHandler: [fastify.requireClientAuth],
|
|
177
|
+
schema: { summary: "更新个人资料", body: UserUpdateProfileSchema },
|
|
178
|
+
}, async (request) => {
|
|
179
|
+
const user = request.currentUser;
|
|
180
|
+
const body = request.body;
|
|
181
|
+
const updated = await service.updateProfile(user.id, body);
|
|
182
|
+
return ApiResponse.success({
|
|
183
|
+
id: updated.id,
|
|
184
|
+
username: updated.username ?? null,
|
|
185
|
+
nickname: updated.nickname ?? null,
|
|
186
|
+
real_name: updated.real_name ?? null,
|
|
187
|
+
avatar: updated.avatar ?? null,
|
|
188
|
+
gender: updated.gender ?? 0,
|
|
189
|
+
birthday: updated.birthday ?? null,
|
|
190
|
+
phone: updated.phone ?? null,
|
|
191
|
+
email: updated.email ?? null,
|
|
192
|
+
region: updated.region ?? null,
|
|
193
|
+
bio: updated.bio ?? null,
|
|
194
|
+
source: updated.source ?? null,
|
|
195
|
+
status: updated.status ?? 1,
|
|
196
|
+
is_verified: Boolean(updated.is_verified),
|
|
197
|
+
vip_level: updated.vip_level ?? 0,
|
|
198
|
+
registered_at: updated.registered_at ?? null,
|
|
199
|
+
}, "更新成功");
|
|
200
|
+
});
|
|
201
|
+
// ── 上传头像 ──
|
|
202
|
+
fastify.post("/avatar", {
|
|
203
|
+
preHandler: [fastify.requireClientAuth],
|
|
204
|
+
schema: { summary: "上传头像", body: UserAvatarUploadSchema },
|
|
205
|
+
}, async (request) => {
|
|
206
|
+
const body = request.body;
|
|
207
|
+
const { data, ext } = decodeImage(body.image_base64);
|
|
208
|
+
const url = saveAvatar(data, ext);
|
|
209
|
+
return ApiResponse.success({ url }, "上传成功");
|
|
210
|
+
});
|
|
211
|
+
// ── 更换绑定手机 ──
|
|
212
|
+
fastify.post("/change-phone", {
|
|
213
|
+
preHandler: [fastify.requireClientAuth],
|
|
214
|
+
schema: { summary: "更换绑定手机", body: ChangePhoneSchema },
|
|
215
|
+
}, async (request) => {
|
|
216
|
+
const user = request.currentUser;
|
|
217
|
+
const body = request.body;
|
|
218
|
+
await service.changePhone(user.id, body.new_phone, body.new_phone_code, body.old_phone_code ?? "");
|
|
219
|
+
return ApiResponse.success(null, "手机号更换成功");
|
|
220
|
+
});
|
|
221
|
+
// ── 修改密码 ──
|
|
222
|
+
fastify.post("/change-password", {
|
|
223
|
+
preHandler: [fastify.requireClientAuth],
|
|
224
|
+
schema: { summary: "修改密码", body: ChangePasswordSchema },
|
|
225
|
+
}, async (request) => {
|
|
226
|
+
const user = request.currentUser;
|
|
227
|
+
const body = request.body;
|
|
228
|
+
await service.changePassword(user.id, body.old_password, body.new_password);
|
|
229
|
+
return ApiResponse.success(null, "密码修改成功");
|
|
230
|
+
});
|
|
231
|
+
// ── 登出 ──
|
|
232
|
+
fastify.post("/logout", { schema: { summary: "登出" }, preHandler: [fastify.requireClientAuth] }, async (request) => {
|
|
233
|
+
const user = request.currentUser;
|
|
234
|
+
const payload = verifyToken(tokenOf(request));
|
|
235
|
+
if (payload) {
|
|
236
|
+
const sessionId = payload.session_id;
|
|
237
|
+
const deviceType = String(payload.device_type || "desktop");
|
|
238
|
+
if (sessionId) {
|
|
239
|
+
await SessionManager.destroySession("user", user.id, deviceType, sessionId);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return ApiResponse.success(null, "已退出登录");
|
|
243
|
+
});
|
|
244
|
+
// ── 会话列表 ──
|
|
245
|
+
fastify.get("/sessions", { schema: { summary: "会话列表" }, preHandler: [fastify.requireClientAuth] }, async (request) => {
|
|
246
|
+
const user = request.currentUser;
|
|
247
|
+
const sessions = await SessionManager.listSessions("user", user.id);
|
|
248
|
+
const payload = verifyToken(tokenOf(request));
|
|
249
|
+
const currentSessionId = payload?.session_id ?? null;
|
|
250
|
+
return ApiResponse.success(sessions.map((s) => ({
|
|
251
|
+
session_id: s.session_id,
|
|
252
|
+
device_type: s.device_type,
|
|
253
|
+
device_name: s.device_name,
|
|
254
|
+
login_ip: s.login_ip,
|
|
255
|
+
login_at: s.login_at,
|
|
256
|
+
last_access_at: s.last_access_at,
|
|
257
|
+
remark: s.remark || "",
|
|
258
|
+
is_current: s.session_id === currentSessionId,
|
|
259
|
+
})));
|
|
260
|
+
});
|
|
261
|
+
// ── 强制登出指定会话 ──
|
|
262
|
+
fastify.delete("/sessions/:session_id", { schema: { summary: "强制登出指定会话" }, preHandler: [fastify.requireClientAuth] }, async (request) => {
|
|
263
|
+
const user = request.currentUser;
|
|
264
|
+
const sessionId = request.params.session_id;
|
|
265
|
+
const payload = verifyToken(tokenOf(request));
|
|
266
|
+
const currentSessionId = payload?.session_id ?? null;
|
|
267
|
+
if (sessionId === currentSessionId) {
|
|
268
|
+
return ApiResponse.fail("不能登出当前设备,请使用退出登录", ErrorCode.PARAM_ERROR);
|
|
269
|
+
}
|
|
270
|
+
for (const deviceType of ["mobile", "tablet", "desktop"]) {
|
|
271
|
+
await SessionManager.destroySession("user", user.id, deviceType, sessionId);
|
|
272
|
+
}
|
|
273
|
+
return ApiResponse.success(null, "已强制登出");
|
|
274
|
+
});
|
|
275
|
+
// ── 更新会话备注 ──
|
|
276
|
+
fastify.put("/sessions/:session_id/remark", {
|
|
277
|
+
preHandler: [fastify.requireClientAuth],
|
|
278
|
+
schema: { summary: "更新会话备注", body: SessionRemarkSchema },
|
|
279
|
+
}, async (request) => {
|
|
280
|
+
const sessionId = request.params.session_id;
|
|
281
|
+
const body = request.body;
|
|
282
|
+
const store = getRedisStore();
|
|
283
|
+
const detailKey = redisKeys.sessionDetailKey(sessionId);
|
|
284
|
+
if (!(await store.exists(detailKey))) {
|
|
285
|
+
return ApiResponse.fail("会话不存在或已过期", ErrorCode.PARAM_ERROR);
|
|
286
|
+
}
|
|
287
|
+
await store.hset(detailKey, { remark: body.remark });
|
|
288
|
+
return ApiResponse.success(null, "备注已更新");
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=controller_client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller_client.js","sourceRoot":"","sources":["../../../../reglow/modules/user/controller_client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,wB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MAAM,EAAE,CAAC,CAAC;QACrD,OAAO,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { User } from "../../core/entities.js";
|
|
2
|
+
export declare class UserRepository {
|
|
3
|
+
findById(id: number): Promise<User | undefined>;
|
|
4
|
+
findByPhone(phone: string): Promise<User | undefined>;
|
|
5
|
+
findByEmail(email: string): Promise<User | undefined>;
|
|
6
|
+
update(id: number, payload: Record<string, unknown>): Promise<User>;
|
|
7
|
+
softDelete(id: number): Promise<void>;
|
|
8
|
+
list(page: number, size: number, keyword: string | null, status: number | null, source: string | null, isVerified: boolean | null): Promise<{
|
|
9
|
+
items: User[];
|
|
10
|
+
total: number;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用户模块 Repository - 数据访问层
|
|
3
|
+
* 对应 backend-python 的 reglow/modules/user/repository.py
|
|
4
|
+
*/
|
|
5
|
+
import { knex } from "../../core/database.js";
|
|
6
|
+
import { ModelRegistry } from "../../core/models.js";
|
|
7
|
+
const UserT = ModelRegistry.get("User");
|
|
8
|
+
export class UserRepository {
|
|
9
|
+
async findById(id) {
|
|
10
|
+
return (await knex(UserT)
|
|
11
|
+
.where("id", id)
|
|
12
|
+
.whereNull("deleted_at")
|
|
13
|
+
.first());
|
|
14
|
+
}
|
|
15
|
+
async findByPhone(phone) {
|
|
16
|
+
return (await knex(UserT)
|
|
17
|
+
.where("phone", phone)
|
|
18
|
+
.whereNull("deleted_at")
|
|
19
|
+
.first());
|
|
20
|
+
}
|
|
21
|
+
async findByEmail(email) {
|
|
22
|
+
return (await knex(UserT)
|
|
23
|
+
.where("email", email)
|
|
24
|
+
.whereNull("deleted_at")
|
|
25
|
+
.first());
|
|
26
|
+
}
|
|
27
|
+
async update(id, payload) {
|
|
28
|
+
await knex(UserT).where("id", id).update(payload);
|
|
29
|
+
return (await knex(UserT).where("id", id).first());
|
|
30
|
+
}
|
|
31
|
+
async softDelete(id) {
|
|
32
|
+
await knex(UserT)
|
|
33
|
+
.where("id", id)
|
|
34
|
+
.whereNull("deleted_at")
|
|
35
|
+
.update({ deleted_at: knex.fn.now() });
|
|
36
|
+
}
|
|
37
|
+
async list(page, size, keyword, status, source, isVerified) {
|
|
38
|
+
let query = knex(UserT).whereNull("deleted_at");
|
|
39
|
+
let countQuery = knex(UserT).whereNull("deleted_at");
|
|
40
|
+
if (keyword) {
|
|
41
|
+
const like = `%${keyword}%`;
|
|
42
|
+
const apply = (b) => b
|
|
43
|
+
.where("username", "like", like)
|
|
44
|
+
.orWhere("nickname", "like", like)
|
|
45
|
+
.orWhere("real_name", "like", like)
|
|
46
|
+
.orWhere("phone", "like", like)
|
|
47
|
+
.orWhere("email", "like", like);
|
|
48
|
+
query = query.where(apply);
|
|
49
|
+
countQuery = countQuery.where(apply);
|
|
50
|
+
}
|
|
51
|
+
if (status !== null) {
|
|
52
|
+
query = query.where("status", status);
|
|
53
|
+
countQuery = countQuery.where("status", status);
|
|
54
|
+
}
|
|
55
|
+
if (source) {
|
|
56
|
+
query = query.where("source", source);
|
|
57
|
+
countQuery = countQuery.where("source", source);
|
|
58
|
+
}
|
|
59
|
+
if (isVerified !== null) {
|
|
60
|
+
query = query.where("is_verified", isVerified ? 1 : 0);
|
|
61
|
+
countQuery = countQuery.where("is_verified", isVerified ? 1 : 0);
|
|
62
|
+
}
|
|
63
|
+
const items = (await query
|
|
64
|
+
.orderBy("id", "desc")
|
|
65
|
+
.offset((page - 1) * size)
|
|
66
|
+
.limit(size));
|
|
67
|
+
const totalRow = (await countQuery.count({ c: "*" }).first());
|
|
68
|
+
return { items, total: Number(totalRow?.c) || 0 };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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