@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,83 @@
|
|
|
1
|
+
import { unlink } from 'node:fs/promises';
|
|
2
|
+
import { findMediaAttachment, updateMediaAttachment, } from '../mediaAttachments/index.js';
|
|
3
|
+
import { recordProcessingStats } from '../processingStats/index.js';
|
|
4
|
+
import { logger } from '../log/index.js';
|
|
5
|
+
import { withSpan } from '../performance/index.js';
|
|
6
|
+
import { mediaStorage, transcodeIncomingMedia, createPreview, storeFromPath, writeStorageToTemp, writeStreamToTemp, } from './index.js';
|
|
7
|
+
const log = logger('app:media:processing');
|
|
8
|
+
export const SYNC_PROCESSING_LIMIT = Number(process.env.MEDIA_SYNC_PROCESSING_LIMIT || 1024 * 1024);
|
|
9
|
+
/**
|
|
10
|
+
* Transcode + generate a preview for an attachment, working entirely with
|
|
11
|
+
* on-disk temp files so a large upload is never held in memory. Source bytes
|
|
12
|
+
* are streamed to a temp file, ffmpeg/sharp read and write files directly, and
|
|
13
|
+
* the outputs are streamed back into storage. All temps are removed afterwards.
|
|
14
|
+
*/
|
|
15
|
+
export const runProcessing = async (input) => withSpan('worker.media.processing', () => runProcessingBody(input), {
|
|
16
|
+
mediaAttachmentId: input.mediaAttachmentId,
|
|
17
|
+
});
|
|
18
|
+
const runProcessingBody = async ({ mediaAttachmentId, sourceStorageKey, thumbnail, }) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const startedAt = Date.now();
|
|
21
|
+
const attachment = await findMediaAttachment(mediaAttachmentId);
|
|
22
|
+
if (!attachment) {
|
|
23
|
+
throw new Error(`MediaAttachment ${mediaAttachmentId} not found`);
|
|
24
|
+
}
|
|
25
|
+
const filetype = attachment.type;
|
|
26
|
+
const originalName = attachment.filename;
|
|
27
|
+
const sourceMimetype = (_a = attachment.meta.mimetype) !== null && _a !== void 0 ? _a : '';
|
|
28
|
+
const temps = new Set();
|
|
29
|
+
try {
|
|
30
|
+
const storage = await mediaStorage();
|
|
31
|
+
const sourcePath = await writeStorageToTemp(sourceStorageKey, originalName);
|
|
32
|
+
temps.add(sourcePath);
|
|
33
|
+
const transcoded = await transcodeIncomingMedia(filetype, sourcePath, originalName, sourceMimetype);
|
|
34
|
+
if (transcoded.path !== sourcePath)
|
|
35
|
+
temps.add(transcoded.path);
|
|
36
|
+
const { key: fileStorageKey, size: storedSize } = await storeFromPath(transcoded.path);
|
|
37
|
+
let previewInputPath = sourcePath;
|
|
38
|
+
let previewMimetype = sourceMimetype;
|
|
39
|
+
let previewName = originalName;
|
|
40
|
+
if (thumbnail) {
|
|
41
|
+
previewInputPath = await writeStreamToTemp(thumbnail.stream(), thumbnail.name);
|
|
42
|
+
temps.add(previewInputPath);
|
|
43
|
+
previewMimetype = thumbnail.type;
|
|
44
|
+
previewName = thumbnail.name;
|
|
45
|
+
}
|
|
46
|
+
const preview = await createPreview(previewInputPath, previewMimetype, previewName);
|
|
47
|
+
if (preview.path !== sourcePath && preview.path !== previewInputPath) {
|
|
48
|
+
temps.add(preview.path);
|
|
49
|
+
}
|
|
50
|
+
const { key: previewStorageKey } = await storeFromPath(preview.path);
|
|
51
|
+
const normalizedFilename = encodeURIComponent(transcoded.filename);
|
|
52
|
+
const thumbnailFilename = `thumbnail-${normalizedFilename}${normalizedFilename.endsWith('.webp') ? '' : '.webp'}`;
|
|
53
|
+
const url = storage.getPath(fileStorageKey, normalizedFilename);
|
|
54
|
+
const previewUrl = storage.getPath(previewStorageKey, thumbnailFilename);
|
|
55
|
+
const updated = await updateMediaAttachment(mediaAttachmentId, {
|
|
56
|
+
url,
|
|
57
|
+
previewUrl,
|
|
58
|
+
meta: Object.assign(Object.assign({}, attachment.meta), { mimetype: transcoded.mimetype, size: storedSize }),
|
|
59
|
+
status: 'ready',
|
|
60
|
+
error: undefined,
|
|
61
|
+
});
|
|
62
|
+
const durationMs = Date.now() - startedAt;
|
|
63
|
+
await recordProcessingStats({
|
|
64
|
+
mediaAttachmentId,
|
|
65
|
+
filesize: (_b = attachment.meta.size) !== null && _b !== void 0 ? _b : storedSize,
|
|
66
|
+
filetype,
|
|
67
|
+
durationMs,
|
|
68
|
+
}).catch((e) => log.error('Failed to record processing stats', e));
|
|
69
|
+
return updated;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
73
|
+
log.error(`Processing failed for media ${mediaAttachmentId}: ${message}`);
|
|
74
|
+
await updateMediaAttachment(mediaAttachmentId, {
|
|
75
|
+
status: 'failed',
|
|
76
|
+
error: message,
|
|
77
|
+
}).catch((e) => log.error('Failed to mark media as failed', e));
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
await Promise.all([...temps].map((p) => unlink(p).catch(() => undefined)));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { MediaStream, MediaStreamStatus } from '@openpeepshq/common/types';
|
|
2
|
+
export declare const HLS_MASTER_PLAYLIST = "hls.m3u8";
|
|
3
|
+
export declare const HLS_ERRORS_LOG = "errors.log";
|
|
4
|
+
/**
|
|
5
|
+
* Returns the on-disk directory used to hold the HLS output for the given
|
|
6
|
+
* source storage id. The directory may or may not exist yet — callers must
|
|
7
|
+
* check before reading from it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getStreamDir: (storageId: string) => Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Extracts the local storage id from a media url that points to this
|
|
12
|
+
* server's `/<prefix>/allpeep/<id>/<filename>` route. Returns `null` for any
|
|
13
|
+
* url that does not match — including urls pointing at other hosts or urls
|
|
14
|
+
* that match the right shape but a different storage driver.
|
|
15
|
+
*/
|
|
16
|
+
export declare const parseLocalStorageUrl: (rawUrl: string) => Promise<string | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Joins a (potentially user-supplied) sub-path under the stream directory and
|
|
19
|
+
* guarantees the result is contained within `streamDir`. Returns `null` if the
|
|
20
|
+
* normalised path would escape the directory or references suspicious
|
|
21
|
+
* components.
|
|
22
|
+
*/
|
|
23
|
+
export declare const resolveStreamFile: (streamDir: string, relativePath: string) => string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Inspects the stream directory on disk to decide the current status.
|
|
26
|
+
*
|
|
27
|
+
* - `errors.log` present → `error` (transcoding failed and left a message)
|
|
28
|
+
* - master playlist (`hls.m3u8`) present → `ready`
|
|
29
|
+
* - otherwise → `processing` (the job is still running, or was interrupted)
|
|
30
|
+
*
|
|
31
|
+
* Returns `null` if the stream directory does not exist at all.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getStreamStatus: (storageId: string) => Promise<{
|
|
34
|
+
status: MediaStreamStatus;
|
|
35
|
+
error?: string;
|
|
36
|
+
} | null>;
|
|
37
|
+
export declare const buildStream: (storageId: string) => Promise<MediaStream | null>;
|
|
38
|
+
export declare const ensureStreamDir: (storageId: string) => Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Records that the given stream was accessed at the current wall-clock time.
|
|
41
|
+
*
|
|
42
|
+
* Backed by a Redis sorted set keyed by storage id with timestamps as scores —
|
|
43
|
+
* keeping it in one key (vs. one key per stream) makes the daily cleanup job
|
|
44
|
+
* a single `ZRANGEBYSCORE` instead of a `SCAN`.
|
|
45
|
+
*
|
|
46
|
+
* In-process debounced to one write per stream per
|
|
47
|
+
* {@link ACCESS_WRITE_DEBOUNCE_MS} window. HLS playback fetches many segments
|
|
48
|
+
* per minute; a write per segment would saturate the Redis pipe for no
|
|
49
|
+
* meaningful precision win — the cleanup window is measured in days.
|
|
50
|
+
*
|
|
51
|
+
* Errors are swallowed and logged: this is a best-effort signal for cleanup
|
|
52
|
+
* and must never break the file-serving path that calls it.
|
|
53
|
+
*/
|
|
54
|
+
export declare const recordStreamAccess: (storageId: string) => Promise<void>;
|
|
55
|
+
export declare const getStreamLastAccess: (storageId: string) => Promise<number | null>;
|
|
56
|
+
export interface CleanupResult {
|
|
57
|
+
deleted: string[];
|
|
58
|
+
kept: number;
|
|
59
|
+
skipped: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Deletes every stream directory whose Redis-recorded last-access time is
|
|
63
|
+
* older than `maxAgeMs`, or which has no Redis entry at all. A missing entry
|
|
64
|
+
* means the stream was never accessed since the last Redis wipe — HLS
|
|
65
|
+
* directories are a cache derived from the source media, so treating "no
|
|
66
|
+
* record" as "evictable" is safe: anything actually being used will have been
|
|
67
|
+
* touched by the POST handler or the file-serving route already.
|
|
68
|
+
*
|
|
69
|
+
* Note: this implies a Redis wipe causes the next cleanup run to delete
|
|
70
|
+
* every existing stream. That's intentional. The streams will be lazily
|
|
71
|
+
* regenerated on the next POST.
|
|
72
|
+
*
|
|
73
|
+
* Directories whose name fails {@link isValidStorageId} are left alone —
|
|
74
|
+
* those are foreign files placed in the hls root by the operator and must
|
|
75
|
+
* never be touched by automated cleanup.
|
|
76
|
+
*/
|
|
77
|
+
export declare const cleanupStaleStreams: (maxAgeMs: number) => Promise<CleanupResult>;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { join, normalize, sep } from 'node:path';
|
|
4
|
+
import { config } from '../config/index.js';
|
|
5
|
+
import { logger } from '../log/index.js';
|
|
6
|
+
import { getSharedConnection } from '../redis/connection.js';
|
|
7
|
+
import { serverRootUrl } from '../server/index.js';
|
|
8
|
+
const log = logger('app:media:streaming');
|
|
9
|
+
export const HLS_MASTER_PLAYLIST = 'hls.m3u8';
|
|
10
|
+
export const HLS_ERRORS_LOG = 'errors.log';
|
|
11
|
+
const STREAM_ACCESS_KEY = 'media:streaming:lastAccess';
|
|
12
|
+
// One write per stream per minute is plenty — HLS playback will fetch many
|
|
13
|
+
// segments and we don't need to hammer Redis with a write for each. The
|
|
14
|
+
// debounce is per-process; multiple app/worker processes will each issue at
|
|
15
|
+
// most one write per window which is still fine.
|
|
16
|
+
const ACCESS_WRITE_DEBOUNCE_MS = 60000;
|
|
17
|
+
const lastAccessWriteCache = new Map();
|
|
18
|
+
const getStorageParams = async () => (await config()).media.storage.params;
|
|
19
|
+
const getHlsRoot = async () => {
|
|
20
|
+
const params = await getStorageParams();
|
|
21
|
+
return join(params.path, 'hls');
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Returns the on-disk directory used to hold the HLS output for the given
|
|
25
|
+
* source storage id. The directory may or may not exist yet — callers must
|
|
26
|
+
* check before reading from it.
|
|
27
|
+
*/
|
|
28
|
+
export const getStreamDir = async (storageId) => {
|
|
29
|
+
const hlsRoot = await getHlsRoot();
|
|
30
|
+
return join(hlsRoot, storageId);
|
|
31
|
+
};
|
|
32
|
+
const isValidStorageId = (storageId) => {
|
|
33
|
+
// Source storage ids in this codebase are content-addressed base64url SHA-256
|
|
34
|
+
// digests. Restrict to the same alphabet so that an attacker can never use
|
|
35
|
+
// path traversal characters (`/`, `..`, `\0`, etc.) to escape the streaming
|
|
36
|
+
// root.
|
|
37
|
+
return /^[A-Za-z0-9_-]{1,128}$/.test(storageId);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Extracts the local storage id from a media url that points to this
|
|
41
|
+
* server's `/<prefix>/allpeep/<id>/<filename>` route. Returns `null` for any
|
|
42
|
+
* url that does not match — including urls pointing at other hosts or urls
|
|
43
|
+
* that match the right shape but a different storage driver.
|
|
44
|
+
*/
|
|
45
|
+
export const parseLocalStorageUrl = async (rawUrl) => {
|
|
46
|
+
let url;
|
|
47
|
+
try {
|
|
48
|
+
url = new URL(rawUrl);
|
|
49
|
+
}
|
|
50
|
+
catch (_a) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const rootUrl = await serverRootUrl();
|
|
54
|
+
const root = new URL(rootUrl);
|
|
55
|
+
// Compare host loosely — protocol may differ between requests behind a
|
|
56
|
+
// reverse proxy, and a port mismatch is also tolerated as long as the host
|
|
57
|
+
// matches the configured server host.
|
|
58
|
+
if (url.host !== root.host && url.hostname !== root.hostname) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const params = await getStorageParams();
|
|
62
|
+
const prefix = params.prefix.replace(/\/+$/, '');
|
|
63
|
+
const expectedPrefix = `${prefix}/allpeep/`;
|
|
64
|
+
if (!url.pathname.startsWith(expectedPrefix)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const rest = url.pathname.slice(expectedPrefix.length);
|
|
68
|
+
const [storageId] = rest.split('/');
|
|
69
|
+
if (!storageId || !isValidStorageId(storageId)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return storageId;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Joins a (potentially user-supplied) sub-path under the stream directory and
|
|
76
|
+
* guarantees the result is contained within `streamDir`. Returns `null` if the
|
|
77
|
+
* normalised path would escape the directory or references suspicious
|
|
78
|
+
* components.
|
|
79
|
+
*/
|
|
80
|
+
export const resolveStreamFile = (streamDir, relativePath) => {
|
|
81
|
+
if (!relativePath || relativePath.includes('\0')) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const normalisedRelative = normalize(relativePath);
|
|
85
|
+
if (normalisedRelative.startsWith('..') ||
|
|
86
|
+
normalisedRelative.includes(`${sep}..${sep}`) ||
|
|
87
|
+
normalisedRelative === '..') {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const full = join(streamDir, normalisedRelative);
|
|
91
|
+
const normalisedStreamDir = normalize(streamDir);
|
|
92
|
+
if (full !== normalisedStreamDir &&
|
|
93
|
+
!full.startsWith(normalisedStreamDir + sep)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return full;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Inspects the stream directory on disk to decide the current status.
|
|
100
|
+
*
|
|
101
|
+
* - `errors.log` present → `error` (transcoding failed and left a message)
|
|
102
|
+
* - master playlist (`hls.m3u8`) present → `ready`
|
|
103
|
+
* - otherwise → `processing` (the job is still running, or was interrupted)
|
|
104
|
+
*
|
|
105
|
+
* Returns `null` if the stream directory does not exist at all.
|
|
106
|
+
*/
|
|
107
|
+
export const getStreamStatus = async (storageId) => {
|
|
108
|
+
if (!isValidStorageId(storageId)) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const streamDir = await getStreamDir(storageId);
|
|
112
|
+
try {
|
|
113
|
+
const stat = await fs.stat(streamDir);
|
|
114
|
+
if (!stat.isDirectory()) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (_a) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const errorsPath = join(streamDir, HLS_ERRORS_LOG);
|
|
122
|
+
if (existsSync(errorsPath)) {
|
|
123
|
+
let error;
|
|
124
|
+
try {
|
|
125
|
+
error = (await fs.readFile(errorsPath, 'utf8')).trim() || undefined;
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
log.warn(`Failed to read ${errorsPath}: ${e.message}`);
|
|
129
|
+
}
|
|
130
|
+
return { status: 'error', error };
|
|
131
|
+
}
|
|
132
|
+
const masterPath = join(streamDir, HLS_MASTER_PLAYLIST);
|
|
133
|
+
if (existsSync(masterPath)) {
|
|
134
|
+
return { status: 'ready' };
|
|
135
|
+
}
|
|
136
|
+
return { status: 'processing' };
|
|
137
|
+
};
|
|
138
|
+
export const buildStream = async (storageId) => {
|
|
139
|
+
const status = await getStreamStatus(storageId);
|
|
140
|
+
if (!status) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return Object.assign({ storageId }, status);
|
|
144
|
+
};
|
|
145
|
+
export const ensureStreamDir = async (storageId) => {
|
|
146
|
+
const streamDir = await getStreamDir(storageId);
|
|
147
|
+
await fs.mkdir(streamDir, { recursive: true });
|
|
148
|
+
return streamDir;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Records that the given stream was accessed at the current wall-clock time.
|
|
152
|
+
*
|
|
153
|
+
* Backed by a Redis sorted set keyed by storage id with timestamps as scores —
|
|
154
|
+
* keeping it in one key (vs. one key per stream) makes the daily cleanup job
|
|
155
|
+
* a single `ZRANGEBYSCORE` instead of a `SCAN`.
|
|
156
|
+
*
|
|
157
|
+
* In-process debounced to one write per stream per
|
|
158
|
+
* {@link ACCESS_WRITE_DEBOUNCE_MS} window. HLS playback fetches many segments
|
|
159
|
+
* per minute; a write per segment would saturate the Redis pipe for no
|
|
160
|
+
* meaningful precision win — the cleanup window is measured in days.
|
|
161
|
+
*
|
|
162
|
+
* Errors are swallowed and logged: this is a best-effort signal for cleanup
|
|
163
|
+
* and must never break the file-serving path that calls it.
|
|
164
|
+
*/
|
|
165
|
+
export const recordStreamAccess = async (storageId) => {
|
|
166
|
+
if (!isValidStorageId(storageId))
|
|
167
|
+
return;
|
|
168
|
+
const now = Date.now();
|
|
169
|
+
const lastWrite = lastAccessWriteCache.get(storageId);
|
|
170
|
+
if (lastWrite !== undefined && now - lastWrite < ACCESS_WRITE_DEBOUNCE_MS) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
lastAccessWriteCache.set(storageId, now);
|
|
174
|
+
try {
|
|
175
|
+
const conn = await getSharedConnection();
|
|
176
|
+
await conn.zAdd(STREAM_ACCESS_KEY, { score: now, value: storageId });
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
log.warn(`Failed to record stream access for ${storageId}: ${e.message}`);
|
|
180
|
+
// Roll back the cache entry so the next request will retry.
|
|
181
|
+
lastAccessWriteCache.delete(storageId);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
export const getStreamLastAccess = async (storageId) => {
|
|
185
|
+
if (!isValidStorageId(storageId))
|
|
186
|
+
return null;
|
|
187
|
+
const conn = await getSharedConnection();
|
|
188
|
+
const score = await conn.zScore(STREAM_ACCESS_KEY, storageId);
|
|
189
|
+
return typeof score === 'number' ? score : null;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Deletes every stream directory whose Redis-recorded last-access time is
|
|
193
|
+
* older than `maxAgeMs`, or which has no Redis entry at all. A missing entry
|
|
194
|
+
* means the stream was never accessed since the last Redis wipe — HLS
|
|
195
|
+
* directories are a cache derived from the source media, so treating "no
|
|
196
|
+
* record" as "evictable" is safe: anything actually being used will have been
|
|
197
|
+
* touched by the POST handler or the file-serving route already.
|
|
198
|
+
*
|
|
199
|
+
* Note: this implies a Redis wipe causes the next cleanup run to delete
|
|
200
|
+
* every existing stream. That's intentional. The streams will be lazily
|
|
201
|
+
* regenerated on the next POST.
|
|
202
|
+
*
|
|
203
|
+
* Directories whose name fails {@link isValidStorageId} are left alone —
|
|
204
|
+
* those are foreign files placed in the hls root by the operator and must
|
|
205
|
+
* never be touched by automated cleanup.
|
|
206
|
+
*/
|
|
207
|
+
export const cleanupStaleStreams = async (maxAgeMs) => {
|
|
208
|
+
const hlsRoot = await getHlsRoot();
|
|
209
|
+
let entries;
|
|
210
|
+
try {
|
|
211
|
+
entries = await fs.readdir(hlsRoot);
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
if (e.code === 'ENOENT') {
|
|
215
|
+
return { deleted: [], kept: 0, skipped: [] };
|
|
216
|
+
}
|
|
217
|
+
throw e;
|
|
218
|
+
}
|
|
219
|
+
const cutoff = Date.now() - maxAgeMs;
|
|
220
|
+
const conn = await getSharedConnection();
|
|
221
|
+
const result = { deleted: [], kept: 0, skipped: [] };
|
|
222
|
+
for (const name of entries) {
|
|
223
|
+
const fullPath = join(hlsRoot, name);
|
|
224
|
+
let stat;
|
|
225
|
+
try {
|
|
226
|
+
stat = await fs.stat(fullPath);
|
|
227
|
+
}
|
|
228
|
+
catch (_a) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (!stat.isDirectory())
|
|
232
|
+
continue;
|
|
233
|
+
if (!isValidStorageId(name)) {
|
|
234
|
+
result.skipped.push(name);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const redisAccess = await conn
|
|
238
|
+
.zScore(STREAM_ACCESS_KEY, name)
|
|
239
|
+
.catch(() => null);
|
|
240
|
+
const lastAccess = typeof redisAccess === 'number' ? redisAccess : 0;
|
|
241
|
+
if (lastAccess < cutoff) {
|
|
242
|
+
try {
|
|
243
|
+
await fs.rm(fullPath, { recursive: true, force: true });
|
|
244
|
+
await conn.zRem(STREAM_ACCESS_KEY, name);
|
|
245
|
+
lastAccessWriteCache.delete(name);
|
|
246
|
+
result.deleted.push(name);
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
log.error(`Failed to delete stale stream ${name}: ${e.message}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
result.kept++;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const STREAM_INACTIVITY_TTL_MS: number;
|
|
2
|
+
export declare const STREAM_CLEANUP_CRON = "0 3 * * *";
|
|
3
|
+
export interface MediaStreamingCleanupJobData {
|
|
4
|
+
/** Override the inactivity threshold; mostly for testing. */
|
|
5
|
+
maxAgeMs?: number;
|
|
6
|
+
}
|
|
7
|
+
declare const mediaStreamingCleanupQueue: () => import("bullmq").Queue, mediaStreamingCleanupWorker: () => import("bullmq").Worker;
|
|
8
|
+
/**
|
|
9
|
+
* Registers (or refreshes) the daily cleanup schedule with BullMQ. Safe to
|
|
10
|
+
* call repeatedly — `upsertJobScheduler` is idempotent and overwrites the
|
|
11
|
+
* existing schedule entry under the same id.
|
|
12
|
+
*/
|
|
13
|
+
export declare const ensureStreamingCleanupSchedule: () => Promise<void>;
|
|
14
|
+
export { mediaStreamingCleanupQueue, mediaStreamingCleanupWorker };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { queueAndWorker } from '../jobs/index.js';
|
|
2
|
+
import { logger } from '../log/index.js';
|
|
3
|
+
import { cleanupStaleStreams } from './streaming.js';
|
|
4
|
+
const log = logger('app:media:streamingCleanupJobs');
|
|
5
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
export const STREAM_INACTIVITY_TTL_MS = 7 * DAY_MS;
|
|
7
|
+
// Cron pattern (UTC): every day at 03:00. Off-peak for most regions and
|
|
8
|
+
// staggered away from other daily housekeeping the platform may run.
|
|
9
|
+
export const STREAM_CLEANUP_CRON = '0 3 * * *';
|
|
10
|
+
const SCHEDULER_ID = 'streaming-cleanup-daily';
|
|
11
|
+
const JOB_NAME = 'cleanup';
|
|
12
|
+
const [mediaStreamingCleanupQueue, mediaStreamingCleanupWorker] = queueAndWorker('media-streaming-cleanup', async (job) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const maxAgeMs = (_a = job.data.maxAgeMs) !== null && _a !== void 0 ? _a : STREAM_INACTIVITY_TTL_MS;
|
|
15
|
+
log.info(`Running stream cleanup (maxAgeMs=${maxAgeMs}, ~${Math.round(maxAgeMs / DAY_MS)}d)`);
|
|
16
|
+
const result = await cleanupStaleStreams(maxAgeMs);
|
|
17
|
+
log.info(`Stream cleanup done: deleted=${result.deleted.length}, ` +
|
|
18
|
+
`kept=${result.kept}, skipped=${result.skipped.length}`);
|
|
19
|
+
if (result.deleted.length > 0) {
|
|
20
|
+
log.info(`Deleted streams: ${result.deleted.join(', ')}`);
|
|
21
|
+
}
|
|
22
|
+
if (result.skipped.length > 0) {
|
|
23
|
+
// These are entries in the hls root that don't match the storage-id
|
|
24
|
+
// shape (e.g. an operator-placed file). Surface them so they can be
|
|
25
|
+
// cleaned up by hand instead of silently lingering forever.
|
|
26
|
+
log.warn(`Skipped non-storage-id entries in hls root: ${result.skipped.join(', ')}`);
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
defaultJobOptions: {
|
|
30
|
+
// We never need more than the most recent run; keep a small history
|
|
31
|
+
// for debugging and let BullMQ trim the rest.
|
|
32
|
+
removeOnComplete: { count: 10 },
|
|
33
|
+
removeOnFail: { age: 86400 * 14, count: 50 },
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Registers (or refreshes) the daily cleanup schedule with BullMQ. Safe to
|
|
38
|
+
* call repeatedly — `upsertJobScheduler` is idempotent and overwrites the
|
|
39
|
+
* existing schedule entry under the same id.
|
|
40
|
+
*/
|
|
41
|
+
export const ensureStreamingCleanupSchedule = async () => {
|
|
42
|
+
const queue = mediaStreamingCleanupQueue();
|
|
43
|
+
await queue.upsertJobScheduler(SCHEDULER_ID, { pattern: STREAM_CLEANUP_CRON }, { name: JOB_NAME });
|
|
44
|
+
log.info(`Streaming cleanup schedule registered: cron="${STREAM_CLEANUP_CRON}" ` +
|
|
45
|
+
`ttl=${Math.round(STREAM_INACTIVITY_TTL_MS / DAY_MS)}d`);
|
|
46
|
+
};
|
|
47
|
+
export { mediaStreamingCleanupQueue, mediaStreamingCleanupWorker };
|