@yrpri/api 9.0.101 → 9.0.103
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/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +11 -1
- package/active-citizen/llms/baseChatBot.js +8 -75
- package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
- package/agents/assistants/agentAssistant.js +3 -2
- package/agents/assistants/baseAssistant.js +7 -30
- package/agents/assistants/baseAssistantWithVoice.js +3 -3
- package/agents/assistants/voiceAssistant.js +2 -2
- package/agents/controllers/agentProductController.js +2 -1
- package/agents/controllers/agentSubscriptionController.js +20 -11
- package/agents/controllers/assistantsController.js +171 -127
- package/agents/controllers/policySynthAgents.js +33 -12
- package/agents/managers/newAiModelSetup.js +96 -0
- package/agents/managers/subscriptionManager.js +2 -2
- package/app.js +12 -12
- package/authorization.cjs +4 -0
- package/controllers/allOurIdeas.js +2 -1
- package/controllers/communities.cjs +47 -1
- package/controllers/groups.cjs +67 -4
- package/controllers/index.cjs +7 -7
- package/controllers/nonSpa.cjs +1 -1
- package/dist/active-citizen/controllers/activities.cjs +174 -0
- package/dist/active-citizen/controllers/news_feeds.cjs +96 -0
- package/dist/active-citizen/controllers/notifications.cjs +243 -0
- package/dist/active-citizen/controllers/recommendations.cjs +280 -0
- package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +204 -0
- package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +66 -0
- package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +38 -0
- package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +334 -0
- package/dist/active-citizen/engine/analytics/importer.js +308 -0
- package/dist/active-citizen/engine/analytics/manager.cjs +377 -0
- package/dist/active-citizen/engine/analytics/plausible/manager.cjs +500 -0
- package/dist/active-citizen/engine/analytics/statsCalc.cjs +194 -0
- package/dist/active-citizen/engine/analytics/utils.cjs +369 -0
- package/dist/active-citizen/engine/marketing/campaign.cjs +90 -0
- package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +313 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +239 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +211 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +120 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +114 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +101 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +84 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +15 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +133 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +185 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +184 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +170 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +109 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +140 -0
- package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +279 -0
- package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +386 -0
- package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +49 -0
- package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +68 -0
- package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +288 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +33 -0
- package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +56 -0
- package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +106 -0
- package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +344 -0
- package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +810 -0
- package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +15 -0
- package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +362 -0
- package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +268 -0
- package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +439 -0
- package/dist/active-citizen/engine/notifications/emails_utils.cjs +569 -0
- package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +233 -0
- package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +118 -0
- package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +41 -0
- package/dist/active-citizen/engine/notifications/notifications_utils.cjs +148 -0
- package/dist/active-citizen/engine/notifications/point_delivery.cjs +54 -0
- package/dist/active-citizen/engine/notifications/post_delivery.cjs +31 -0
- package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +471 -0
- package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +212 -0
- package/dist/active-citizen/engine/old/exporters/categories_dataset.js +153 -0
- package/dist/active-citizen/engine/old/exporters/dataset_tools.js +80 -0
- package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +157 -0
- package/dist/active-citizen/engine/recommendations/events_importer.cjs +139 -0
- package/dist/active-citizen/engine/recommendations/events_manager.cjs +212 -0
- package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +83 -0
- package/dist/active-citizen/engine/reports/commonUtils.js +75 -0
- package/dist/active-citizen/engine/reports/common_utils.cjs +740 -0
- package/dist/active-citizen/engine/reports/docx_group_report.cjs +596 -0
- package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +232 -0
- package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +277 -0
- package/dist/active-citizen/engine/reports/xls_group_report.cjs +718 -0
- package/dist/active-citizen/llms/baseChatBot.js +183 -0
- package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +109 -0
- package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +84 -0
- package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +49 -0
- package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +64 -0
- package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +107 -0
- package/dist/active-citizen/llms/imageGeneration/s3Service.js +110 -0
- package/dist/active-citizen/llms/llmTranslation.js +472 -0
- package/dist/active-citizen/models/ac_activity.cjs +216 -0
- package/dist/active-citizen/models/ac_background_job.cjs +109 -0
- package/dist/active-citizen/models/ac_campaign.cjs +97 -0
- package/dist/active-citizen/models/ac_client_activity.cjs +23 -0
- package/dist/active-citizen/models/ac_delayed_notification.cjs +43 -0
- package/dist/active-citizen/models/ac_following.cjs +43 -0
- package/dist/active-citizen/models/ac_list.cjs +68 -0
- package/dist/active-citizen/models/ac_list_users.cjs +19 -0
- package/dist/active-citizen/models/ac_mute.cjs +27 -0
- package/dist/active-citizen/models/ac_news_feed_item.cjs +57 -0
- package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +59 -0
- package/dist/active-citizen/models/ac_notification.cjs +292 -0
- package/dist/active-citizen/models/ac_translation_cache.cjs +750 -0
- package/dist/active-citizen/models/ac_watching.cjs +31 -0
- package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +13 -0
- package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +63 -0
- package/dist/active-citizen/scripts/kue_status.js +31 -0
- package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +24 -0
- package/dist/active-citizen/scripts/translation_clear_language.js +117 -0
- package/dist/active-citizen/scripts/translation_delete.js +27 -0
- package/dist/active-citizen/scripts/translation_replace_text_from_url.js +180 -0
- package/dist/active-citizen/scripts/translation_update.js +28 -0
- package/dist/active-citizen/scripts/translations_list.js +27 -0
- package/{active-citizen/utils/airbrake.js → dist/active-citizen/utils/airbrake.cjs} +1 -1
- package/dist/active-citizen/utils/get_anonymous_system_user.cjs +21 -0
- package/dist/active-citizen/utils/i18n.cjs +3 -0
- package/dist/active-citizen/utils/logger.cjs +25 -0
- package/dist/active-citizen/utils/redisConnection.cjs +29 -0
- package/dist/active-citizen/utils/to_json.cjs +9 -0
- package/dist/active-citizen/utils/translation_cloning.cjs +171 -0
- package/dist/active-citizen/utils/translation_helpers.cjs +534 -0
- package/dist/active-citizen/utils/truncate_text.cjs +21 -0
- package/dist/active-citizen/utils/updateAllLocalesFromEn.js +253 -0
- package/dist/active-citizen/utils/updateLocaleFolders.js +34 -0
- package/dist/active-citizen/workers/activity.cjs +189 -0
- package/dist/active-citizen/workers/anonymizations.cjs +734 -0
- package/dist/active-citizen/workers/bulk_status_update.cjs +458 -0
- package/dist/active-citizen/workers/delayed_jobs.cjs +244 -0
- package/dist/active-citizen/workers/deletions.cjs +1911 -0
- package/dist/active-citizen/workers/email.cjs +9 -0
- package/dist/active-citizen/workers/fraud_management.cjs +109 -0
- package/dist/active-citizen/workers/generativeAi.js +56 -0
- package/dist/active-citizen/workers/main.cjs +89 -0
- package/dist/active-citizen/workers/marketing.cjs +25 -0
- package/dist/active-citizen/workers/moderation.cjs +73 -0
- package/dist/active-citizen/workers/notification_delivery.cjs +368 -0
- package/dist/active-citizen/workers/notification_news_feed.cjs +142 -0
- package/dist/active-citizen/workers/queue.cjs +99 -0
- package/dist/active-citizen/workers/recount.cjs +74 -0
- package/dist/active-citizen/workers/reports.cjs +42 -0
- package/dist/active-citizen/workers/similarities.cjs +21 -0
- package/dist/active-citizen/workers/speech_to_text.cjs +482 -0
- package/dist/agents/assistants/agentAssistant.js +88 -0
- package/dist/agents/assistants/baseAssistant.js +888 -0
- package/dist/agents/assistants/baseAssistantWithVoice.js +150 -0
- package/dist/agents/assistants/modes/agentDirectConnection.js +84 -0
- package/dist/agents/assistants/modes/agentSelectionMode.js +44 -0
- package/dist/agents/assistants/modes/baseAssistantMode.js +54 -0
- package/dist/agents/assistants/modes/tools/agentTools.js +447 -0
- package/dist/agents/assistants/modes/tools/baseTools.js +58 -0
- package/dist/agents/assistants/modes/tools/loginTools.js +156 -0
- package/dist/agents/assistants/modes/tools/models/agents.js +146 -0
- package/dist/agents/assistants/modes/tools/models/subscriptions.js +332 -0
- package/dist/agents/assistants/modes/tools/models/users.js +11 -0
- package/dist/agents/assistants/modes/tools/navigationTools.js +166 -0
- package/{agents/assistants/modes/tools/workflowConversationTools.js → dist/agents/assistants/modes/tools/subscriptionTools.js} +1 -4
- package/{agents/assistants/modes/tools/workflowTools.js → dist/agents/assistants/modes/tools/workflowConverstationTools.js} +1 -1
- package/dist/agents/assistants/voiceAssistant.js +619 -0
- package/dist/agents/controllers/agentProductController.js +103 -0
- package/dist/agents/controllers/agentSubscriptionController.js +261 -0
- package/dist/agents/controllers/assistantsController.js +511 -0
- package/dist/agents/controllers/policySynthAgents.js +395 -0
- package/{agents → dist/agents/managers}/agentProductManager.js +2 -2
- package/dist/agents/managers/emailInvitesManager.js +55 -0
- package/dist/agents/managers/emailTemplateRenderer.js +362 -0
- package/dist/agents/managers/newAiModelSetup.js +650 -0
- package/dist/agents/managers/notificationAgentQueueManager.js +510 -0
- package/dist/agents/managers/subscriptionManager.js +535 -0
- package/dist/agents/managers/workflowConversationManager.js +79 -0
- package/dist/agents/models/agentProduct.js +116 -0
- package/dist/agents/models/agentProductBoosterPurchase.js +58 -0
- package/dist/agents/models/agentProductBundle.js +68 -0
- package/dist/agents/models/agentProductRun.js +52 -0
- package/dist/agents/models/discount.js +88 -0
- package/dist/agents/models/subscription.js +79 -0
- package/dist/agents/models/subscriptionPlan.js +46 -0
- package/dist/agents/models/subscriptionUser.js +27 -0
- package/dist/agents/models/testData/createEvolyAgentProduct.js +477 -0
- package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +230 -0
- package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +233 -0
- package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +230 -0
- package/{agents/models/workflowConverstation.js → dist/agents/models/workflowConversation.js} +1 -1
- package/{agents/tools/updateTemplateWorkflow.js → dist/agents/tools/setTemplateWorkflowCommunityId.js} +1 -0
- package/dist/app.js +943 -0
- package/dist/authorization.cjs +1860 -0
- package/dist/bot_control.js +1930 -0
- package/dist/config/config.cjs +14 -0
- package/dist/config/config.js +14 -0
- package/dist/controllers/allOurIdeas.js +696 -0
- package/dist/controllers/audios.cjs +100 -0
- package/dist/controllers/bulkStatusUpdates.cjs +202 -0
- package/dist/controllers/categories.cjs +199 -0
- package/dist/controllers/communities.cjs +2996 -0
- package/dist/controllers/domains.cjs +1341 -0
- package/dist/controllers/externalIds.cjs +223 -0
- package/dist/controllers/groups.cjs +4309 -0
- package/dist/controllers/images.cjs +499 -0
- package/dist/controllers/index.cjs +449 -0
- package/dist/controllers/legacyPages.cjs +35 -0
- package/dist/controllers/legacyPosts.cjs +56 -0
- package/dist/controllers/legacyUsers.cjs +36 -0
- package/dist/controllers/nonSpa.cjs +574 -0
- package/dist/controllers/organizations.cjs +250 -0
- package/dist/controllers/points.cjs +1137 -0
- package/dist/controllers/posts.cjs +2036 -0
- package/dist/controllers/ratings.cjs +234 -0
- package/dist/controllers/users.cjs +2255 -0
- package/dist/controllers/videos.cjs +226 -0
- package/dist/deleteUnwantedDeclerations.cjs +55 -0
- package/dist/migrations/agentAuditLogs.cjs +46 -0
- package/dist/migrations/agentClasses.cjs +60 -0
- package/dist/migrations/agentConnectorClasses.cjs +61 -0
- package/dist/migrations/agentConnectors.cjs +50 -0
- package/dist/migrations/agentEvals.cjs +45 -0
- package/dist/migrations/agentRegistries.cjs +40 -0
- package/dist/migrations/agents.cjs +54 -0
- package/dist/migrations/aiModels.cjs +49 -0
- package/dist/migrations/apiUsage.cjs +47 -0
- package/dist/migrations/apis.cjs +49 -0
- package/dist/migrations/groupPrivateData.cjs +30 -0
- package/dist/migrations/modelUsage.cjs +60 -0
- package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +23 -0
- package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +360 -0
- package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +29 -0
- package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +24 -0
- package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +29 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +22 -0
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +23 -0
- package/{migrations/200824_create_embeddings_and_org_update.cjs → dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js} +6 -3
- package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +43 -0
- package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +36 -0
- package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +41 -0
- package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +88 -0
- package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +33 -0
- package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +38 -0
- package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +19 -0
- package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +127 -0
- package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +68 -0
- package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +63 -0
- package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +14 -0
- package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +71 -0
- package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +12 -0
- package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +46 -0
- package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +46 -0
- package/dist/migrations/privateAccessStore.cjs +55 -0
- package/dist/migrations/zzz_associations.cjs +154 -0
- package/dist/migrations/zzzzz_create_agent_runs.cjs +606 -0
- package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +11 -0
- package/dist/migrations/zzzzzzz_create_trees.cjs +81 -0
- package/dist/models/audio.cjs +430 -0
- package/dist/models/bulk_status_update.cjs +58 -0
- package/dist/models/campaign.cjs +78 -0
- package/dist/models/category.cjs +94 -0
- package/dist/models/community.cjs +337 -0
- package/dist/models/domain.cjs +486 -0
- package/dist/models/endorsement.cjs +39 -0
- package/dist/models/general_data_store.cjs +20 -0
- package/dist/models/group.cjs +728 -0
- package/dist/models/image.cjs +579 -0
- package/dist/models/index.cjs +186 -0
- package/dist/models/invite.cjs +48 -0
- package/dist/models/iso_country.cjs +16 -0
- package/dist/models/organization.cjs +122 -0
- package/dist/models/page.cjs +273 -0
- package/dist/models/point.cjs +622 -0
- package/dist/models/point_quality.cjs +39 -0
- package/dist/models/point_revision.cjs +47 -0
- package/dist/models/post.cjs +680 -0
- package/dist/models/post_revision.cjs +38 -0
- package/dist/models/post_status_change.cjs +35 -0
- package/dist/models/promotion.cjs +34 -0
- package/dist/models/rating.cjs +51 -0
- package/dist/models/relationship.cjs +19 -0
- package/dist/models/request_to_join.cjs +20 -0
- package/dist/models/user.cjs +604 -0
- package/dist/models/user_legacy_password.cjs +13 -0
- package/dist/models/video.cjs +1137 -0
- package/dist/publish.js +40 -0
- package/dist/repack.js +53 -0
- package/dist/scripts/addRatingUsersToGroup.js +51 -0
- package/dist/scripts/addUserToOrganization.js +71 -0
- package/dist/scripts/analyseRatingsForCommunity.js +150 -0
- package/dist/scripts/analyzeAndFixBrokenPointUsers.js +28 -0
- package/dist/scripts/analyzeEndorsementsByCountry.js +70 -0
- package/dist/scripts/analyzePostsForCommunity.js +185 -0
- package/dist/scripts/bulkStatusUpdates/listUpdates.js +14 -0
- package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +110 -0
- package/dist/scripts/bulkStatusUpdates/performUpdate.js +116 -0
- package/{scripts/bulkStatusUpdates/performUpdateForGroup.js → dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs} +1 -2
- package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +141 -0
- package/dist/scripts/change/changeVideoAspectTo.js +34 -0
- package/dist/scripts/change/setUseNewVersion.cjs +22 -0
- package/dist/scripts/changeCommunityGroupcount.js +30 -0
- package/dist/scripts/changeCommunityPostCount.js +30 -0
- package/dist/scripts/changeGroupPostCount.js +30 -0
- package/dist/scripts/changeLanguage.js +50 -0
- package/dist/scripts/changeOfficalStatus.js +30 -0
- package/{scripts/cleanups/deleteAnonNotifications.js → dist/scripts/cleanups/deleteAnonNotifications.cjs} +1 -1
- package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +62 -0
- package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +72 -0
- package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +43 -0
- package/dist/scripts/clearAllEndorsementInGroup.js +50 -0
- package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +129 -0
- package/dist/scripts/cloning/cloneFromUrlScript.js +65 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +140 -0
- package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +140 -0
- package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +173 -0
- package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +18 -0
- package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +17 -0
- package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +26 -0
- package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +205 -0
- package/dist/scripts/cloning/copyPostToGroupOld.js +397 -0
- package/dist/scripts/cloning/copyPostVideosFromURL.js +236 -0
- package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +17 -0
- package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +131 -0
- package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +139 -0
- package/dist/scripts/cloning/setAdminsFromURL.js +161 -0
- package/dist/scripts/cloning/setExternalIdsFromURL.js +129 -0
- package/dist/scripts/countCommunity.js +291 -0
- package/dist/scripts/countCommunityUsers.js +152 -0
- package/dist/scripts/countDelayedNotifications.js +18 -0
- package/dist/scripts/countGroup.js +246 -0
- package/dist/scripts/countStuff.js +67 -0
- package/dist/scripts/countUniqueVotersInAGroup.js +48 -0
- package/dist/scripts/createInvitesAndShow.js +75 -0
- package/dist/scripts/database/sync_database.js +14 -0
- package/dist/scripts/database/sync_dev_database.js +17 -0
- package/dist/scripts/debugNotifications.js +58 -0
- package/dist/scripts/deleteAllNewsFeeds.js +10 -0
- package/dist/scripts/deleteCategory.js +13 -0
- package/dist/scripts/deleteOldAppActivities.js +40 -0
- package/dist/scripts/deletePostContactDataForCommunity.js +53 -0
- package/dist/scripts/destroy/destroy_all_but_one_domain.js +1026 -0
- package/dist/scripts/displayAuthorForPost.js +16 -0
- package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +183 -0
- package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +208 -0
- package/dist/scripts/exportAllStatusChanges.js +36 -0
- package/dist/scripts/exportClientAcitivity.js +36 -0
- package/dist/scripts/exportEndorsementsForCommunity.js +79 -0
- package/dist/scripts/exportPointQualitiesForCommunity.js +84 -0
- package/dist/scripts/exportPostsAndPointsForCommunity.js +147 -0
- package/dist/scripts/exportPostsDataSetForDomain.js +244 -0
- package/dist/scripts/exportPostsForGroup.js +173 -0
- package/dist/scripts/exportRatingsForPost.js +15 -0
- package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +123 -0
- package/dist/scripts/exportUsersForCommunity.js +24 -0
- package/dist/scripts/exportUsersForDomain.js +24 -0
- package/dist/scripts/exportUsersForGroup.js +24 -0
- package/dist/scripts/exports/ratingDistribution.js +71 -0
- package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +56 -0
- package/dist/scripts/findUnusedClientImports.js +56 -0
- package/dist/scripts/fixAllPostPointCounts.js +22 -0
- package/dist/scripts/fixAnonNotificationsSettings.js +48 -0
- package/dist/scripts/fixCountKopavogur.js +9 -0
- package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +190 -0
- package/dist/scripts/fixExternalUserId.js +24 -0
- package/dist/scripts/fixGroupAccess.js +16 -0
- package/dist/scripts/fixGroupIdeasAndPointsCount.js +49 -0
- package/dist/scripts/fixNotificationSettings.js +39 -0
- package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +64 -0
- package/dist/scripts/fixWrongUserIdForStatusUpdates.js +49 -0
- package/dist/scripts/gallery/exportGalleryData.js +40 -0
- package/dist/scripts/gallery/importGalleryForCommunity.js +168 -0
- package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +55 -0
- package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +58 -0
- package/dist/scripts/genderAnalysis.js +63 -0
- package/dist/scripts/genderAnalysisByStatus.js +62 -0
- package/dist/scripts/importAllLocalesFromLocalFolders.js +55 -0
- package/dist/scripts/importDomain.js +1652 -0
- package/dist/scripts/keys/addOidcToDomain.cjs +61 -0
- package/dist/scripts/landUseGame/export3Ddata.js +162 -0
- package/dist/scripts/listLanguagesForGroup.js +54 -0
- package/dist/scripts/loadTestCreateDummyContentForGroup.js +27 -0
- package/dist/scripts/makeRecursiveMapData.js +103 -0
- package/dist/scripts/mapping/community_map_csv.js +145 -0
- package/dist/scripts/moveCommunityToDomain.js +22 -0
- package/dist/scripts/moveGroupToCommunity.js +23 -0
- package/dist/scripts/movePostToGroup.js +101 -0
- package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +297 -0
- package/dist/scripts/oldMovePostToGroup.js +153 -0
- package/dist/scripts/processCsvForPdfUrls.js +37 -0
- package/dist/scripts/processCsvForTranslationAndToxicity.js +125 -0
- package/dist/scripts/recount/recount_recursive_communities.js +125 -0
- package/dist/scripts/recountALLCommunityGroupCounts.js +37 -0
- package/dist/scripts/recountAll.js +97 -0
- package/dist/scripts/recountCommunitesFromUrl.js +58 -0
- package/dist/scripts/recountCommunity.js +19 -0
- package/dist/scripts/recountGroup.js +218 -0
- package/dist/scripts/recountGroupNoUserChange.js +219 -0
- package/dist/scripts/resetAllEndorsementsForGroup.js +57 -0
- package/dist/scripts/resetEnTranslationForGroup.js +45 -0
- package/dist/scripts/setAdminOnAll.cjs +107 -0
- package/{scripts/change → dist/scripts}/setDomainAdmin.cjs +0 -2
- package/dist/scripts/setDomainLocales.js +33 -0
- package/dist/scripts/setEarlQuestionIdOnGroup.cjs +29 -0
- package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +86 -0
- package/dist/scripts/setMemberOfAll.js +101 -0
- package/dist/scripts/setNewUserForContentOfCommunity.js +189 -0
- package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +35 -0
- package/dist/scripts/setUserOnAll.js +101 -0
- package/dist/scripts/showCategoryForGroup.js +18 -0
- package/dist/scripts/showOldActivityTypes.js +14 -0
- package/dist/scripts/showPostsMissingCategoryForGroup.js +17 -0
- package/dist/scripts/showStatuses.js +17 -0
- package/dist/scripts/showUniqueVotersInCommunity.js +61 -0
- package/dist/scripts/showUserAgentsAndIpsForEmails.js +66 -0
- package/dist/scripts/simpleExportForGroupsForCommunity.js +46 -0
- package/dist/scripts/simpleExportForPointsForCommunity.js +82 -0
- package/dist/scripts/simpleExportForPostsForCommunity.js +61 -0
- package/dist/scripts/testForEndorsments.js +21 -0
- package/dist/scripts/undeleteGroupAndAllContent.js +151 -0
- package/dist/scripts/undeletePost.js +135 -0
- package/dist/scripts/unlinkSsn.js +23 -0
- package/dist/scripts/updateFromAlthingi.js +303 -0
- package/dist/server.js +3 -0
- package/dist/utils/airbrake.cjs +17 -0
- package/dist/utils/cjsCodeReview.js +99 -0
- package/dist/utils/community_mapping_tools.cjs +124 -0
- package/dist/utils/copy_utils.cjs +1399 -0
- package/dist/utils/docx_utils.cjs +464 -0
- package/dist/utils/export_utils.cjs +491 -0
- package/dist/utils/i18n.cjs +17 -0
- package/dist/utils/is_valid_db_id.cjs +28 -0
- package/dist/utils/logger.cjs +25 -0
- package/dist/utils/loggerTs.js +26 -0
- package/dist/utils/manifest_generator.cjs +104 -0
- package/dist/utils/parse_domain.cjs +16 -0
- package/dist/utils/recount_utils.cjs +415 -0
- package/dist/utils/sharing_parameters.cjs +111 -0
- package/dist/utils/sitemap_generator.cjs +286 -0
- package/dist/utils/to_json.cjs +14 -0
- package/dist/utils/ypLanguages.js +747 -0
- package/dist/webSockets.js +77 -0
- package/package.json +46 -44
- package/server.d.ts +104 -2
- package/utils/copy_utils.cjs +7 -1
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
- package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
- package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
- package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
- package/active-citizen/llms/baseChatBot.d.ts +0 -51
- package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
- package/active-citizen/llms/collectionImageGenerator.js +0 -357
- package/active-citizen/llms/llmTranslation.d.ts +0 -24
- package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
- package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
- package/active-citizen/scripts/kue_status.d.ts.map +0 -1
- package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
- package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
- package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
- package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
- package/active-citizen/scripts/translation_update.d.ts.map +0 -1
- package/active-citizen/scripts/translations_list.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.d.ts.map +0 -1
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
- package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
- package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
- package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
- package/active-citizen/workers/generativeAi.d.ts.map +0 -1
- package/agents/assistants/agentAssistantOld.js +0 -863
- package/agents/assistants/modes/agentConfigurationMode.js +0 -63
- package/agents/assistants/modes/agentOperationsMode.js +0 -195
- package/agents/assistants/modes/commonTools.js +0 -58
- package/agents/assistants/modes/directConversationMode.js +0 -14
- package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
- package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
- package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
- package/agents/assistants/modes/tools/commonHandlers.js +0 -57
- package/agents/assistants/modes/tools/loginHandlers.js +0 -46
- package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
- package/agents/controllers/assistantController.js +0 -243
- package/agents/managers/workflowManager.js +0 -76
- package/agents/models/testData/setupConfig.js +0 -140
- package/agents/models/workflow.js +0 -53
- package/agents/subscriptionManager.js +0 -218
- package/app.d.ts +0 -40
- package/app.d.ts.map +0 -1
- package/bot_control.d.ts.map +0 -1
- package/publish.d.ts.map +0 -1
- package/repack.d.ts.map +0 -1
- package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
- package/scripts/addUserToOrganization.d.ts.map +0 -1
- package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
- package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
- package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
- package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
- package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
- package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
- package/scripts/changeCommunityPostCount.d.ts.map +0 -1
- package/scripts/changeGroupPostCount.d.ts.map +0 -1
- package/scripts/changeLanguage.d.ts.map +0 -1
- package/scripts/changeOfficalStatus.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
- package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
- package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
- package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
- package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
- package/scripts/countCommunity.d.ts.map +0 -1
- package/scripts/countCommunityUsers.d.ts.map +0 -1
- package/scripts/countDelayedNotifications.d.ts.map +0 -1
- package/scripts/countGroup.d.ts.map +0 -1
- package/scripts/countStuff.d.ts.map +0 -1
- package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
- package/scripts/createInvitesAndShow.d.ts.map +0 -1
- package/scripts/database/seedTestAiModels.js +0 -64
- package/scripts/database/sync_database.d.ts.map +0 -1
- package/scripts/database/sync_dev_database.d.ts.map +0 -1
- package/scripts/debugNotifications.d.ts.map +0 -1
- package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
- package/scripts/deleteCategory.d.ts.map +0 -1
- package/scripts/deleteOldAppActivities.d.ts.map +0 -1
- package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
- package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
- package/scripts/displayAuthorForPost.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
- package/scripts/exportAllStatusChanges.d.ts.map +0 -1
- package/scripts/exportClientAcitivity.d.ts.map +0 -1
- package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
- package/scripts/exportPostsForGroup.d.ts.map +0 -1
- package/scripts/exportRatingsForPost.d.ts.map +0 -1
- package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
- package/scripts/exportUsersForCommunity.d.ts.map +0 -1
- package/scripts/exportUsersForDomain.d.ts.map +0 -1
- package/scripts/exportUsersForGroup.d.ts.map +0 -1
- package/scripts/exports/ratingDistribution.d.ts.map +0 -1
- package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
- package/scripts/findUnusedClientImports.d.ts.map +0 -1
- package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
- package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
- package/scripts/fixCountKopavogur.d.ts.map +0 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
- package/scripts/fixExternalUserId.d.ts.map +0 -1
- package/scripts/fixGroupAccess.d.ts.map +0 -1
- package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
- package/scripts/fixNotificationSettings.d.ts.map +0 -1
- package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
- package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
- package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
- package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
- package/scripts/genderAnalysis.d.ts.map +0 -1
- package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
- package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
- package/scripts/importDomain.d.ts.map +0 -1
- package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
- package/scripts/listLanguagesForGroup.d.ts.map +0 -1
- package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
- package/scripts/makeRecursiveMapData.d.ts.map +0 -1
- package/scripts/mapping/community_map_csv.d.ts.map +0 -1
- package/scripts/moveCommunityToDomain.d.ts.map +0 -1
- package/scripts/moveGroupToCommunity.d.ts.map +0 -1
- package/scripts/movePostToGroup.d.ts.map +0 -1
- package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
- package/scripts/oldMovePostToGroup.d.ts.map +0 -1
- package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
- package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
- package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
- package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
- package/scripts/recountAll.d.ts.map +0 -1
- package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/recountCommunity.d.ts.map +0 -1
- package/scripts/recountGroup.d.ts.map +0 -1
- package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
- package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
- package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
- package/scripts/setDomainLocales.d.ts.map +0 -1
- package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/setMemberOfAll.d.ts.map +0 -1
- package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
- package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
- package/scripts/setUserOnAll.d.ts.map +0 -1
- package/scripts/showCategoryForGroup.d.ts.map +0 -1
- package/scripts/showOldActivityTypes.d.ts.map +0 -1
- package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
- package/scripts/showStatuses.d.ts.map +0 -1
- package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
- package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
- package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
- package/scripts/testForEndorsments.d.ts.map +0 -1
- package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
- package/scripts/undeletePost.d.ts.map +0 -1
- package/scripts/unlinkSsn.d.ts.map +0 -1
- package/scripts/updateFromAlthingi.d.ts.map +0 -1
- package/server.d.ts.map +0 -1
- package/utils/copyGroup.js +0 -246
- package/utils/loggerTs.d.ts +0 -4
- package/utils/loggerTs.d.ts.map +0 -1
- package/utils/ypLanguages.d.ts +0 -18
- package/utils/ypLanguages.d.ts.map +0 -1
- /package/{agents/tools/updateCommunityWorkflow.js → dist/active-citizen/llms/imageGeneration/iImageGenerator.js} +0 -0
- /package/{migrations/270724_createUsersAndAdminsForClasses.cjs → dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs} +0 -0
|
@@ -0,0 +1,1137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var express = require("express");
|
|
3
|
+
var router = express.Router();
|
|
4
|
+
var models = require("../models/index.cjs");
|
|
5
|
+
var auth = require("../authorization.cjs");
|
|
6
|
+
var log = require("../utils/logger.cjs");
|
|
7
|
+
var toJson = require("../utils/to_json.cjs");
|
|
8
|
+
var async = require("async");
|
|
9
|
+
const ogs = require("open-graph-scraper");
|
|
10
|
+
var _ = require("lodash");
|
|
11
|
+
var queue = require("../active-citizen/workers/queue.cjs");
|
|
12
|
+
var changePointCounter = function (pointId, column, upDown, next) {
|
|
13
|
+
models.Point.findOne({
|
|
14
|
+
where: { id: pointId },
|
|
15
|
+
}).then(function (point) {
|
|
16
|
+
if (point && upDown === 1) {
|
|
17
|
+
point.increment(column).then(function () {
|
|
18
|
+
next();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else if (point && upDown === -1) {
|
|
22
|
+
point.decrement(column).then(function () {
|
|
23
|
+
next();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
next();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var decrementOldPointQualityCountersIfNeeded = function (oldPointQualityValue, pointId, pointQuality, next) {
|
|
32
|
+
if (oldPointQualityValue) {
|
|
33
|
+
if (oldPointQualityValue > 0) {
|
|
34
|
+
changePointCounter(pointId, "counter_quality_up", -1, function () {
|
|
35
|
+
next();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else if (oldPointQualityValue < 0) {
|
|
39
|
+
changePointCounter(pointId, "counter_quality_down", -1, function () {
|
|
40
|
+
next();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
log.error("Strange state of pointQualities");
|
|
45
|
+
next();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
next();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var sendPointOrError = function (res, point, context, user, error, errorStatus) {
|
|
53
|
+
if (error || !point) {
|
|
54
|
+
if (errorStatus == 404) {
|
|
55
|
+
log.warn("Point Not Found", {
|
|
56
|
+
context: context,
|
|
57
|
+
point: toJson(point),
|
|
58
|
+
user: toJson(user),
|
|
59
|
+
err: error,
|
|
60
|
+
errorStatus: 404,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
log.error("Point Error", {
|
|
65
|
+
context: context,
|
|
66
|
+
point: toJson(point),
|
|
67
|
+
user: toJson(user),
|
|
68
|
+
err: error,
|
|
69
|
+
errorStatus: errorStatus ? errorStatus : 500,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (errorStatus) {
|
|
73
|
+
res.sendStatus(errorStatus);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
res.sendStatus(500);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
res.send(point);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var validateEmbedUrl = function (urlIn) {
|
|
84
|
+
var urlRegex = /((?:(http|https|Http|Https|rtsp|Rtsp):\/\/(?:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,64}(?:\:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,25})?\@)?)?((?:(?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}\.)+(?:(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])|(?:biz|b[abdefghijmnorstvwyz])|(?:cat|com|coop|c[acdfghiklmnoruvxyz])|d[ejkmoz]|(?:edu|e[cegrstu])|f[ijkmor]|(?:gov|g[abdefghilmnpqrstuwy])|h[kmnrtu]|(?:info|int|i[delmnoqrst])|(?:jobs|j[emop])|k[eghimnrwyz]|l[abcikrstuvy]|(?:mil|mobi|museum|m[acdghklmnopqrstuvwxyz])|(?:name|net|n[acefgilopruz])|(?:org|om)|(?:pro|p[aefghklmnrstwy])|qa|r[eouw]|s[abcdeghijklmnortuvyz]|(?:tel|travel|t[cdfghjklmnoprtvwz])|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]))|(?:(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])))(?:\:\d{1,5})?)(\/(?:(?:[a-zA-Z0-9\;\/\?\:\@\&\=\#\~\-\.\+\!\*\'\(\)\,\_])|(?:\%[a-fA-F0-9]{2}))*)?(?:\b|$)/gi;
|
|
85
|
+
var urls = urlRegex.exec(urlIn);
|
|
86
|
+
return urls != null && urls.length > 0;
|
|
87
|
+
};
|
|
88
|
+
var loadPointWithAll = function (pointId, callback) {
|
|
89
|
+
let outPoint;
|
|
90
|
+
models.Point.findOne({
|
|
91
|
+
where: {
|
|
92
|
+
id: pointId,
|
|
93
|
+
},
|
|
94
|
+
attributes: [
|
|
95
|
+
"id",
|
|
96
|
+
"name",
|
|
97
|
+
"content",
|
|
98
|
+
"status",
|
|
99
|
+
"value",
|
|
100
|
+
"counter_quality_up",
|
|
101
|
+
"counter_quality_down",
|
|
102
|
+
"counter_flags",
|
|
103
|
+
"embed_data",
|
|
104
|
+
"data",
|
|
105
|
+
"public_data",
|
|
106
|
+
"language",
|
|
107
|
+
"group_id",
|
|
108
|
+
"post_id",
|
|
109
|
+
"user_id",
|
|
110
|
+
],
|
|
111
|
+
order: [
|
|
112
|
+
[models.PointRevision, "created_at", "asc"],
|
|
113
|
+
[
|
|
114
|
+
models.User,
|
|
115
|
+
{ model: models.Image, as: "UserProfileImages" },
|
|
116
|
+
"created_at",
|
|
117
|
+
"asc",
|
|
118
|
+
],
|
|
119
|
+
[{ model: models.Audio, as: "PointAudios" }, "updated_at", "desc"],
|
|
120
|
+
],
|
|
121
|
+
include: [
|
|
122
|
+
{
|
|
123
|
+
model: models.User,
|
|
124
|
+
attributes: [
|
|
125
|
+
"id",
|
|
126
|
+
"name",
|
|
127
|
+
"email",
|
|
128
|
+
"facebook_id",
|
|
129
|
+
"twitter_id",
|
|
130
|
+
"google_id",
|
|
131
|
+
"github_id",
|
|
132
|
+
],
|
|
133
|
+
required: false,
|
|
134
|
+
include: [
|
|
135
|
+
{
|
|
136
|
+
model: models.Image,
|
|
137
|
+
as: "UserProfileImages",
|
|
138
|
+
required: false,
|
|
139
|
+
through: { attributes: [] }
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
model: models.PointRevision,
|
|
145
|
+
required: false,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
model: models.PointQuality,
|
|
149
|
+
required: false,
|
|
150
|
+
include: [
|
|
151
|
+
{
|
|
152
|
+
model: models.User,
|
|
153
|
+
attributes: ["id", "name", "email"],
|
|
154
|
+
required: false,
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
model: models.Audio,
|
|
160
|
+
required: false,
|
|
161
|
+
attributes: ["id", "formats", "updated_at", "listenable"],
|
|
162
|
+
as: "PointAudios",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
model: models.Post,
|
|
166
|
+
required: false,
|
|
167
|
+
attributes: ["id", "group_id"],
|
|
168
|
+
include: [
|
|
169
|
+
{
|
|
170
|
+
model: models.Group,
|
|
171
|
+
attributes: ["id", "configuration"],
|
|
172
|
+
required: false,
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
})
|
|
178
|
+
.then(function (point) {
|
|
179
|
+
if (point) {
|
|
180
|
+
outPoint = point;
|
|
181
|
+
async.parallel([
|
|
182
|
+
(parallelCallback) => {
|
|
183
|
+
models.Point.getVideosForPoints([point.id], (error, videos) => {
|
|
184
|
+
if (error) {
|
|
185
|
+
parallelCallback(error);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
outPoint.setDataValue("PointVideos", videos);
|
|
189
|
+
outPoint.PointVideos = videos;
|
|
190
|
+
parallelCallback();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
(parallelCallback) => {
|
|
195
|
+
models.Point.setOrganizationUsersForPoints([outPoint], (error) => {
|
|
196
|
+
parallelCallback(error);
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
], (error) => {
|
|
200
|
+
callback(error, outPoint);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
callback("Can't find point");
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
.catch(function (error) {
|
|
208
|
+
callback(error);
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
router.put("/:id/report", auth.can("vote on point"), function (req, res) {
|
|
212
|
+
models.Point.findOne({
|
|
213
|
+
where: {
|
|
214
|
+
id: req.params.id,
|
|
215
|
+
},
|
|
216
|
+
}).then(function (point) {
|
|
217
|
+
if (point) {
|
|
218
|
+
models.Post.findOne({
|
|
219
|
+
where: {
|
|
220
|
+
id: point.post_id,
|
|
221
|
+
},
|
|
222
|
+
include: [
|
|
223
|
+
{
|
|
224
|
+
model: models.Group,
|
|
225
|
+
required: true,
|
|
226
|
+
attributes: ["id"],
|
|
227
|
+
include: [
|
|
228
|
+
{
|
|
229
|
+
model: models.Community,
|
|
230
|
+
required: true,
|
|
231
|
+
attributes: ["id"],
|
|
232
|
+
include: [
|
|
233
|
+
{
|
|
234
|
+
model: models.Domain,
|
|
235
|
+
required: true,
|
|
236
|
+
attributes: ["id"],
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
})
|
|
244
|
+
.then(function (post) {
|
|
245
|
+
if (post) {
|
|
246
|
+
point.report(req, "user", post, function (error) {
|
|
247
|
+
if (error) {
|
|
248
|
+
log.error("Point Report Error", {
|
|
249
|
+
context: "report",
|
|
250
|
+
post: post ? toJson(post) : null,
|
|
251
|
+
user: toJson(req.user),
|
|
252
|
+
err: error,
|
|
253
|
+
});
|
|
254
|
+
res.sendStatus(500);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
log.info("Point Report Created", {
|
|
258
|
+
postId: post ? post.id : -1,
|
|
259
|
+
userId: req.user ? req.user.id : -1,
|
|
260
|
+
});
|
|
261
|
+
res.sendStatus(200);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
log.error("Point Report", {
|
|
267
|
+
context: "report",
|
|
268
|
+
post: toJson(post),
|
|
269
|
+
user: toJson(req.user),
|
|
270
|
+
err: "Could not created post",
|
|
271
|
+
});
|
|
272
|
+
res.sendStatus(500);
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
.catch(function (error) {
|
|
276
|
+
log.error("Point Report", {
|
|
277
|
+
context: "report",
|
|
278
|
+
user: toJson(req.user),
|
|
279
|
+
err: error,
|
|
280
|
+
});
|
|
281
|
+
res.sendStatus(500);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
res.sendStatus(404);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
router.get("/:parentPointId/comments", auth.can("view point"), function (req, res) {
|
|
290
|
+
models.Point.findAll({
|
|
291
|
+
where: {
|
|
292
|
+
parent_point_id: req.params.parentPointId,
|
|
293
|
+
},
|
|
294
|
+
order: [
|
|
295
|
+
["created_at", "asc"],
|
|
296
|
+
[
|
|
297
|
+
models.PointRevision,
|
|
298
|
+
models.User,
|
|
299
|
+
{ model: models.Image, as: "UserProfileImages" },
|
|
300
|
+
"created_at",
|
|
301
|
+
"asc",
|
|
302
|
+
],
|
|
303
|
+
[models.PointRevision, "created_at", "asc"],
|
|
304
|
+
],
|
|
305
|
+
include: [
|
|
306
|
+
{
|
|
307
|
+
model: models.PointRevision,
|
|
308
|
+
include: [
|
|
309
|
+
{
|
|
310
|
+
model: models.User,
|
|
311
|
+
attributes: models.User.defaultAttributesWithSocialMediaPublic,
|
|
312
|
+
include: [
|
|
313
|
+
{
|
|
314
|
+
model: models.Image,
|
|
315
|
+
as: "UserProfileImages",
|
|
316
|
+
required: false,
|
|
317
|
+
through: { attributes: [] }
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
})
|
|
325
|
+
.then(function (comments) {
|
|
326
|
+
log.info("Point Comment for Parent Point", {
|
|
327
|
+
context: "comment",
|
|
328
|
+
user: req.user ? toJson(req.user.simple()) : null,
|
|
329
|
+
});
|
|
330
|
+
res.send(comments);
|
|
331
|
+
})
|
|
332
|
+
.catch(function (error) {
|
|
333
|
+
log.error("Could not get comments for parent point", {
|
|
334
|
+
err: error,
|
|
335
|
+
context: "comment",
|
|
336
|
+
user: req.user ? toJson(req.user.simple()) : null,
|
|
337
|
+
});
|
|
338
|
+
res.sendStatus(500);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
router.get("/:parentPointId/commentsCount", auth.can("view point"), function (req, res) {
|
|
342
|
+
models.Point.count({
|
|
343
|
+
where: {
|
|
344
|
+
parent_point_id: req.params.parentPointId,
|
|
345
|
+
},
|
|
346
|
+
include: [
|
|
347
|
+
{
|
|
348
|
+
model: models.PointRevision,
|
|
349
|
+
include: [
|
|
350
|
+
{
|
|
351
|
+
model: models.User,
|
|
352
|
+
attributes: ["id", "name", "created_at"],
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
order: [["created_at", "asc"]],
|
|
358
|
+
})
|
|
359
|
+
.then(function (commentsCount) {
|
|
360
|
+
log.info("Point Comment Count for Parent Point", {
|
|
361
|
+
context: "comment",
|
|
362
|
+
user: req.user ? toJson(req.user.simple()) : null,
|
|
363
|
+
});
|
|
364
|
+
res.send({ count: commentsCount });
|
|
365
|
+
})
|
|
366
|
+
.catch(function (error) {
|
|
367
|
+
log.error("Could not get comments count for parent point", {
|
|
368
|
+
err: error,
|
|
369
|
+
context: "comment",
|
|
370
|
+
user: req.user ? toJson(req.user.simple()) : null,
|
|
371
|
+
});
|
|
372
|
+
res.sendStatus(500);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
router.post("/:parentPointId/comment", auth.isLoggedInNoAnonymousCheck, auth.can("add to point"), function (req, res) {
|
|
376
|
+
models.Point.createComment(req, { parent_point_id: req.params.parentPointId, comment: req.body.comment }, function (error) {
|
|
377
|
+
if (error) {
|
|
378
|
+
log.error("Could not save comment point on parent point", {
|
|
379
|
+
err: error,
|
|
380
|
+
context: "comment",
|
|
381
|
+
user: toJson(req.user.simple()),
|
|
382
|
+
});
|
|
383
|
+
res.sendStatus(500);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
log.info("Point Comment Created on Parent Point", {
|
|
387
|
+
context: "news_story",
|
|
388
|
+
user: toJson(req.user.simple()),
|
|
389
|
+
});
|
|
390
|
+
res.sendStatus(200);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
router.put("/:pointId", auth.can("edit point"), function (req, res) {
|
|
395
|
+
if (!req.body.content) {
|
|
396
|
+
req.body.content = "";
|
|
397
|
+
}
|
|
398
|
+
var point = models.Point.findOne({
|
|
399
|
+
where: {
|
|
400
|
+
id: req.params.pointId,
|
|
401
|
+
},
|
|
402
|
+
})
|
|
403
|
+
.then(function (point) {
|
|
404
|
+
var maxNumberOfPointsBeforeEditFrozen = 5;
|
|
405
|
+
if (point.counter_quality_up + point.counter_quality_down <=
|
|
406
|
+
maxNumberOfPointsBeforeEditFrozen) {
|
|
407
|
+
var pointRevision = models.PointRevision.build({
|
|
408
|
+
group_id: point.group_id,
|
|
409
|
+
post_id: point.post_id,
|
|
410
|
+
content: req.body.content,
|
|
411
|
+
user_id: req.user.id,
|
|
412
|
+
status: point.status,
|
|
413
|
+
value: point.value,
|
|
414
|
+
point_id: point.id,
|
|
415
|
+
user_agent: req.useragent.source,
|
|
416
|
+
ip_address: req.clientIp,
|
|
417
|
+
});
|
|
418
|
+
pointRevision.save().then(function () {
|
|
419
|
+
log.info("PointRevision Created", {
|
|
420
|
+
pointRevisionId: pointRevision ? pointRevision.id : -1,
|
|
421
|
+
context: "create",
|
|
422
|
+
userId: req.user ? req.user.id : -1,
|
|
423
|
+
});
|
|
424
|
+
queue.add("process-similarities", { type: "update-collection", pointId: point.id }, "low");
|
|
425
|
+
models.AcActivity.createActivity({
|
|
426
|
+
type: "activity.point.edited",
|
|
427
|
+
userId: point.user_id,
|
|
428
|
+
domainId: req.ypDomain.id,
|
|
429
|
+
// communityId: req.ypCommunity ? req.ypCommunity.id : null,
|
|
430
|
+
groupId: point.group_id,
|
|
431
|
+
postId: point.post_id,
|
|
432
|
+
pointId: point.id,
|
|
433
|
+
access: models.AcActivity.ACCESS_PUBLIC,
|
|
434
|
+
}, function (error) {
|
|
435
|
+
loadPointWithAll(point.id, function (error, loadedPoint) {
|
|
436
|
+
if (error) {
|
|
437
|
+
log.error("Could not reload point point", {
|
|
438
|
+
err: error,
|
|
439
|
+
context: "createPoint",
|
|
440
|
+
user: toJson(req.user.simple()),
|
|
441
|
+
});
|
|
442
|
+
res.sendStatus(500);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
if (loadedPoint.PointRevisions &&
|
|
446
|
+
loadedPoint.PointRevisions.length > 0 &&
|
|
447
|
+
loadedPoint.PointRevisions[loadedPoint.PointRevisions.length - 1].content !== "") {
|
|
448
|
+
log.info("process-moderation point toxicity after create point");
|
|
449
|
+
queue.add("process-moderation", {
|
|
450
|
+
type: "estimate-point-toxicity",
|
|
451
|
+
pointId: loadedPoint.id,
|
|
452
|
+
}, "high");
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
log.info("No process-moderation toxicity for empty text on point");
|
|
456
|
+
}
|
|
457
|
+
res.send(loadedPoint);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
log.error("Trying to edit point with too many point qualities", {
|
|
465
|
+
point: toJson(point),
|
|
466
|
+
context: "edit",
|
|
467
|
+
user: toJson(req.user),
|
|
468
|
+
});
|
|
469
|
+
res.sendStatus(401);
|
|
470
|
+
}
|
|
471
|
+
})
|
|
472
|
+
.catch(function (error) {
|
|
473
|
+
sendPointOrError(res, null, "edit", req.user, error);
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
router.get("/:id/translatedText", auth.can("view point"), function (req, res) {
|
|
477
|
+
if (req.query.textType.indexOf("point") > -1) {
|
|
478
|
+
models.Point.findOne({
|
|
479
|
+
where: {
|
|
480
|
+
id: req.params.id,
|
|
481
|
+
},
|
|
482
|
+
order: [[models.PointRevision, "created_at", "asc"]],
|
|
483
|
+
attributes: ["id", "public_data"],
|
|
484
|
+
include: [
|
|
485
|
+
{
|
|
486
|
+
model: models.PointRevision,
|
|
487
|
+
attributes: ["id", "content"],
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
})
|
|
491
|
+
.then(function (point) {
|
|
492
|
+
if (point) {
|
|
493
|
+
models.AcTranslationCache.getTranslation(req, point, function (error, translation) {
|
|
494
|
+
if (error) {
|
|
495
|
+
sendPointOrError(res, req.params.id, "translated", req.user, error, 500);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
res.send(translation);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
sendPointOrError(res, req.params.id, "translated", req.user, "Not found", 404);
|
|
504
|
+
}
|
|
505
|
+
})
|
|
506
|
+
.catch(function (error) {
|
|
507
|
+
sendPointOrError(res, null, "translated", req.user, error);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
sendPointOrError(res, req.params.id, "translated", req.user, "Wrong textType", 401);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
router.get("/:id/videoTranscriptStatus", auth.can("view point"), function (req, res) {
|
|
515
|
+
loadPointWithAll(req.params.id, (error, point) => {
|
|
516
|
+
if (error) {
|
|
517
|
+
sendPointOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
|
|
518
|
+
}
|
|
519
|
+
else if (point.PointVideos && point.PointVideos.length > 0) {
|
|
520
|
+
models.Video.findOne({
|
|
521
|
+
where: {
|
|
522
|
+
id: point.PointVideos[0].id,
|
|
523
|
+
},
|
|
524
|
+
})
|
|
525
|
+
.then((video) => {
|
|
526
|
+
if (video.meta.transcript && video.meta.transcript.text) {
|
|
527
|
+
point
|
|
528
|
+
.save()
|
|
529
|
+
.then((savedPoint) => {
|
|
530
|
+
var pointRevision = models.PointRevision.build({
|
|
531
|
+
group_id: savedPoint.group_id,
|
|
532
|
+
post_id: savedPoint.post_id,
|
|
533
|
+
content: video.meta.transcript.text,
|
|
534
|
+
user_id: req.user.id,
|
|
535
|
+
status: savedPoint.status,
|
|
536
|
+
value: savedPoint.value,
|
|
537
|
+
point_id: savedPoint.id,
|
|
538
|
+
user_agent: req.useragent.source,
|
|
539
|
+
ip_address: req.clientIp,
|
|
540
|
+
});
|
|
541
|
+
pointRevision
|
|
542
|
+
.save()
|
|
543
|
+
.then(() => {
|
|
544
|
+
loadPointWithAll(point.id, function (error, loadedPoint) {
|
|
545
|
+
if (error) {
|
|
546
|
+
log.error("Could not reload point point", {
|
|
547
|
+
err: error,
|
|
548
|
+
context: "createPoint",
|
|
549
|
+
user: toJson(req.user.simple()),
|
|
550
|
+
});
|
|
551
|
+
res.sendStatus(500);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
log.info("process-moderation point toxicity after video transcript");
|
|
555
|
+
queue.add("process-moderation", {
|
|
556
|
+
type: "estimate-point-toxicity",
|
|
557
|
+
pointId: loadedPoint.id,
|
|
558
|
+
}, "high");
|
|
559
|
+
res.send({ point: loadedPoint });
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
})
|
|
563
|
+
.catch((error) => {
|
|
564
|
+
sendPointOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
|
|
565
|
+
});
|
|
566
|
+
})
|
|
567
|
+
.catch((error) => {
|
|
568
|
+
sendPointOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
else if (video.meta.transcript && video.meta.transcript.error) {
|
|
572
|
+
res.send({ error: video.meta.transcript.error });
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
res.send({ inProgress: true });
|
|
576
|
+
}
|
|
577
|
+
})
|
|
578
|
+
.catch((error) => {
|
|
579
|
+
sendPointOrError(res, req.params.id, "videoTranscriptStatus", req.user, error, 500);
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
sendPointOrError(res, req.params.id, "videoTranscriptStatus", req.user, "No video for videoTranscriptStatus", 500);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
router.get("/:id/audioTranscriptStatus", auth.can("view point"), function (req, res) {
|
|
588
|
+
loadPointWithAll(req.params.id, (error, point) => {
|
|
589
|
+
if (error) {
|
|
590
|
+
sendPointOrError(res, req.params.id, "audioTranscriptStatus", req.user, error, 500);
|
|
591
|
+
}
|
|
592
|
+
else if (point.PointAudios && point.PointAudios.length > 0) {
|
|
593
|
+
models.Audio.findOne({
|
|
594
|
+
where: {
|
|
595
|
+
id: point.PointAudios[0].id,
|
|
596
|
+
},
|
|
597
|
+
})
|
|
598
|
+
.then((audio) => {
|
|
599
|
+
if (audio.meta.transcript && audio.meta.transcript.text) {
|
|
600
|
+
point
|
|
601
|
+
.save()
|
|
602
|
+
.then((savedPoint) => {
|
|
603
|
+
var pointRevision = models.PointRevision.build({
|
|
604
|
+
group_id: savedPoint.group_id,
|
|
605
|
+
post_id: savedPoint.post_id,
|
|
606
|
+
content: audio.meta.transcript.text,
|
|
607
|
+
user_id: req.user.id,
|
|
608
|
+
status: savedPoint.status,
|
|
609
|
+
value: savedPoint.value,
|
|
610
|
+
point_id: savedPoint.id,
|
|
611
|
+
user_agent: req.useragent.source,
|
|
612
|
+
ip_address: req.clientIp,
|
|
613
|
+
});
|
|
614
|
+
pointRevision
|
|
615
|
+
.save()
|
|
616
|
+
.then(() => {
|
|
617
|
+
loadPointWithAll(point.id, function (error, loadedPoint) {
|
|
618
|
+
if (error) {
|
|
619
|
+
log.error("Could not reload point", {
|
|
620
|
+
err: error,
|
|
621
|
+
context: "createPoint",
|
|
622
|
+
user: toJson(req.user.simple()),
|
|
623
|
+
});
|
|
624
|
+
res.sendStatus(500);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
log.info("process-moderation point toxicity after audio transcript");
|
|
628
|
+
queue.add("process-moderation", {
|
|
629
|
+
type: "estimate-point-toxicity",
|
|
630
|
+
pointId: loadedPoint.id,
|
|
631
|
+
}, "high");
|
|
632
|
+
res.send({ point: loadedPoint });
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
})
|
|
636
|
+
.catch((error) => {
|
|
637
|
+
sendPointOrError(res, req.params.id, "audioTranscriptStatus", req.user, error, 500);
|
|
638
|
+
});
|
|
639
|
+
})
|
|
640
|
+
.catch((error) => {
|
|
641
|
+
sendPointOrError(res, req.params.id, "audioTranscriptStatus", req.user, error, 500);
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
else if (audio.meta.transcript && audio.meta.transcript.error) {
|
|
645
|
+
res.send({ error: audio.meta.transcript.error });
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
res.send({ inProgress: true });
|
|
649
|
+
}
|
|
650
|
+
})
|
|
651
|
+
.catch((error) => {
|
|
652
|
+
sendPointOrError(res, req.params.id, "audioTranscriptStatus", req.user, error, 500);
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
sendPointOrError(res, req.params.id, "audioTranscriptStatus", req.user, "No audio for audioTranscriptStatus", 500);
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
router.post("/:groupId", auth.can("create point"), function (req, res) {
|
|
661
|
+
log.info("In POST createPoint");
|
|
662
|
+
if (!req.body.content) {
|
|
663
|
+
req.body.content = "";
|
|
664
|
+
}
|
|
665
|
+
var point = models.Point.build({
|
|
666
|
+
group_id: req.params.groupId,
|
|
667
|
+
post_id: req.body.postId,
|
|
668
|
+
content: req.body.content,
|
|
669
|
+
value: req.body.value,
|
|
670
|
+
user_id: req.user.id,
|
|
671
|
+
status: "published",
|
|
672
|
+
user_agent: req.useragent.source,
|
|
673
|
+
ip_address: req.clientIp,
|
|
674
|
+
data: {
|
|
675
|
+
browserId: req.body.pointBaseId,
|
|
676
|
+
browserFingerprint: req.body.pointValCode,
|
|
677
|
+
browserFingerprintConfidence: req.body.pointConf,
|
|
678
|
+
originalQueryString: req.body.originalQueryString,
|
|
679
|
+
userLocale: req.body.userLocale,
|
|
680
|
+
userAutoTranslate: req.body.userAutoTranslate,
|
|
681
|
+
referrer: req.body.referrer,
|
|
682
|
+
url: req.body.url,
|
|
683
|
+
screen_width: req.body.screen_width,
|
|
684
|
+
},
|
|
685
|
+
});
|
|
686
|
+
point
|
|
687
|
+
.save()
|
|
688
|
+
.then(function () {
|
|
689
|
+
log.info("Point Created", {
|
|
690
|
+
pointId: point ? point.id : -1,
|
|
691
|
+
context: "create",
|
|
692
|
+
userId: req.user ? req.user.id : -1,
|
|
693
|
+
});
|
|
694
|
+
async.parallel([
|
|
695
|
+
(parallelCallback) => {
|
|
696
|
+
var pointRevision = models.PointRevision.build({
|
|
697
|
+
group_id: point.group_id,
|
|
698
|
+
post_id: point.post_id,
|
|
699
|
+
content: point.content,
|
|
700
|
+
user_id: req.user.id,
|
|
701
|
+
status: point.status,
|
|
702
|
+
value: point.value,
|
|
703
|
+
point_id: point.id,
|
|
704
|
+
user_agent: req.useragent.source,
|
|
705
|
+
ip_address: req.clientIp,
|
|
706
|
+
});
|
|
707
|
+
pointRevision.save().then(function () {
|
|
708
|
+
log.info("PointRevision Created", {
|
|
709
|
+
pointRevisionId: pointRevision ? pointRevision.id : -1,
|
|
710
|
+
context: "create",
|
|
711
|
+
userId: req.user ? req.user.id : -1,
|
|
712
|
+
});
|
|
713
|
+
parallelCallback();
|
|
714
|
+
});
|
|
715
|
+
},
|
|
716
|
+
(parallelCallback) => {
|
|
717
|
+
models.AcActivity.createActivity({
|
|
718
|
+
type: "activity.point.new",
|
|
719
|
+
userId: point.user_id,
|
|
720
|
+
domainId: req.ypDomain.id,
|
|
721
|
+
// communityId: req.ypCommunity ? req.ypCommunity.id : null,
|
|
722
|
+
groupId: point.group_id,
|
|
723
|
+
postId: point.post_id,
|
|
724
|
+
pointId: point.id,
|
|
725
|
+
access: models.AcActivity.ACCESS_PUBLIC,
|
|
726
|
+
}, function (error) {
|
|
727
|
+
parallelCallback(error);
|
|
728
|
+
});
|
|
729
|
+
},
|
|
730
|
+
(parallelCallback) => {
|
|
731
|
+
models.Group.addUserToGroupIfNeeded(point.group_id, req, function () {
|
|
732
|
+
parallelCallback();
|
|
733
|
+
});
|
|
734
|
+
},
|
|
735
|
+
(parallelCallback) => {
|
|
736
|
+
models.Post.findOne({
|
|
737
|
+
where: { id: point.post_id },
|
|
738
|
+
attributes: ["id", "counter_points", "group_id"],
|
|
739
|
+
}).then(function (post) {
|
|
740
|
+
if (post) {
|
|
741
|
+
post.updateAllExternalCounters(req, "up", "counter_points", function () {
|
|
742
|
+
post.increment("counter_points");
|
|
743
|
+
parallelCallback();
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
parallelCallback("Post not found for point");
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
},
|
|
751
|
+
(parallelCallback) => {
|
|
752
|
+
if (req.body.videoId) {
|
|
753
|
+
models.Video.completeUploadAndAddToPoint(req, res, { pointId: point.id, videoId: req.body.videoId }, (error) => {
|
|
754
|
+
if (error) {
|
|
755
|
+
parallelCallback(error);
|
|
756
|
+
}
|
|
757
|
+
else {
|
|
758
|
+
if (process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON) {
|
|
759
|
+
const workPackage = {
|
|
760
|
+
browserLanguage: req.headers["accept-language"]
|
|
761
|
+
? req.headers["accept-language"].split(",")[0]
|
|
762
|
+
: "en-US",
|
|
763
|
+
appLanguage: req.body.appLanguage,
|
|
764
|
+
videoId: req.body.videoId,
|
|
765
|
+
type: "create-video-transcript",
|
|
766
|
+
};
|
|
767
|
+
queue.add("process-voice-to-text", workPackage, "high");
|
|
768
|
+
}
|
|
769
|
+
parallelCallback();
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
parallelCallback();
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
(parallelCallback) => {
|
|
778
|
+
if (req.body.audioId) {
|
|
779
|
+
models.Audio.completeUploadAndAddToPoint(req, res, { pointId: point.id, audioId: req.body.audioId }, (error) => {
|
|
780
|
+
if (error) {
|
|
781
|
+
parallelCallback(error);
|
|
782
|
+
}
|
|
783
|
+
else {
|
|
784
|
+
if (process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON) {
|
|
785
|
+
const workPackage = {
|
|
786
|
+
browserLanguage: req.headers["accept-language"]
|
|
787
|
+
? req.headers["accept-language"].split(",")[0]
|
|
788
|
+
: "en-US",
|
|
789
|
+
appLanguage: req.body.appLanguage,
|
|
790
|
+
audioId: req.body.audioId,
|
|
791
|
+
type: "create-audio-transcript",
|
|
792
|
+
};
|
|
793
|
+
queue.add("process-voice-to-text", workPackage, "high");
|
|
794
|
+
}
|
|
795
|
+
parallelCallback();
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
parallelCallback();
|
|
801
|
+
}
|
|
802
|
+
},
|
|
803
|
+
], (error) => {
|
|
804
|
+
if (error) {
|
|
805
|
+
log.error(error);
|
|
806
|
+
res.sendStatus(500);
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
if (point.content && point.content !== "") {
|
|
810
|
+
log.info("process-moderation point toxicity after create point");
|
|
811
|
+
queue.add("process-moderation", { type: "estimate-point-toxicity", pointId: point.id }, "high");
|
|
812
|
+
queue.add("process-similarities", { type: "update-collection", pointId: point.id }, "low");
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
log.info("No process-moderation toxicity for empty text on point");
|
|
816
|
+
}
|
|
817
|
+
queue.add("process-moderation", { type: "point-review-and-annotate-images", pointId: point.id }, "medium");
|
|
818
|
+
loadPointWithAll(point.id, function (error, loadedPoint) {
|
|
819
|
+
if (error) {
|
|
820
|
+
log.error("Could not reload point point", {
|
|
821
|
+
err: error,
|
|
822
|
+
context: "createPoint",
|
|
823
|
+
user: toJson(req.user.simple()),
|
|
824
|
+
});
|
|
825
|
+
res.sendStatus(500);
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
const newPointRedisKey = `newUserPoint_${req.user.id}`;
|
|
829
|
+
req.redisClient.setEx(newPointRedisKey, 30, JSON.stringify({}));
|
|
830
|
+
res.send(loadedPoint);
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
})
|
|
836
|
+
.catch(function (error) {
|
|
837
|
+
sendPointOrError(res, null, "create", req.user, error);
|
|
838
|
+
});
|
|
839
|
+
});
|
|
840
|
+
router.delete("/:id", auth.can("delete point"), function (req, res) {
|
|
841
|
+
models.Point.findOne({
|
|
842
|
+
where: { id: req.params.id },
|
|
843
|
+
include: [
|
|
844
|
+
{
|
|
845
|
+
model: models.Post,
|
|
846
|
+
required: false,
|
|
847
|
+
},
|
|
848
|
+
],
|
|
849
|
+
})
|
|
850
|
+
.then(function (point) {
|
|
851
|
+
point.deleted = true;
|
|
852
|
+
point.save().then(function () {
|
|
853
|
+
log.info("Point Deleted", {
|
|
854
|
+
point: toJson(point),
|
|
855
|
+
context: "delete",
|
|
856
|
+
user: toJson(req.user),
|
|
857
|
+
});
|
|
858
|
+
queue.add("process-similarities", { type: "update-collection", pointId: point.id }, "low");
|
|
859
|
+
queue.add("process-deletion", {
|
|
860
|
+
type: "delete-point-content",
|
|
861
|
+
pointId: point.id,
|
|
862
|
+
userId: req.user.id,
|
|
863
|
+
}, "critical");
|
|
864
|
+
if (point.Post) {
|
|
865
|
+
point.Post.updateAllExternalCounters(req, "down", "counter_points", function () {
|
|
866
|
+
point.Post.decrement("counter_points");
|
|
867
|
+
res.sendStatus(200);
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
res.sendStatus(200);
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
})
|
|
875
|
+
.catch(function (error) {
|
|
876
|
+
sendPointOrError(res, null, "delete", req.user, error);
|
|
877
|
+
});
|
|
878
|
+
});
|
|
879
|
+
router.post("/:id/pointQuality", auth.can("vote on point"), function (req, res) {
|
|
880
|
+
var point, post;
|
|
881
|
+
models.PointQuality.findOne({
|
|
882
|
+
where: { point_id: req.params.id, user_id: req.user.id },
|
|
883
|
+
include: [
|
|
884
|
+
{
|
|
885
|
+
model: models.Point,
|
|
886
|
+
attributes: ["id", "group_id", "post_id"],
|
|
887
|
+
include: [
|
|
888
|
+
{
|
|
889
|
+
model: models.Post,
|
|
890
|
+
attributes: ["id", "group_id"],
|
|
891
|
+
required: false,
|
|
892
|
+
},
|
|
893
|
+
],
|
|
894
|
+
},
|
|
895
|
+
],
|
|
896
|
+
}).then(function (pointQuality) {
|
|
897
|
+
var oldPointQualityValue;
|
|
898
|
+
if (pointQuality) {
|
|
899
|
+
point = pointQuality.Point;
|
|
900
|
+
if (pointQuality.value > 0)
|
|
901
|
+
oldPointQualityValue = 1;
|
|
902
|
+
else if (pointQuality.value < 0)
|
|
903
|
+
oldPointQualityValue = -1;
|
|
904
|
+
pointQuality.value = req.body.value;
|
|
905
|
+
pointQuality.status = "active";
|
|
906
|
+
pointQuality.set("data", {
|
|
907
|
+
browserId: req.body.qualityBaseId,
|
|
908
|
+
browserFingerprint: req.body.qualityValCode,
|
|
909
|
+
browserFingerprintConfidence: req.body.qualityConf,
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
else {
|
|
913
|
+
pointQuality = models.PointQuality.build({
|
|
914
|
+
point_id: req.params.id,
|
|
915
|
+
value: req.body.value,
|
|
916
|
+
user_id: req.user.id,
|
|
917
|
+
data: {
|
|
918
|
+
browserId: req.body.qualityBaseId,
|
|
919
|
+
browserFingerprint: req.body.qualityValCode,
|
|
920
|
+
browserFingerprintConfidence: req.body.qualityConf,
|
|
921
|
+
},
|
|
922
|
+
status: "active",
|
|
923
|
+
user_agent: req.useragent.source,
|
|
924
|
+
ip_address: req.clientIp,
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
pointQuality.save().then(function () {
|
|
928
|
+
log.info("PointQuality Created or Updated", {
|
|
929
|
+
pointQualityId: pointQuality ? pointQuality.id : -1,
|
|
930
|
+
userId: req.user ? req.user.id : -1,
|
|
931
|
+
});
|
|
932
|
+
async.series([
|
|
933
|
+
function (seriesCallback) {
|
|
934
|
+
if (point) {
|
|
935
|
+
seriesCallback();
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
models.Point.findOne({
|
|
939
|
+
where: { id: pointQuality.point_id },
|
|
940
|
+
attributes: ["id", "post_id", "group_id"],
|
|
941
|
+
}).then(function (results) {
|
|
942
|
+
if (results) {
|
|
943
|
+
point = results;
|
|
944
|
+
seriesCallback();
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
seriesCallback("Can't find point");
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
},
|
|
952
|
+
function (seriesCallback) {
|
|
953
|
+
models.AcActivity.createActivity({
|
|
954
|
+
type: pointQuality.value > 0
|
|
955
|
+
? "activity.point.helpful.new"
|
|
956
|
+
: "activity.point.unhelpful.new",
|
|
957
|
+
userId: pointQuality.user_id,
|
|
958
|
+
domainId: req.ypDomain.id,
|
|
959
|
+
// communityId: req.ypCommunity ? req.ypCommunity.id : null,
|
|
960
|
+
pointQualityId: pointQuality.id,
|
|
961
|
+
groupId: point.group_id,
|
|
962
|
+
postId: point.post_id,
|
|
963
|
+
pointId: point.id,
|
|
964
|
+
access: models.AcActivity.ACCESS_PUBLIC,
|
|
965
|
+
}, function (error) {
|
|
966
|
+
seriesCallback(error);
|
|
967
|
+
});
|
|
968
|
+
},
|
|
969
|
+
function (seriesCallback) {
|
|
970
|
+
if (point && point.group_id) {
|
|
971
|
+
models.Group.addUserToGroupIfNeeded(point.group_id, req, function () {
|
|
972
|
+
seriesCallback();
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
else {
|
|
976
|
+
seriesCallback();
|
|
977
|
+
}
|
|
978
|
+
},
|
|
979
|
+
], function (error) {
|
|
980
|
+
if (error) {
|
|
981
|
+
log.error("Point Quality Error", {
|
|
982
|
+
context: "create",
|
|
983
|
+
pointQuality: toJson(pointQuality),
|
|
984
|
+
user: toJson(req.user),
|
|
985
|
+
err: error,
|
|
986
|
+
errorStatus: 500,
|
|
987
|
+
});
|
|
988
|
+
res.sendStatus(500);
|
|
989
|
+
}
|
|
990
|
+
else {
|
|
991
|
+
decrementOldPointQualityCountersIfNeeded(oldPointQualityValue, req.params.id, pointQuality, function () {
|
|
992
|
+
if (pointQuality.value > 0) {
|
|
993
|
+
changePointCounter(req.params.id, "counter_quality_up", 1, function () {
|
|
994
|
+
res.send({
|
|
995
|
+
pointQuality: pointQuality,
|
|
996
|
+
oldPointQualityValue: oldPointQualityValue,
|
|
997
|
+
});
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
else if (pointQuality.value < 0) {
|
|
1001
|
+
changePointCounter(req.params.id, "counter_quality_down", 1, function () {
|
|
1002
|
+
res.send({
|
|
1003
|
+
pointQuality: pointQuality,
|
|
1004
|
+
oldPointQualityValue: oldPointQualityValue,
|
|
1005
|
+
});
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
else {
|
|
1009
|
+
log.error("PointQuality Error", {
|
|
1010
|
+
pointQuality: toJson(pointQuality),
|
|
1011
|
+
context: "createOrUpdate",
|
|
1012
|
+
user: toJson(req.user),
|
|
1013
|
+
});
|
|
1014
|
+
res.status(500);
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
});
|
|
1020
|
+
});
|
|
1021
|
+
});
|
|
1022
|
+
router.delete("/:id/pointQuality", auth.can("vote on point"), function (req, res) {
|
|
1023
|
+
models.PointQuality.findOne({
|
|
1024
|
+
where: { point_id: req.params.id, user_id: req.user.id },
|
|
1025
|
+
}).then(function (pointQuality) {
|
|
1026
|
+
if (pointQuality) {
|
|
1027
|
+
var oldPointQualityValue;
|
|
1028
|
+
if (pointQuality.value > 0)
|
|
1029
|
+
oldPointQualityValue = 1;
|
|
1030
|
+
else if (pointQuality.value < 0)
|
|
1031
|
+
oldPointQualityValue = -1;
|
|
1032
|
+
pointQuality.value = 0;
|
|
1033
|
+
//pointQuality.deleted = true;
|
|
1034
|
+
pointQuality.save().then(function () {
|
|
1035
|
+
log.info("PointQuality Deleted", {
|
|
1036
|
+
pointQualityId: pointQuality ? pointQuality.id : -1,
|
|
1037
|
+
userId: req.user ? req.user.id : -1,
|
|
1038
|
+
});
|
|
1039
|
+
if (oldPointQualityValue > 0) {
|
|
1040
|
+
changePointCounter(req.params.id, "counter_quality_up", -1, function () {
|
|
1041
|
+
res.status(200).send({
|
|
1042
|
+
pointQuality: pointQuality,
|
|
1043
|
+
oldPointQualityValue: oldPointQualityValue,
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
else if (oldPointQualityValue < 0) {
|
|
1048
|
+
changePointCounter(req.params.id, "counter_quality_down", -1, function () {
|
|
1049
|
+
res.status(200).send({
|
|
1050
|
+
pointQuality: pointQuality,
|
|
1051
|
+
oldPointQualityValue: oldPointQualityValue,
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
else {
|
|
1056
|
+
console.error("Strange state of pointQualities");
|
|
1057
|
+
res.status(200).send({
|
|
1058
|
+
pointQuality: pointQuality,
|
|
1059
|
+
oldPointQualityValue: oldPointQualityValue,
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
else {
|
|
1065
|
+
log.error("PointQuality Not Found", {
|
|
1066
|
+
pointQuality: toJson(pointQuality),
|
|
1067
|
+
context: "delete",
|
|
1068
|
+
user: toJson(req.user),
|
|
1069
|
+
});
|
|
1070
|
+
res.sendStatus(404);
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
});
|
|
1074
|
+
const translateToObsFormat = (json) => {
|
|
1075
|
+
return [
|
|
1076
|
+
{
|
|
1077
|
+
url: json.ogUrl,
|
|
1078
|
+
type: json.ogType,
|
|
1079
|
+
title: json.ogTitle,
|
|
1080
|
+
version: "1.0",
|
|
1081
|
+
description: json.ogDescription,
|
|
1082
|
+
provider_url: json.ogUrl,
|
|
1083
|
+
request_url: json.requestUrl,
|
|
1084
|
+
provider_name: json.ogSiteName,
|
|
1085
|
+
thumbnail_url: json.ogImage ? json.ogImage[0].url : "",
|
|
1086
|
+
thumbnail_width: json.ogImage ? json.ogImage[0].width : "",
|
|
1087
|
+
thumbnail_height: json.ogImage ? json.ogImage[0].height : "",
|
|
1088
|
+
},
|
|
1089
|
+
];
|
|
1090
|
+
};
|
|
1091
|
+
router.get("/url_preview", auth.isLoggedInNoAnonymousCheck, function (req, res) {
|
|
1092
|
+
if (req.query.url && validateEmbedUrl(req.query.url)) {
|
|
1093
|
+
log.info("Before ogs", { url: req.query.url });
|
|
1094
|
+
const userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36";
|
|
1095
|
+
ogs({
|
|
1096
|
+
url: req.query.url,
|
|
1097
|
+
fetchOptions: { headers: { "user-agent": userAgent } },
|
|
1098
|
+
}).then((data) => {
|
|
1099
|
+
const { error, html, result, response } = data;
|
|
1100
|
+
log.info("After ogs", { url: req.query.url });
|
|
1101
|
+
if (error && result && result.error === "Page not found") {
|
|
1102
|
+
res.sendStatus(404);
|
|
1103
|
+
}
|
|
1104
|
+
else if (error) {
|
|
1105
|
+
log.error("Open graph not working", {
|
|
1106
|
+
err: error,
|
|
1107
|
+
url: req.query.url,
|
|
1108
|
+
context: "url_preview"
|
|
1109
|
+
});
|
|
1110
|
+
res.sendStatus(500);
|
|
1111
|
+
}
|
|
1112
|
+
else {
|
|
1113
|
+
log.info("Before translateToObsFormat", {
|
|
1114
|
+
url: req.query.url,
|
|
1115
|
+
result: result,
|
|
1116
|
+
});
|
|
1117
|
+
res.send(translateToObsFormat(result));
|
|
1118
|
+
}
|
|
1119
|
+
}).catch((error) => {
|
|
1120
|
+
log.error("Open graph not working", {
|
|
1121
|
+
err: error,
|
|
1122
|
+
url: req.query.url,
|
|
1123
|
+
context: "url_preview"
|
|
1124
|
+
});
|
|
1125
|
+
res.send([{}]);
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
else {
|
|
1129
|
+
log.error("Url not found or not valid", {
|
|
1130
|
+
url: req.params.url,
|
|
1131
|
+
context: "url_preview",
|
|
1132
|
+
user: toJson(req.user),
|
|
1133
|
+
});
|
|
1134
|
+
res.sendStatus(404);
|
|
1135
|
+
}
|
|
1136
|
+
});
|
|
1137
|
+
module.exports = router;
|