-function addVideo (req, res, videoFile, finalCallback) {
- const videoInfos = req.body
-
- waterfall([
-
- startSerializableTransaction,
-
- function findOrCreateAuthor (t, callback) {
- const user = res.locals.oauth.token.User
-
- const name = user.username
- // null because it is OUR pod
- const podId = null
- const userId = user.id
-
- db.Author.findOrCreateAuthor(name, podId, userId, t, function (err, authorInstance) {
- return callback(err, t, authorInstance)
- })
- },
-
- function findOrCreateTags (t, author, callback) {
- const tags = videoInfos.tags
-
- db.Tag.findOrCreateTags(tags, t, function (err, tagInstances) {
- return callback(err, t, author, tagInstances)
- })
- },
-
- function createVideoObject (t, author, tagInstances, callback) {
- const videoData = {
- name: videoInfos.name,
- remoteId: null,
- extname: path.extname(videoFile.filename),
- category: videoInfos.category,
- licence: videoInfos.licence,
- language: videoInfos.language,
- nsfw: videoInfos.nsfw,
- description: videoInfos.description,
- duration: videoFile.duration,
- authorId: author.id
- }
-
- const video = db.Video.build(videoData)
+async function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) {
+ const videoInfo: VideoCreate = req.body
+
+ // Prepare data so we don't block the transaction
+ const videoData = {
+ name: videoInfo.name,
+ remote: false,
+ extname: extname(videoPhysicalFile.filename),
+ category: videoInfo.category,
+ licence: videoInfo.licence,
+ language: videoInfo.language,
+ nsfw: videoInfo.nsfw,
+ description: videoInfo.description,
+ privacy: videoInfo.privacy,
+ duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
+ channelId: res.locals.videoChannel.id
+ }
+ const video = new VideoModel(videoData)
+ video.url = getVideoActivityPubUrl(video)