Sequelize models contain optional fields corresponding to table joins.
For example, VideoModel has a VideoChannel?: VideoChannelModel field. It can be filled if the SQL query joined with the videoChannel table or empty if not.
It can be difficult in TypeScript to understand if a function argument expects associations to be filled or not.
To improve clarity and reduce bugs, PeerTube defines multiple versions of a database model depending on its associations in server/core/types/models/.
These models start with M and by default do not include any association. MVideo for example corresponds to VideoModel without any association, where VideoChannel attribute doesn’t exist. On the other hand, MVideoWithChannel is a MVideo that has a VideoChannel field. This way, a function that accepts video: MVideoWithChannel argument expects a video with channel populated. Main PeerTube code should never use ...Model (VideoModel) database type, but always M... instead (MVideo, MVideoChannel etc).
Here’s a list of all the parts of the server to update if you want to add a new feature (new API REST endpoints for example) to the PeerTube server.
Some of these may be optional (for example your new endpoint may not need to send notifications) but this guide tries to be exhaustive.
config/default.yaml and config/production.yamlconfig/dev.yaml and config/test.yamlserver/core/initializers/config.tsserver/core/initializers/checker-before-init.tsserver/core/initializers/checker-after-init.tspackages/models/src/server/core/server-config.model.tsserver/core/lib/server-config-manager.ts to include your new configurationpackages/models/src/server/core/custom-config.model.tsserver/core/controllers/api/config.ts controllerserver/core/middlewares/validators that will be used by your controllersserver/core/middlewares/validators/index.ts so it’s easier to importserver/core/types/express.d.ts to attach the database model loaded by your middleware to the express responseserver/core/helpers/custom-validatorspackages/modelsindex.ts of current directory to facilitate the importsserver/core/models/:
@ColumnloadBy...listBy...toFormattedJSON that creates the JSON to send to the REST API from the modelserver/core/initializers/database.tsserver/core/types to define multiple versions of your Sequelize model depending on database associationsserver/core/types/*/index.ts to facilitate the importsserver/core/initializers/migrations using raw SQL (copy the same SQL query as at PeerTube startup)LAST_MIGRATION_VERSION in server/core/initializers/constants.tsserver/core/models/initializers/migrations using Sequelize Query Interface (.addColumn, .dropTable, .changeColumn)LAST_MIGRATION_VERSION in server/core/initializers/constants.tspackages/models/src/users/user-notification.model.tsserver/core/lib/notifier/shared:
server/core/lib/notifier/notifier.tsserver/core/assets/email-templates:
../common/grettings that already says “Hi” and “Cheers”. You just have to write the title and the content blocks that will be inserted in the appropriate places in the HTML templateuserNotification:
UserNotificationModel (don’t forget the index)packages/models/src/users/user-notification.model.ts)UserNotificationModel.toFormattedJSONUserNotificationsComponent)UserNotification)packages/server-commands/ that will wrap HTTP requests to your new endpointindex.ts of current directorypackages/server-commands/src/server/core.tsserver/core/tests/api/check-params to test middleware validators/authentification/user rights (offensive tests)server/core/tests/api/check-params/index.tsserver/core/tests/api to test your new endpointsindex.ts of current directoryserver/core/tests/api/notificationssupport/doc/api/openapi.yaml