@openpeepshq/core 0.1.31
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/LICENSE +674 -0
- package/dist/accessTokens/finders.d.ts +11 -0
- package/dist/accessTokens/finders.js +43 -0
- package/dist/accessTokens/helpers.d.ts +13 -0
- package/dist/accessTokens/helpers.js +15 -0
- package/dist/accessTokens/index.d.ts +4 -0
- package/dist/accessTokens/index.js +4 -0
- package/dist/accessTokens/mapping.d.ts +10 -0
- package/dist/accessTokens/mapping.js +25 -0
- package/dist/accessTokens/mutations.d.ts +4 -0
- package/dist/accessTokens/mutations.js +24 -0
- package/dist/accessTokens/revokations.d.ts +2 -0
- package/dist/accessTokens/revokations.js +18 -0
- package/dist/accessTokens/tokens.d.ts +31 -0
- package/dist/accessTokens/tokens.js +174 -0
- package/dist/accounts/cache.d.ts +3 -0
- package/dist/accounts/cache.js +13 -0
- package/dist/accounts/finders.d.ts +6 -0
- package/dist/accounts/finders.js +17 -0
- package/dist/accounts/helpers.d.ts +7 -0
- package/dist/accounts/helpers.js +36 -0
- package/dist/accounts/index.d.ts +6 -0
- package/dist/accounts/index.js +6 -0
- package/dist/accounts/mapping.d.ts +10 -0
- package/dist/accounts/mapping.js +28 -0
- package/dist/accounts/mutations.d.ts +21 -0
- package/dist/accounts/mutations.js +204 -0
- package/dist/analytics/cache.d.ts +6 -0
- package/dist/analytics/cache.js +29 -0
- package/dist/analytics/compile.d.ts +4 -0
- package/dist/analytics/compile.js +296 -0
- package/dist/analytics/dateRange.d.ts +39 -0
- package/dist/analytics/dateRange.js +181 -0
- package/dist/analytics/index.d.ts +8 -0
- package/dist/analytics/index.js +8 -0
- package/dist/analytics/jobs.d.ts +20 -0
- package/dist/analytics/jobs.js +84 -0
- package/dist/analytics/metrics.d.ts +4 -0
- package/dist/analytics/metrics.js +13 -0
- package/dist/analytics/pdfReport.d.ts +8 -0
- package/dist/analytics/pdfReport.js +821 -0
- package/dist/analytics/read.d.ts +6 -0
- package/dist/analytics/read.js +696 -0
- package/dist/analytics/report.d.ts +293 -0
- package/dist/analytics/report.js +153 -0
- package/dist/analytics/settings.d.ts +3 -0
- package/dist/analytics/settings.js +37 -0
- package/dist/backups/index.d.ts +5 -0
- package/dist/backups/index.js +260 -0
- package/dist/backups/metadata.d.ts +9 -0
- package/dist/backups/metadata.js +2 -0
- package/dist/config/db.d.ts +7 -0
- package/dist/config/db.js +26 -0
- package/dist/config/defaults/capabilities.d.ts +2 -0
- package/dist/config/defaults/capabilities.js +47 -0
- package/dist/config/defaults/community.d.ts +2 -0
- package/dist/config/defaults/community.js +41 -0
- package/dist/config/defaults/core.d.ts +2 -0
- package/dist/config/defaults/core.js +113 -0
- package/dist/config/defaults/db.d.ts +6 -0
- package/dist/config/defaults/db.js +8 -0
- package/dist/config/defaults/logs.d.ts +6 -0
- package/dist/config/defaults/logs.js +7 -0
- package/dist/config/defaults/redis.d.ts +4 -0
- package/dist/config/defaults/redis.js +5 -0
- package/dist/config/helpers.d.ts +11 -0
- package/dist/config/helpers.js +31 -0
- package/dist/config/index.d.ts +392 -0
- package/dist/config/index.js +83 -0
- package/dist/config/pruneEmptyConfigStrings.d.ts +7 -0
- package/dist/config/pruneEmptyConfigStrings.js +29 -0
- package/dist/db/aql.d.ts +0 -0
- package/dist/db/aql.js +1 -0
- package/dist/db/arango.d.ts +2 -0
- package/dist/db/arango.js +110 -0
- package/dist/db/bootMigrate.d.ts +1 -0
- package/dist/db/bootMigrate.js +15 -0
- package/dist/db/examples.d.ts +1 -0
- package/dist/db/examples.js +13 -0
- package/dist/db/explorer/csv.d.ts +1 -0
- package/dist/db/explorer/csv.js +18 -0
- package/dist/db/explorer/index.d.ts +6 -0
- package/dist/db/explorer/index.js +5 -0
- package/dist/db/explorer/mutate.d.ts +6 -0
- package/dist/db/explorer/mutate.js +66 -0
- package/dist/db/explorer/query.d.ts +17 -0
- package/dist/db/explorer/query.js +48 -0
- package/dist/db/explorer/sql.d.ts +11 -0
- package/dist/db/explorer/sql.js +42 -0
- package/dist/db/explorer/tables.d.ts +9 -0
- package/dist/db/explorer/tables.js +65 -0
- package/dist/db/helpers.d.ts +64 -0
- package/dist/db/helpers.js +240 -0
- package/dist/db/index.d.ts +13 -0
- package/dist/db/index.js +15 -0
- package/dist/db/init.d.ts +2 -0
- package/dist/db/init.js +10 -0
- package/dist/db/migration/autoMigrate.d.ts +2 -0
- package/dist/db/migration/autoMigrate.js +111 -0
- package/dist/db/migration/cli.d.ts +1 -0
- package/dist/db/migration/cli.js +56 -0
- package/dist/db/migration/detect.d.ts +6 -0
- package/dist/db/migration/detect.js +87 -0
- package/dist/db/migration/exportArango.d.ts +4 -0
- package/dist/db/migration/exportArango.js +80 -0
- package/dist/db/migration/importCollections.d.ts +19 -0
- package/dist/db/migration/importCollections.js +280 -0
- package/dist/db/migration/importPostgres.d.ts +3 -0
- package/dist/db/migration/importPostgres.js +18 -0
- package/dist/db/migration/shared.d.ts +39 -0
- package/dist/db/migration/shared.js +158 -0
- package/dist/db/migration/transform.d.ts +18 -0
- package/dist/db/migration/transform.js +209 -0
- package/dist/db/migration/validate.d.ts +18 -0
- package/dist/db/migration/validate.js +69 -0
- package/dist/db/pg/client.d.ts +35 -0
- package/dist/db/pg/client.js +126 -0
- package/dist/db/pg/collections.d.ts +48 -0
- package/dist/db/pg/collections.js +53 -0
- package/dist/db/pg/filters/common.d.ts +21 -0
- package/dist/db/pg/filters/common.js +48 -0
- package/dist/db/pg/filters/edges.d.ts +9 -0
- package/dist/db/pg/filters/edges.js +10 -0
- package/dist/db/pg/filters/groups.d.ts +7 -0
- package/dist/db/pg/filters/groups.js +15 -0
- package/dist/db/pg/filters/index.d.ts +22 -0
- package/dist/db/pg/filters/index.js +35 -0
- package/dist/db/pg/filters/notifications.d.ts +6 -0
- package/dist/db/pg/filters/notifications.js +10 -0
- package/dist/db/pg/filters/posts.d.ts +18 -0
- package/dist/db/pg/filters/posts.js +25 -0
- package/dist/db/pg/filters/profiles.d.ts +6 -0
- package/dist/db/pg/filters/profiles.js +9 -0
- package/dist/db/pg/filters/types.d.ts +7 -0
- package/dist/db/pg/filters/types.js +5 -0
- package/dist/db/pg/helpers.d.ts +19 -0
- package/dist/db/pg/helpers.js +67 -0
- package/dist/db/pg/map/filters.d.ts +22 -0
- package/dist/db/pg/map/filters.js +566 -0
- package/dist/db/pg/map/helpers.d.ts +2 -0
- package/dist/db/pg/map/helpers.js +2 -0
- package/dist/db/pg/map/index.d.ts +46 -0
- package/dist/db/pg/map/index.js +93 -0
- package/dist/db/pg/map/mutations.d.ts +11 -0
- package/dist/db/pg/map/mutations.js +135 -0
- package/dist/db/pg/map/queryTypes.d.ts +115 -0
- package/dist/db/pg/map/queryTypes.js +1 -0
- package/dist/db/pg/map/registry.d.ts +29 -0
- package/dist/db/pg/map/registry.js +413 -0
- package/dist/db/pg/map/relations.d.ts +28 -0
- package/dist/db/pg/map/relations.js +399 -0
- package/dist/db/pg/map/search.d.ts +6 -0
- package/dist/db/pg/map/search.js +190 -0
- package/dist/db/pg/map/types.d.ts +11 -0
- package/dist/db/pg/map/types.js +1 -0
- package/dist/db/pg/mappers.d.ts +28 -0
- package/dist/db/pg/mappers.js +29 -0
- package/dist/db/pg/migrate.d.ts +14 -0
- package/dist/db/pg/migrate.js +134 -0
- package/dist/db/pg/queries/activity.d.ts +10 -0
- package/dist/db/pg/queries/activity.js +47 -0
- package/dist/db/pg/queries/computed.d.ts +7 -0
- package/dist/db/pg/queries/computed.js +19 -0
- package/dist/db/pg/queries/derived.d.ts +22 -0
- package/dist/db/pg/queries/derived.js +100 -0
- package/dist/db/pg/queries/index.d.ts +4 -0
- package/dist/db/pg/queries/index.js +4 -0
- package/dist/db/pg/queries/sorts.d.ts +10 -0
- package/dist/db/pg/queries/sorts.js +9 -0
- package/dist/db/pg/schema/analytics.d.ts +998 -0
- package/dist/db/pg/schema/analytics.js +110 -0
- package/dist/db/pg/schema/base.d.ts +36 -0
- package/dist/db/pg/schema/base.js +23 -0
- package/dist/db/pg/schema/documents.d.ts +2002 -0
- package/dist/db/pg/schema/documents.js +40 -0
- package/dist/db/pg/schema/edges.d.ts +2725 -0
- package/dist/db/pg/schema/edges.js +34 -0
- package/dist/db/pg/schema/index.d.ts +5724 -0
- package/dist/db/pg/schema/index.js +7 -0
- package/dist/db/pg/sql/0000_bizarre_chat.sql +456 -0
- package/dist/db/pg/sql/0001_search_vector.sql +122 -0
- package/dist/db/pg/sql/0002_data_migrations_id_text.sql +1 -0
- package/dist/db/pg/sql/0003_fix_group_post_visibility.sql +4 -0
- package/dist/db/pg/sql/0004_analytics.sql +90 -0
- package/dist/db/pg/sql/meta/0000_snapshot.json +3380 -0
- package/dist/db/pg/sql/meta/0004_snapshot.json +4114 -0
- package/dist/db/pg/sql/meta/_journal.json +41 -0
- package/dist/db/replaceHostname.d.ts +1 -0
- package/dist/db/replaceHostname.js +88 -0
- package/dist/db/types.d.ts +17 -0
- package/dist/db/types.js +1 -0
- package/dist/email/index.d.ts +9 -0
- package/dist/email/index.js +19 -0
- package/dist/email/jobs.d.ts +3 -0
- package/dist/email/jobs.js +13 -0
- package/dist/email/queueStats.d.ts +2 -0
- package/dist/email/queueStats.js +27 -0
- package/dist/email/registry.d.ts +3 -0
- package/dist/email/registry.js +4 -0
- package/dist/email/render.d.ts +8 -0
- package/dist/email/render.js +34 -0
- package/dist/email/send.d.ts +9 -0
- package/dist/email/send.js +97 -0
- package/dist/email/smtpTest.d.ts +2 -0
- package/dist/email/smtpTest.js +26 -0
- package/dist/errors/index.d.ts +8 -0
- package/dist/errors/index.js +13 -0
- package/dist/events/index.d.ts +31 -0
- package/dist/events/index.js +66 -0
- package/dist/events/once.d.ts +4 -0
- package/dist/events/once.js +23 -0
- package/dist/groups/finders.d.ts +125 -0
- package/dist/groups/finders.js +18 -0
- package/dist/groups/helpers.d.ts +227 -0
- package/dist/groups/helpers.js +17 -0
- package/dist/groups/index.d.ts +3 -0
- package/dist/groups/index.js +3 -0
- package/dist/groups/mapping.d.ts +188 -0
- package/dist/groups/mapping.js +47 -0
- package/dist/groups/mutations.d.ts +26 -0
- package/dist/groups/mutations.js +41 -0
- package/dist/hashtags/finders.d.ts +3 -0
- package/dist/hashtags/finders.js +22 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mapping.d.ts +4 -0
- package/dist/hashtags/mapping.js +5 -0
- package/dist/hashtags/mutations.d.ts +0 -0
- package/dist/hashtags/mutations.js +1 -0
- package/dist/i18n/index.d.ts +14 -0
- package/dist/i18n/index.js +53 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +1 -0
- package/dist/inviteLinks/finders.d.ts +3 -0
- package/dist/inviteLinks/finders.js +5 -0
- package/dist/inviteLinks/helpers.d.ts +20 -0
- package/dist/inviteLinks/helpers.js +4 -0
- package/dist/inviteLinks/index.d.ts +3 -0
- package/dist/inviteLinks/index.js +3 -0
- package/dist/inviteLinks/mapping.d.ts +10 -0
- package/dist/inviteLinks/mapping.js +35 -0
- package/dist/inviteLinks/mutations.d.ts +4 -0
- package/dist/inviteLinks/mutations.js +39 -0
- package/dist/jams/cache.d.ts +9 -0
- package/dist/jams/cache.js +13 -0
- package/dist/jams/finders.d.ts +23 -0
- package/dist/jams/finders.js +24 -0
- package/dist/jams/helpers.d.ts +70 -0
- package/dist/jams/helpers.js +29 -0
- package/dist/jams/index.d.ts +15 -0
- package/dist/jams/index.js +108 -0
- package/dist/jams/jobs.d.ts +9 -0
- package/dist/jams/jobs.js +42 -0
- package/dist/jams/livekit.d.ts +24 -0
- package/dist/jams/livekit.js +220 -0
- package/dist/jams/mapping.d.ts +137 -0
- package/dist/jams/mapping.js +35 -0
- package/dist/jams/mutations.d.ts +40 -0
- package/dist/jams/mutations.js +4 -0
- package/dist/jams/recording.d.ts +8 -0
- package/dist/jams/recording.js +67 -0
- package/dist/jams/recordingUploadAuth.d.ts +9 -0
- package/dist/jams/recordingUploadAuth.js +19 -0
- package/dist/jams/token.d.ts +4 -0
- package/dist/jams/token.js +129 -0
- package/dist/jams/waitingRoom.d.ts +5 -0
- package/dist/jams/waitingRoom.js +71 -0
- package/dist/jobs/index.d.ts +10 -0
- package/dist/jobs/index.js +60 -0
- package/dist/jobs/jobDetail.d.ts +2 -0
- package/dist/jobs/jobDetail.js +31 -0
- package/dist/jobs/jobLog.d.ts +18 -0
- package/dist/jobs/jobLog.js +61 -0
- package/dist/jwt/index.d.ts +10 -0
- package/dist/jwt/index.js +43 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/streams.d.ts +2 -0
- package/dist/lib/streams.js +56 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +17 -0
- package/dist/lib/zodDeepPartial.d.ts +3 -0
- package/dist/lib/zodDeepPartial.js +26 -0
- package/dist/location/index.d.ts +2 -0
- package/dist/location/index.js +28 -0
- package/dist/log/index.d.ts +3 -0
- package/dist/log/index.js +97 -0
- package/dist/mastodon/index.d.ts +4 -0
- package/dist/mastodon/index.js +51 -0
- package/dist/mastodon/types.d.ts +7579 -0
- package/dist/mastodon/types.js +523 -0
- package/dist/mastodon/typescript.d.ts +1578 -0
- package/dist/mastodon/typescript.js +1 -0
- package/dist/media/index.d.ts +40 -0
- package/dist/media/index.js +248 -0
- package/dist/media/ipfs/index.d.ts +0 -0
- package/dist/media/ipfs/index.js +39 -0
- package/dist/media/jobs.d.ts +19 -0
- package/dist/media/jobs.js +90 -0
- package/dist/media/openpeeps/index.d.ts +3 -0
- package/dist/media/openpeeps/index.js +131 -0
- package/dist/media/processing.d.ts +19 -0
- package/dist/media/processing.js +83 -0
- package/dist/media/streaming.d.ts +77 -0
- package/dist/media/streaming.js +257 -0
- package/dist/media/streamingCleanupJobs.d.ts +14 -0
- package/dist/media/streamingCleanupJobs.js +47 -0
- package/dist/media/streamingJobs.d.ts +5 -0
- package/dist/media/streamingJobs.js +329 -0
- package/dist/media/streamingPrewarm.d.ts +36 -0
- package/dist/media/streamingPrewarm.js +109 -0
- package/dist/mediaAttachments/finders.d.ts +1 -0
- package/dist/mediaAttachments/finders.js +3 -0
- package/dist/mediaAttachments/index.d.ts +5 -0
- package/dist/mediaAttachments/index.js +12 -0
- package/dist/mediaAttachments/mapping.d.ts +21 -0
- package/dist/mediaAttachments/mapping.js +4 -0
- package/dist/mediaAttachments/mutations.d.ts +3 -0
- package/dist/mediaAttachments/mutations.js +10 -0
- package/dist/notifications/defaultNotifications/announcement/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/announcement/index.js +42 -0
- package/dist/notifications/defaultNotifications/directMessage/index.d.ts +28 -0
- package/dist/notifications/defaultNotifications/directMessage/index.js +69 -0
- package/dist/notifications/defaultNotifications/follow/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/follow/index.js +31 -0
- package/dist/notifications/defaultNotifications/groupAdded/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupAdded/index.js +33 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +36 -0
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +36 -0
- package/dist/notifications/defaultNotifications/index.d.ts +3 -0
- package/dist/notifications/defaultNotifications/index.js +43 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.d.ts +23 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +49 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.d.ts +23 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +47 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.js +82 -0
- package/dist/notifications/defaultNotifications/mention/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/mention/index.js +89 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +47 -0
- package/dist/notifications/defaultNotifications/newProfile/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/newProfile/index.js +40 -0
- package/dist/notifications/defaultNotifications/pollVote/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +40 -0
- package/dist/notifications/defaultNotifications/reaction/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/reaction/index.js +43 -0
- package/dist/notifications/defaultNotifications/reply/index.d.ts +25 -0
- package/dist/notifications/defaultNotifications/reply/index.js +57 -0
- package/dist/notifications/defaultNotifications/repost/index.d.ts +18 -0
- package/dist/notifications/defaultNotifications/repost/index.js +42 -0
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/rsvp/index.js +40 -0
- package/dist/notifications/fcmCredential.d.ts +14 -0
- package/dist/notifications/fcmCredential.js +68 -0
- package/dist/notifications/finders.d.ts +7 -0
- package/dist/notifications/finders.js +13 -0
- package/dist/notifications/firebase.d.ts +1 -0
- package/dist/notifications/firebase.js +33 -0
- package/dist/notifications/handlers.d.ts +3 -0
- package/dist/notifications/handlers.js +6 -0
- package/dist/notifications/helpers.d.ts +7 -0
- package/dist/notifications/helpers.js +31 -0
- package/dist/notifications/index.d.ts +9 -0
- package/dist/notifications/index.js +43 -0
- package/dist/notifications/jobs.d.ts +2 -0
- package/dist/notifications/jobs.js +75 -0
- package/dist/notifications/mapping.d.ts +25 -0
- package/dist/notifications/mapping.js +25 -0
- package/dist/notifications/mutations.d.ts +6 -0
- package/dist/notifications/mutations.js +40 -0
- package/dist/notifications/push.d.ts +9 -0
- package/dist/notifications/push.js +261 -0
- package/dist/notifications/pushInvalidation.d.ts +10 -0
- package/dist/notifications/pushInvalidation.js +10 -0
- package/dist/performance/index.d.ts +24 -0
- package/dist/performance/index.js +61 -0
- package/dist/plugins/helpers.d.ts +3 -0
- package/dist/plugins/helpers.js +72 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.js +84 -0
- package/dist/plugins/pluginAuth.d.ts +30 -0
- package/dist/plugins/pluginAuth.js +44 -0
- package/dist/posts/contextClosure.d.ts +16 -0
- package/dist/posts/contextClosure.js +66 -0
- package/dist/posts/finders.d.ts +298 -0
- package/dist/posts/finders.js +259 -0
- package/dist/posts/helpers/filters.d.ts +14 -0
- package/dist/posts/helpers/filters.js +39 -0
- package/dist/posts/helpers/index.d.ts +837 -0
- package/dist/posts/helpers/index.js +117 -0
- package/dist/posts/index.d.ts +6 -0
- package/dist/posts/index.js +6 -0
- package/dist/posts/mapping.d.ts +2187 -0
- package/dist/posts/mapping.js +222 -0
- package/dist/posts/mutations.d.ts +19 -0
- package/dist/posts/mutations.js +202 -0
- package/dist/posts/rsvpConfirmationEmail.d.ts +2 -0
- package/dist/posts/rsvpConfirmationEmail.js +82 -0
- package/dist/processingStats/index.d.ts +3 -0
- package/dist/processingStats/index.js +3 -0
- package/dist/processingStats/mapping.d.ts +7 -0
- package/dist/processingStats/mapping.js +4 -0
- package/dist/processingStats/mutations.d.ts +2 -0
- package/dist/processingStats/mutations.js +6 -0
- package/dist/processingStats/queries.d.ts +4 -0
- package/dist/processingStats/queries.js +46 -0
- package/dist/profileSettings/cache.d.ts +2 -0
- package/dist/profileSettings/cache.js +24 -0
- package/dist/profileSettings/finders.d.ts +1 -0
- package/dist/profileSettings/finders.js +2 -0
- package/dist/profileSettings/index.d.ts +3 -0
- package/dist/profileSettings/index.js +3 -0
- package/dist/profileSettings/mapping.d.ts +38 -0
- package/dist/profileSettings/mapping.js +5 -0
- package/dist/profileSettings/mutations.d.ts +3 -0
- package/dist/profileSettings/mutations.js +24 -0
- package/dist/profiles/cache.d.ts +5 -0
- package/dist/profiles/cache.js +19 -0
- package/dist/profiles/capacity.d.ts +2 -0
- package/dist/profiles/capacity.js +20 -0
- package/dist/profiles/export.d.ts +3 -0
- package/dist/profiles/export.js +85 -0
- package/dist/profiles/finders.d.ts +11 -0
- package/dist/profiles/finders.js +39 -0
- package/dist/profiles/helpers.d.ts +35 -0
- package/dist/profiles/helpers.js +10 -0
- package/dist/profiles/index.d.ts +5 -0
- package/dist/profiles/index.js +18 -0
- package/dist/profiles/mapping.d.ts +157 -0
- package/dist/profiles/mapping.js +132 -0
- package/dist/profiles/mutations.d.ts +9 -0
- package/dist/profiles/mutations.js +75 -0
- package/dist/pushSubscriptions/finders.d.ts +187 -0
- package/dist/pushSubscriptions/finders.js +6 -0
- package/dist/pushSubscriptions/helpers.d.ts +99 -0
- package/dist/pushSubscriptions/helpers.js +3 -0
- package/dist/pushSubscriptions/index.d.ts +3 -0
- package/dist/pushSubscriptions/index.js +3 -0
- package/dist/pushSubscriptions/mapping.d.ts +261 -0
- package/dist/pushSubscriptions/mapping.js +6 -0
- package/dist/pushSubscriptions/mutations.d.ts +95 -0
- package/dist/pushSubscriptions/mutations.js +21 -0
- package/dist/redis/connection.d.ts +4 -0
- package/dist/redis/connection.js +17 -0
- package/dist/redis/index.d.ts +1 -0
- package/dist/redis/index.js +1 -0
- package/dist/reports/finders.d.ts +6 -0
- package/dist/reports/finders.js +44 -0
- package/dist/reports/helpers.d.ts +21 -0
- package/dist/reports/helpers.js +12 -0
- package/dist/reports/index.d.ts +3 -0
- package/dist/reports/index.js +3 -0
- package/dist/reports/mapping.d.ts +9 -0
- package/dist/reports/mapping.js +34 -0
- package/dist/reports/mutations.d.ts +5 -0
- package/dist/reports/mutations.js +16 -0
- package/dist/roles/defaults.d.ts +2 -0
- package/dist/roles/defaults.js +94 -0
- package/dist/roles/finders.d.ts +5 -0
- package/dist/roles/finders.js +9 -0
- package/dist/roles/index.d.ts +4 -0
- package/dist/roles/index.js +4 -0
- package/dist/roles/mapping.d.ts +11 -0
- package/dist/roles/mapping.js +5 -0
- package/dist/roles/mutations.d.ts +4 -0
- package/dist/roles/mutations.js +30 -0
- package/dist/search/finders.d.ts +47 -0
- package/dist/search/finders.js +59 -0
- package/dist/search/helpers.d.ts +3 -0
- package/dist/search/helpers.js +1 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/index.js +1 -0
- package/dist/search/mapping.d.ts +40 -0
- package/dist/search/mapping.js +43 -0
- package/dist/sentry/index.d.ts +34 -0
- package/dist/sentry/index.js +113 -0
- package/dist/server/helpers.d.ts +0 -0
- package/dist/server/helpers.js +1 -0
- package/dist/server/index.d.ts +105 -0
- package/dist/server/index.js +64 -0
- package/dist/stats/finders.d.ts +16156 -0
- package/dist/stats/finders.js +167 -0
- package/dist/stats/helpers.d.ts +17 -0
- package/dist/stats/helpers.js +34 -0
- package/dist/stats/index.d.ts +1 -0
- package/dist/stats/index.js +1 -0
- package/dist/stats/mapping.d.ts +188 -0
- package/dist/stats/mapping.js +19 -0
- package/dist/stripe/cache.d.ts +30 -0
- package/dist/stripe/cache.js +37 -0
- package/dist/stripe/connection.d.ts +5 -0
- package/dist/stripe/connection.js +23 -0
- package/dist/stripe/helpers.d.ts +25 -0
- package/dist/stripe/helpers.js +211 -0
- package/dist/stripe/index.d.ts +3 -0
- package/dist/stripe/index.js +3 -0
- package/package.json +99 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MediaStorage } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const mediaStorage: () => Promise<MediaStorage>;
|
|
3
|
+
/**
|
|
4
|
+
* A media source/output that lives on disk rather than in memory. The whole
|
|
5
|
+
* processing pipeline passes these around so ffmpeg/sharp read and write files
|
|
6
|
+
* directly — a multi-hundred-megabyte upload is never materialised as a
|
|
7
|
+
* `Buffer`/`ArrayBuffer`. `mimetype` carries the type that the `File` used to.
|
|
8
|
+
*/
|
|
9
|
+
export interface MediaFile {
|
|
10
|
+
path: string;
|
|
11
|
+
mimetype: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Stream a web `ReadableStream` to a temp file, preserving the original
|
|
15
|
+
* extension so format-sniffing tools (audiowaveform, sharp) behave. Peak
|
|
16
|
+
* memory is bounded by the write stream's highWaterMark, not the file size.
|
|
17
|
+
*/
|
|
18
|
+
export declare const writeStreamToTemp: (stream: ReadableStream, name: string) => Promise<string>;
|
|
19
|
+
/** Stream a stored object straight to a temp file (never fully buffered). */
|
|
20
|
+
export declare const writeStorageToTemp: (storageId: string, name: string) => Promise<string>;
|
|
21
|
+
/** Content-address and store a file by streaming it from disk. */
|
|
22
|
+
export declare const storeFromPath: (filePath: string) => Promise<{
|
|
23
|
+
key: string;
|
|
24
|
+
size: number;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the on-disk file to store for the attachment plus its final
|
|
28
|
+
* filename. Videos are transcoded to a temp `.mp4` (a fresh path); everything
|
|
29
|
+
* else is stored as-is (the returned `path` is the input itself).
|
|
30
|
+
*/
|
|
31
|
+
export declare const transcodeIncomingMedia: (type: string, inputPath: string, originalName: string, sourceMimetype: string) => Promise<MediaFile & {
|
|
32
|
+
filename: string;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const createPreview: (inputPath: string, mimetype: string, originalName: string) => Promise<MediaFile>;
|
|
35
|
+
export * from './processing';
|
|
36
|
+
export * from './jobs';
|
|
37
|
+
export * from './streaming';
|
|
38
|
+
export * from './streamingJobs';
|
|
39
|
+
export * from './streamingCleanupJobs';
|
|
40
|
+
export * from './streamingPrewarm';
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { communityConfig, config } from '../config/index.js';
|
|
2
|
+
import openpeepsStorage from './openpeeps/index.js';
|
|
3
|
+
import sharp from 'sharp';
|
|
4
|
+
import ffmpeg from 'fluent-ffmpeg';
|
|
5
|
+
import path, { join } from 'node:path';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import fs from 'node:fs/promises';
|
|
8
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
9
|
+
import { Readable } from 'node:stream';
|
|
10
|
+
import { pipeline } from 'node:stream/promises';
|
|
11
|
+
import { getTheme, randomString } from '@openpeepshq/common/lib';
|
|
12
|
+
import { execSync } from 'node:child_process';
|
|
13
|
+
import { logger } from '../log/index.js';
|
|
14
|
+
import { hub } from '../events/index.js';
|
|
15
|
+
let storagePromise = null;
|
|
16
|
+
const log = logger('app:media');
|
|
17
|
+
const previewMaxWidth = 700;
|
|
18
|
+
const initStorage = async () => {
|
|
19
|
+
const { media: { storage: { params }, }, } = await config();
|
|
20
|
+
hub.on('configUpdated', (namespace, name) => {
|
|
21
|
+
if (namespace === 'openpeeps' && name === 'core') {
|
|
22
|
+
storagePromise = null;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return openpeepsStorage(params);
|
|
26
|
+
};
|
|
27
|
+
export const mediaStorage = () => {
|
|
28
|
+
if (!storagePromise) {
|
|
29
|
+
storagePromise = initStorage();
|
|
30
|
+
}
|
|
31
|
+
return storagePromise;
|
|
32
|
+
};
|
|
33
|
+
const tempPathFor = (name) => join(tmpdir(), `media-${randomString(16)}${path.extname(name)}`);
|
|
34
|
+
/**
|
|
35
|
+
* Stream a web `ReadableStream` to a temp file, preserving the original
|
|
36
|
+
* extension so format-sniffing tools (audiowaveform, sharp) behave. Peak
|
|
37
|
+
* memory is bounded by the write stream's highWaterMark, not the file size.
|
|
38
|
+
*/
|
|
39
|
+
export const writeStreamToTemp = async (stream, name) => {
|
|
40
|
+
const tempPath = tempPathFor(name);
|
|
41
|
+
await pipeline(Readable.fromWeb(stream), createWriteStream(tempPath));
|
|
42
|
+
return tempPath;
|
|
43
|
+
};
|
|
44
|
+
/** Stream a stored object straight to a temp file (never fully buffered). */
|
|
45
|
+
export const writeStorageToTemp = async (storageId, name) => {
|
|
46
|
+
const storage = await mediaStorage();
|
|
47
|
+
const stream = await storage.getStream(storageId);
|
|
48
|
+
if (!stream) {
|
|
49
|
+
throw new Error(`Source file not found in storage: ${storageId}`);
|
|
50
|
+
}
|
|
51
|
+
return writeStreamToTemp(stream, name);
|
|
52
|
+
};
|
|
53
|
+
/** Content-address and store a file by streaming it from disk. */
|
|
54
|
+
export const storeFromPath = (filePath) => mediaStorage().then((storage) => storage.storeStream(Readable.toWeb(createReadStream(filePath))));
|
|
55
|
+
const transcodeVideo = async (inputPath) => {
|
|
56
|
+
const { size } = await fs.stat(inputPath);
|
|
57
|
+
const isLargeFile = size > 10 * 1024 * 1024;
|
|
58
|
+
const tempOutputPath = join(tmpdir(), `output-${randomString(16)}.mp4`);
|
|
59
|
+
const baseOutput = [
|
|
60
|
+
'-c:v h264', // Better for iOS hardware acceleration
|
|
61
|
+
'-profile:v baseline', // Ensures maximum device compatibility
|
|
62
|
+
'-level 3.0', // Compatible with older iOS devices
|
|
63
|
+
'-movflags +faststart', // Enables fast start for web playback
|
|
64
|
+
'-pix_fmt yuv420p', // Required for iOS compatibility
|
|
65
|
+
'-c:a aac', // AAC audio (iOS standard)
|
|
66
|
+
'-b:a 128k', // Audio bitrate
|
|
67
|
+
'-tune zerolatency', // Optimized for web streaming with minimal latency
|
|
68
|
+
'-keyint_min 24', // Minimum "Group of Pictures"(GOP) size for better seeking
|
|
69
|
+
'-g 24', // Standard GOP size
|
|
70
|
+
];
|
|
71
|
+
if (isLargeFile) {
|
|
72
|
+
baseOutput.push('-max_muxing_queue_size 9999'); // Helps with complex MOV files
|
|
73
|
+
}
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
ffmpeg(inputPath)
|
|
76
|
+
.size(`${previewMaxWidth}x?`)
|
|
77
|
+
.output(tempOutputPath)
|
|
78
|
+
.outputOptions(baseOutput)
|
|
79
|
+
.on('end', () => resolve(tempOutputPath))
|
|
80
|
+
.on('error', reject)
|
|
81
|
+
.run();
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Returns the on-disk file to store for the attachment plus its final
|
|
86
|
+
* filename. Videos are transcoded to a temp `.mp4` (a fresh path); everything
|
|
87
|
+
* else is stored as-is (the returned `path` is the input itself).
|
|
88
|
+
*/
|
|
89
|
+
export const transcodeIncomingMedia = async (type, inputPath, originalName, sourceMimetype) => {
|
|
90
|
+
if (type === 'video') {
|
|
91
|
+
return {
|
|
92
|
+
path: await transcodeVideo(inputPath),
|
|
93
|
+
filename: path.parse(originalName).name + '.mp4',
|
|
94
|
+
mimetype: 'video/mp4',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return { path: inputPath, filename: originalName, mimetype: sourceMimetype };
|
|
98
|
+
};
|
|
99
|
+
export const createPreview = async (inputPath, mimetype, originalName) => {
|
|
100
|
+
switch (mimetype.split('/')[0]) {
|
|
101
|
+
case 'image':
|
|
102
|
+
return createImagePreview(inputPath, mimetype);
|
|
103
|
+
case 'audio':
|
|
104
|
+
return createAudioPreview(inputPath);
|
|
105
|
+
case 'video':
|
|
106
|
+
return createVideoPreview(inputPath);
|
|
107
|
+
default:
|
|
108
|
+
if (originalName.endsWith('.mkv')) {
|
|
109
|
+
return createVideoPreview(inputPath);
|
|
110
|
+
}
|
|
111
|
+
return { path: inputPath, mimetype };
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const createImagePreview = async (inputPath, mimetype) => {
|
|
115
|
+
const width = await sharp(inputPath)
|
|
116
|
+
.metadata()
|
|
117
|
+
.then((m) => m.width || 0);
|
|
118
|
+
if (width <= previewMaxWidth) {
|
|
119
|
+
return { path: inputPath, mimetype };
|
|
120
|
+
}
|
|
121
|
+
const outputPath = join(tmpdir(), `preview-${randomString(16)}.webp`);
|
|
122
|
+
await sharp(inputPath)
|
|
123
|
+
.rotate()
|
|
124
|
+
.resize(previewMaxWidth)
|
|
125
|
+
.webp()
|
|
126
|
+
.toFile(outputPath);
|
|
127
|
+
return { path: outputPath, mimetype: 'image/webp' };
|
|
128
|
+
};
|
|
129
|
+
const getMediaDuration = (filePath) => new Promise((resolve, reject) => {
|
|
130
|
+
ffmpeg.ffprobe(filePath, (err, metadata) => {
|
|
131
|
+
if (err) {
|
|
132
|
+
reject(err);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Access the duration from the format section of the metadata
|
|
136
|
+
const duration = metadata.format.duration;
|
|
137
|
+
if (!duration) {
|
|
138
|
+
reject(new Error('No duration found'));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
resolve(duration);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
const getVideoStreamInfo = (filePath) => new Promise((resolve, reject) => {
|
|
147
|
+
ffmpeg.ffprobe(filePath, (err, metadata) => {
|
|
148
|
+
var _a;
|
|
149
|
+
if (err) {
|
|
150
|
+
reject(err);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const stream = metadata.streams.find((s) => s.codec_type === 'video');
|
|
154
|
+
const duration = (_a = metadata.format.duration) !== null && _a !== void 0 ? _a : ((stream === null || stream === void 0 ? void 0 : stream.duration) ? Number(stream.duration) : undefined);
|
|
155
|
+
if (!(stream === null || stream === void 0 ? void 0 : stream.width) || !(stream === null || stream === void 0 ? void 0 : stream.height) || !duration) {
|
|
156
|
+
reject(new Error('Could not determine video stream info'));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
resolve({ width: stream.width, height: stream.height, duration });
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
const createAudioPreview = async (inputPath) => {
|
|
163
|
+
const outputPath = join(tmpdir(), `preview-${randomString(16)}.png`);
|
|
164
|
+
try {
|
|
165
|
+
const duration = await getMediaDuration(inputPath);
|
|
166
|
+
const pixelsPerSecond = Math.floor(700 / duration);
|
|
167
|
+
execSync(`audiowaveform -i ${inputPath} -o ${outputPath} \
|
|
168
|
+
--background-color ffffff88 --waveform-color ${getTheme(await communityConfig()).primaryHex.slice(1)} \
|
|
169
|
+
-w ${previewMaxWidth} -h ${previewMaxWidth} --pixels-per-second ${pixelsPerSecond} \
|
|
170
|
+
--no-axis-labels -q`);
|
|
171
|
+
return { path: outputPath, mimetype: 'image/png' };
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
await fs.unlink(outputPath).catch(() => { });
|
|
175
|
+
throw new Error(`Error generating audio preview: ${error}`);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Build a still 3x3 WebP montage of the video. Nine frames are sampled
|
|
180
|
+
* evenly across the duration and tiled at the source aspect ratio so the
|
|
181
|
+
* final image's dimensions mirror the video. We emit a single still frame
|
|
182
|
+
* (not animated WebP) because RN/iOS' built-in image decoder doesn't render
|
|
183
|
+
* animated WebP without an extra native dep.
|
|
184
|
+
*/
|
|
185
|
+
const createVideoPreview = async (inputPath) => {
|
|
186
|
+
const tempOutputPath = join(tmpdir(), `preview-${randomString(16)}.webp`);
|
|
187
|
+
const cleanup = async () => {
|
|
188
|
+
fs.unlink(tempOutputPath).catch(log.error);
|
|
189
|
+
};
|
|
190
|
+
let info;
|
|
191
|
+
try {
|
|
192
|
+
info = await getVideoStreamInfo(inputPath);
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
await cleanup();
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
198
|
+
const gridCols = 3;
|
|
199
|
+
const gridRows = 3;
|
|
200
|
+
const frameCount = gridCols * gridRows;
|
|
201
|
+
// Cell size derived from source aspect ratio; cap the total montage at
|
|
202
|
+
// `previewMaxWidth` so we don't generate huge thumbnails for 4K video.
|
|
203
|
+
// libwebp wants even dimensions for its yuv420 pipeline.
|
|
204
|
+
const targetWidth = Math.min(info.width, previewMaxWidth);
|
|
205
|
+
const cellWidth = Math.max(2, Math.floor(targetWidth / gridCols / 2) * 2);
|
|
206
|
+
const cellHeight = Math.max(2, Math.floor((cellWidth * info.height) / info.width / 2) * 2);
|
|
207
|
+
// Sample 9 evenly spaced frames across the full duration via the fps
|
|
208
|
+
// filter. setpts resets PTS so `tile` collects the frames in order.
|
|
209
|
+
const sampleRate = frameCount / Math.max(info.duration, 0.001);
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
ffmpeg(inputPath)
|
|
212
|
+
.noAudio()
|
|
213
|
+
.videoFilters([
|
|
214
|
+
`fps=${sampleRate}`,
|
|
215
|
+
`scale=${cellWidth}:${cellHeight}:force_original_aspect_ratio=decrease`,
|
|
216
|
+
`pad=${cellWidth}:${cellHeight}:(ow-iw)/2:(oh-ih)/2:color=black`,
|
|
217
|
+
`setpts=N/TB`,
|
|
218
|
+
`tile=${gridCols}x${gridRows}`,
|
|
219
|
+
])
|
|
220
|
+
.frames(1)
|
|
221
|
+
.outputOptions(['-c:v libwebp', '-lossless 0', '-q:v 80'])
|
|
222
|
+
.output(tempOutputPath)
|
|
223
|
+
.on('end', async () => {
|
|
224
|
+
try {
|
|
225
|
+
const { size } = await fs.stat(tempOutputPath);
|
|
226
|
+
if (!size) {
|
|
227
|
+
throw new Error('Generated video preview is empty');
|
|
228
|
+
}
|
|
229
|
+
resolve({ path: tempOutputPath, mimetype: 'image/webp' });
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
await cleanup();
|
|
233
|
+
reject(new Error(`Error handling output file: ${error.message}`));
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
.on('error', async (error) => {
|
|
237
|
+
await cleanup();
|
|
238
|
+
reject(new Error(`FFmpeg error: ${error.message}`));
|
|
239
|
+
})
|
|
240
|
+
.run();
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
export * from './processing.js';
|
|
244
|
+
export * from './jobs.js';
|
|
245
|
+
export * from './streaming.js';
|
|
246
|
+
export * from './streamingJobs.js';
|
|
247
|
+
export * from './streamingCleanupJobs.js';
|
|
248
|
+
export * from './streamingPrewarm.js';
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { unixfs } from '@helia/unixfs';
|
|
3
|
+
// import { createHelia } from 'helia';
|
|
4
|
+
// import { FsBlockstore } from 'blockstore-fs';
|
|
5
|
+
// import { CID } from 'multiformats';
|
|
6
|
+
// import type {MediaStorage, MediaStorageParams} from '@openpeepshq/common/types';
|
|
7
|
+
//
|
|
8
|
+
// interface EnhancedReadableStream extends ReadableStream {
|
|
9
|
+
// from: <T> (iterable: Iterable<T> | AsyncIterable<T>) => ReadableStream<T>
|
|
10
|
+
// }
|
|
11
|
+
//
|
|
12
|
+
// const EnhancedReadableStreamObject = (ReadableStream as unknown) as EnhancedReadableStream;
|
|
13
|
+
//
|
|
14
|
+
// const ipfsStorage = async (params: MediaStorageParams): Promise<MediaStorage> => {
|
|
15
|
+
// // const helia = await createHelia({ blockstore: new FsBlockstore(params.path) });
|
|
16
|
+
// // const fs = unixfs(helia);
|
|
17
|
+
//
|
|
18
|
+
// const { path } = params;
|
|
19
|
+
//
|
|
20
|
+
// const fs = (path: string) => {
|
|
21
|
+
//
|
|
22
|
+
// const storagePath = path + '/.simpleDedupStorage';
|
|
23
|
+
//
|
|
24
|
+
// return {
|
|
25
|
+
// addBytes: (data: Uint8Array) => {
|
|
26
|
+
// const hash = sha512
|
|
27
|
+
// }
|
|
28
|
+
// };
|
|
29
|
+
// }
|
|
30
|
+
//
|
|
31
|
+
// return {
|
|
32
|
+
// store: async (data) => (await fs.addBytes(data)).toString(),
|
|
33
|
+
// load: (key) => fs.cat(CID.parse(key)),
|
|
34
|
+
// getPath: (id, filename) => `${params.host}${params.prefix}/ipfs/${id}/${filename}`,
|
|
35
|
+
// getStream: (id) => EnhancedReadableStreamObject.from(fs.cat(CID.parse(id))),
|
|
36
|
+
// };
|
|
37
|
+
// };
|
|
38
|
+
//
|
|
39
|
+
// export default ipfsStorage;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface MediaProcessingJobData {
|
|
2
|
+
mediaAttachmentId: string;
|
|
3
|
+
fileStorageKey: string;
|
|
4
|
+
filename: string;
|
|
5
|
+
mimetype: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const mediaProcessingMetaKey: (mediaAttachmentId: string) => string;
|
|
8
|
+
export declare const mediaProgressChannel: (mediaAttachmentId: string) => string;
|
|
9
|
+
export interface MediaProcessingMeta {
|
|
10
|
+
startedAt: number;
|
|
11
|
+
estimatedDurationMs: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const setMediaProcessingMeta: (mediaAttachmentId: string, meta: MediaProcessingMeta) => Promise<void>;
|
|
14
|
+
export declare const getMediaProcessingMeta: (mediaAttachmentId: string) => Promise<MediaProcessingMeta | undefined>;
|
|
15
|
+
export declare const clearMediaProcessingMeta: (mediaAttachmentId: string) => Promise<void>;
|
|
16
|
+
export declare const publishMediaProgress: (mediaAttachmentId: string, message?: string) => Promise<void>;
|
|
17
|
+
export declare const subscribeToMediaProgress: (mediaAttachmentId: string, onMessage: (message: string) => void | Promise<void>) => Promise<() => Promise<void>>;
|
|
18
|
+
declare const mediaProcessingQueue: () => import("bullmq").Queue, mediaProcessingWorker: () => import("bullmq").Worker;
|
|
19
|
+
export { mediaProcessingQueue, mediaProcessingWorker };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { queueAndWorker } from '../jobs/index.js';
|
|
2
|
+
import { logger } from '../log/index.js';
|
|
3
|
+
import { findMediaAttachment, updateMediaAttachment, } from '../mediaAttachments/index.js';
|
|
4
|
+
import { estimateProcessingDuration } from '../processingStats/index.js';
|
|
5
|
+
import { disconnect, getConnection, getSharedConnection, } from '../redis/connection.js';
|
|
6
|
+
import { runProcessing } from './processing.js';
|
|
7
|
+
const log = logger('app:media:jobs');
|
|
8
|
+
export const mediaProcessingMetaKey = (mediaAttachmentId) => `media:processing:${mediaAttachmentId}`;
|
|
9
|
+
export const mediaProgressChannel = (mediaAttachmentId) => `media:progress:${mediaAttachmentId}`;
|
|
10
|
+
export const setMediaProcessingMeta = async (mediaAttachmentId, meta) => {
|
|
11
|
+
const conn = await getSharedConnection();
|
|
12
|
+
await conn.hSet(mediaProcessingMetaKey(mediaAttachmentId), {
|
|
13
|
+
startedAt: String(meta.startedAt),
|
|
14
|
+
estimatedDurationMs: String(meta.estimatedDurationMs),
|
|
15
|
+
});
|
|
16
|
+
await conn.expire(mediaProcessingMetaKey(mediaAttachmentId), 60 * 60);
|
|
17
|
+
};
|
|
18
|
+
export const getMediaProcessingMeta = async (mediaAttachmentId) => {
|
|
19
|
+
const conn = await getSharedConnection();
|
|
20
|
+
const raw = await conn.hGetAll(mediaProcessingMetaKey(mediaAttachmentId));
|
|
21
|
+
if (!raw || !raw.startedAt) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
startedAt: Number(raw.startedAt),
|
|
26
|
+
estimatedDurationMs: Number(raw.estimatedDurationMs) || 0,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const clearMediaProcessingMeta = async (mediaAttachmentId) => {
|
|
30
|
+
const conn = await getSharedConnection();
|
|
31
|
+
await conn.del(mediaProcessingMetaKey(mediaAttachmentId));
|
|
32
|
+
};
|
|
33
|
+
export const publishMediaProgress = async (mediaAttachmentId, message = 'updated') => {
|
|
34
|
+
const conn = await getSharedConnection();
|
|
35
|
+
await conn.publish(mediaProgressChannel(mediaAttachmentId), message);
|
|
36
|
+
};
|
|
37
|
+
export const subscribeToMediaProgress = async (mediaAttachmentId, onMessage) => {
|
|
38
|
+
const conn = await getConnection();
|
|
39
|
+
await conn.subscribe(mediaProgressChannel(mediaAttachmentId), (message) => {
|
|
40
|
+
void onMessage(message);
|
|
41
|
+
});
|
|
42
|
+
return () => disconnect(conn);
|
|
43
|
+
};
|
|
44
|
+
const [mediaProcessingQueue, mediaProcessingWorker] = queueAndWorker('media-processing', async (job) => {
|
|
45
|
+
var _a;
|
|
46
|
+
const { mediaAttachmentId, fileStorageKey } = job.data;
|
|
47
|
+
const attachment = await findMediaAttachment(mediaAttachmentId);
|
|
48
|
+
if (!attachment) {
|
|
49
|
+
throw new Error(`MediaAttachment ${mediaAttachmentId} not found in worker`);
|
|
50
|
+
}
|
|
51
|
+
const filesize = (_a = attachment.meta.size) !== null && _a !== void 0 ? _a : 0;
|
|
52
|
+
const estimatedDurationMs = await estimateProcessingDuration({
|
|
53
|
+
filetype: attachment.type,
|
|
54
|
+
filesize,
|
|
55
|
+
});
|
|
56
|
+
await setMediaProcessingMeta(mediaAttachmentId, {
|
|
57
|
+
startedAt: Date.now(),
|
|
58
|
+
estimatedDurationMs,
|
|
59
|
+
});
|
|
60
|
+
await publishMediaProgress(mediaAttachmentId, 'started');
|
|
61
|
+
try {
|
|
62
|
+
await runProcessing({
|
|
63
|
+
mediaAttachmentId,
|
|
64
|
+
sourceStorageKey: fileStorageKey,
|
|
65
|
+
});
|
|
66
|
+
await publishMediaProgress(mediaAttachmentId, 'ready');
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
70
|
+
log.error(`Media processing job failed for ${mediaAttachmentId}: ${message}`);
|
|
71
|
+
// `runProcessing` marks the doc as failed itself, but errors that happen
|
|
72
|
+
// outside of it (e.g. storage fetch) would otherwise leave it stuck in
|
|
73
|
+
// `processing`. Update is idempotent so calling it twice is safe.
|
|
74
|
+
await updateMediaAttachment(mediaAttachmentId, {
|
|
75
|
+
status: 'failed',
|
|
76
|
+
error: message,
|
|
77
|
+
}).catch((e) => log.error('Failed to mark media as failed in worker', e));
|
|
78
|
+
await publishMediaProgress(mediaAttachmentId, 'failed');
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
await clearMediaProcessingMeta(mediaAttachmentId).catch((e) => log.error('Failed to clear processing meta', e));
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
defaultJobOptions: {
|
|
86
|
+
removeOnComplete: { age: 3600 },
|
|
87
|
+
removeOnFail: { age: 86400 * 7, count: 50 },
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
export { mediaProcessingQueue, mediaProcessingWorker };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
2
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
3
|
+
var m = o[Symbol.asyncIterator], i;
|
|
4
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
5
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
6
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
7
|
+
};
|
|
8
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
9
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
10
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
11
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
12
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
13
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
14
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
15
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
16
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
17
|
+
function fulfill(value) { resume("next", value); }
|
|
18
|
+
function reject(value) { resume("throw", value); }
|
|
19
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
20
|
+
};
|
|
21
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
22
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
23
|
+
import fs from 'node:fs/promises';
|
|
24
|
+
import { Readable } from 'node:stream';
|
|
25
|
+
import { pipeline } from 'node:stream/promises';
|
|
26
|
+
import { serverRootUrl } from '../../server/index.js';
|
|
27
|
+
const allpeepStorage = async (params) => {
|
|
28
|
+
const { path } = params;
|
|
29
|
+
const storagePath = path + '/allpeep';
|
|
30
|
+
await fs.mkdir(storagePath, { recursive: true });
|
|
31
|
+
const rootUrl = await serverRootUrl();
|
|
32
|
+
/**
|
|
33
|
+
* Streaming sibling of {@link MediaStorage.store}. Consumes the incoming web
|
|
34
|
+
* `ReadableStream` chunk-by-chunk, writing each chunk straight to a temp
|
|
35
|
+
* file in `storagePath` while feeding the same bytes into a SHA-256 digest.
|
|
36
|
+
* Once the stream completes the temp file is atomically renamed to its
|
|
37
|
+
* content-addressed final name. This keeps peak memory bounded by the
|
|
38
|
+
* highWaterMark of the write stream rather than the size of the upload.
|
|
39
|
+
*
|
|
40
|
+
* The type is sourced from {@link MediaStorage} so the implementation tracks
|
|
41
|
+
* the interface's `ReadableStream` lib choice exactly — global vs.
|
|
42
|
+
* `node:stream/web` resolution differs between packages and trying to
|
|
43
|
+
* re-declare the parameter type here causes assignability errors.
|
|
44
|
+
*/
|
|
45
|
+
const storeStream = async (stream) => {
|
|
46
|
+
const tempPath = `${storagePath}/.tmp-${randomBytes(16).toString('hex')}`;
|
|
47
|
+
const hash = createHash('sha256');
|
|
48
|
+
let size = 0;
|
|
49
|
+
const source = Readable.fromWeb(stream);
|
|
50
|
+
try {
|
|
51
|
+
await pipeline(source, function (input) {
|
|
52
|
+
return __asyncGenerator(this, arguments, function* () {
|
|
53
|
+
var _a, e_1, _b, _c;
|
|
54
|
+
try {
|
|
55
|
+
for (var _d = true, input_1 = __asyncValues(input), input_1_1; input_1_1 = yield __await(input_1.next()), _a = input_1_1.done, !_a; _d = true) {
|
|
56
|
+
_c = input_1_1.value;
|
|
57
|
+
_d = false;
|
|
58
|
+
const chunk = _c;
|
|
59
|
+
// pipeline can yield Buffer or string depending on encoding; force
|
|
60
|
+
// through the Buffer path so the hash and byte count are correct.
|
|
61
|
+
const buf = chunk instanceof Buffer
|
|
62
|
+
? chunk
|
|
63
|
+
: Buffer.from(chunk);
|
|
64
|
+
hash.update(buf);
|
|
65
|
+
size += buf.length;
|
|
66
|
+
yield yield __await(buf);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
70
|
+
finally {
|
|
71
|
+
try {
|
|
72
|
+
if (!_d && !_a && (_b = input_1.return)) yield __await(_b.call(input_1));
|
|
73
|
+
}
|
|
74
|
+
finally { if (e_1) throw e_1.error; }
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}, createWriteStream(tempPath));
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
await fs.unlink(tempPath).catch(() => { });
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
const key = hash.digest('base64url');
|
|
84
|
+
const finalPath = `${storagePath}/${key}`;
|
|
85
|
+
try {
|
|
86
|
+
// POSIX rename is atomic and silently overwrites a same-content
|
|
87
|
+
// (same-hash) sibling, giving us free deduplication.
|
|
88
|
+
await fs.rename(tempPath, finalPath);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
await fs.unlink(tempPath).catch(() => { });
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
return { key, size };
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Streaming reader sibling of {@link MediaStorage.getStream}.
|
|
98
|
+
*
|
|
99
|
+
* Uses `createReadStream` rather than `fs.open(...).readableWebStream()`:
|
|
100
|
+
* the latter hands the FileHandle to the stream but immediately drops the
|
|
101
|
+
* only reference to it, so on Node ≥22 the FileHandle can be
|
|
102
|
+
* garbage-collected before the stream drains — Node emits a DEP0137
|
|
103
|
+
* deprecation warning ("Closing a FileHandle object on garbage
|
|
104
|
+
* collection") and a future major will throw outright. `createReadStream`
|
|
105
|
+
* owns its file descriptor and closes it deterministically on `'end'` or
|
|
106
|
+
* `'error'` (`autoClose` defaults to true).
|
|
107
|
+
*
|
|
108
|
+
* Bound to the interface type via `MediaStorage['getStream']` so the cast
|
|
109
|
+
* lands in the same place as `storeStream` does for the input direction —
|
|
110
|
+
* `Readable.toWeb` returns a `node:stream/web.ReadableStream` which is
|
|
111
|
+
* structurally identical to the DOM lib's `ReadableStream` but rejected by
|
|
112
|
+
* TypeScript across the boundary.
|
|
113
|
+
*/
|
|
114
|
+
const getStream = async (id) => Readable.toWeb(createReadStream(storagePath + '/' + id));
|
|
115
|
+
return {
|
|
116
|
+
store: async (data) => {
|
|
117
|
+
const hash = Buffer.from(await crypto.subtle.digest('SHA-256', data)).toString('base64url');
|
|
118
|
+
await fs.writeFile(storagePath + '/' + hash, Buffer.from(data));
|
|
119
|
+
return hash;
|
|
120
|
+
},
|
|
121
|
+
storeStream,
|
|
122
|
+
getPath: (id, filename) => `${rootUrl}${params.prefix}/allpeep/${id}/${filename}`,
|
|
123
|
+
getStream,
|
|
124
|
+
getData: async (id) => {
|
|
125
|
+
const data = await fs.readFile(storagePath + '/' + id);
|
|
126
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
127
|
+
},
|
|
128
|
+
isLocal: () => true,
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export default allpeepStorage;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MediaAttachment } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const SYNC_PROCESSING_LIMIT: number;
|
|
3
|
+
export interface RunProcessingInput {
|
|
4
|
+
mediaAttachmentId: string;
|
|
5
|
+
/**
|
|
6
|
+
* Content-addressed storage key of the already-stored source bytes. Both the
|
|
7
|
+
* HTTP sync path and the worker store the upload first, then hand off the
|
|
8
|
+
* key — the bytes are streamed off disk here, never buffered.
|
|
9
|
+
*/
|
|
10
|
+
sourceStorageKey: string;
|
|
11
|
+
thumbnail?: File;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Transcode + generate a preview for an attachment, working entirely with
|
|
15
|
+
* on-disk temp files so a large upload is never held in memory. Source bytes
|
|
16
|
+
* are streamed to a temp file, ffmpeg/sharp read and write files directly, and
|
|
17
|
+
* the outputs are streamed back into storage. All temps are removed afterwards.
|
|
18
|
+
*/
|
|
19
|
+
export declare const runProcessing: (input: RunProcessingInput) => Promise<MediaAttachment>;
|