From 6bafac54bf375cd60f1c06f6afdc648e0e19743d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Dec 2017 15:01:47 +0100 Subject: Fix missing default avatar --- server/controllers/client.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'server/controllers') diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 64e5829ca..f474c4282 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts @@ -18,6 +18,7 @@ import { VideoInstance } from '../models' const clientsRouter = express.Router() const distPath = join(root(), 'client', 'dist') +const assetsImagesPath = join(root(), 'client', 'dist', 'assets', 'images') const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') const indexPath = join(distPath, 'index.html') @@ -33,6 +34,7 @@ clientsRouter.use('/videos/embed', (req: express.Request, res: express.Response, // Static HTML/CSS/JS client files clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) +clientsRouter.use('/client/assets/images', express.static(assetsImagesPath, { maxAge: STATIC_MAX_AGE })) // 404 for static files not found clientsRouter.use('/client/*', (req: express.Request, res: express.Response, next: express.NextFunction) => { -- cgit v1.2.3 From f3aaa9a95cc2b61f1f255472d7014d08faa66561 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Dec 2017 17:46:33 +0100 Subject: Fix client search --- server/controllers/api/videos/index.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index e2798830e..2b70d535e 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -26,7 +26,6 @@ import { authenticate, paginationValidator, setPagination, - setVideosSearch, setVideosSort, videosAddValidator, videosGetValidator, @@ -84,6 +83,14 @@ videosRouter.get('/', setPagination, asyncMiddleware(listVideos) ) +videosRouter.get('/search', + videosSearchValidator, + paginationValidator, + videosSortValidator, + setVideosSort, + setPagination, + asyncMiddleware(searchVideos) +) videosRouter.put('/:id', authenticate, asyncMiddleware(videosUpdateValidator), @@ -115,16 +122,6 @@ videosRouter.delete('/:id', asyncMiddleware(removeVideoRetryWrapper) ) -videosRouter.get('/search/:value', - videosSearchValidator, - paginationValidator, - videosSortValidator, - setVideosSort, - setPagination, - setVideosSearch, - asyncMiddleware(searchVideos) -) - // --------------------------------------------------------------------------- export { @@ -378,8 +375,7 @@ async function removeVideo (req: express.Request, res: express.Response) { async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { const resultList = await db.Video.searchAndPopulateAccountAndServerAndTags( - req.params.value, - req.query.field, + req.query.search, req.query.start, req.query.count, req.query.sort -- cgit v1.2.3 From cadb46d832724ea1a17b085b992142aa32e212be Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Dec 2017 08:39:15 +0100 Subject: Design second video upload step --- server/controllers/api/videos/index.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 2b70d535e..f427a25c0 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -15,6 +15,7 @@ import { getServerAccount } from '../../../helpers/utils' import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' import { database as db } from '../../../initializers/database' import { sendAddVideo } from '../../../lib/activitypub/send/send-add' +import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create' import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update' import { shareVideoByServer } from '../../../lib/activitypub/share' import { getVideoActivityPubUrl } from '../../../lib/activitypub/url' @@ -39,7 +40,6 @@ import { abuseVideoRouter } from './abuse' import { blacklistRouter } from './blacklist' import { videoChannelRouter } from './channel' import { rateVideoRouter } from './rate' -import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create' const videosRouter = express.Router() @@ -154,17 +154,20 @@ async function addVideoRetryWrapper (req: express.Request, res: express.Response errorMessage: 'Cannot insert the video with many retries.' } - await retryTransactionWrapper(addVideo, options) + const video = await retryTransactionWrapper(addVideo, options) - // TODO : include Location of the new video -> 201 - res.type('json').status(204).end() + res.json({ + video: { + id: video.id, + uuid: video.uuid + } + }).end() } -async function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { +function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { const videoInfo: VideoCreate = req.body - let videoUUID = '' - await db.sequelize.transaction(async t => { + return db.sequelize.transaction(async t => { const sequelizeOptions = { transaction: t } const videoData = { @@ -223,7 +226,6 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi const videoCreated = await video.save(sequelizeOptions) // Do not forget to add video channel information to the created video videoCreated.VideoChannel = res.locals.videoChannel - videoUUID = videoCreated.uuid videoFile.videoId = video.id @@ -238,15 +240,17 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi } // Let transcoding job send the video to friends because the video file extension might change - if (CONFIG.TRANSCODING.ENABLED === true) return undefined + if (CONFIG.TRANSCODING.ENABLED === true) return videoCreated // Don't send video to remote servers, it is private - if (video.privacy === VideoPrivacy.PRIVATE) return undefined + if (video.privacy === VideoPrivacy.PRIVATE) return videoCreated await sendAddVideo(video, t) await shareVideoByServer(video, t) - }) - logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoUUID) + logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid) + + return videoCreated + }) } async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { -- cgit v1.2.3 From e11f68a3562d2468480c396f47f1bdd2a306e17a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Dec 2017 10:08:36 +0100 Subject: Optimise transaction for video upload --- server/controllers/api/videos/index.ts | 87 +++++++++++++++++----------------- 1 file changed, 43 insertions(+), 44 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index f427a25c0..0f71a7f7f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -164,52 +164,54 @@ async function addVideoRetryWrapper (req: express.Request, res: express.Response }).end() } -function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { +async function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { const videoInfo: VideoCreate = req.body - return db.sequelize.transaction(async t => { - const sequelizeOptions = { transaction: t } + // 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 = db.Video.build(videoData) + video.url = getVideoActivityPubUrl(video) - 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 = db.Video.build(videoData) - video.url = getVideoActivityPubUrl(video) + const videoFilePath = join(CONFIG.STORAGE.VIDEOS_DIR, videoPhysicalFile.filename) + const videoFileHeight = await getVideoFileHeight(videoFilePath) - const videoFilePath = join(CONFIG.STORAGE.VIDEOS_DIR, videoPhysicalFile.filename) - const videoFileHeight = await getVideoFileHeight(videoFilePath) + const videoFileData = { + extname: extname(videoPhysicalFile.filename), + resolution: videoFileHeight, + size: videoPhysicalFile.size + } + const videoFile = db.VideoFile.build(videoFileData) + const videoDir = CONFIG.STORAGE.VIDEOS_DIR + const source = join(videoDir, videoPhysicalFile.filename) + const destination = join(videoDir, video.getVideoFilename(videoFile)) - const videoFileData = { - extname: extname(videoPhysicalFile.filename), - resolution: videoFileHeight, - size: videoPhysicalFile.size - } - const videoFile = db.VideoFile.build(videoFileData) - const videoDir = CONFIG.STORAGE.VIDEOS_DIR - const source = join(videoDir, videoPhysicalFile.filename) - const destination = join(videoDir, video.getVideoFilename(videoFile)) + await renamePromise(source, destination) + // This is important in case if there is another attempt in the retry process + videoPhysicalFile.filename = video.getVideoFilename(videoFile) - await renamePromise(source, destination) - // This is important in case if there is another attempt in the retry process - videoPhysicalFile.filename = video.getVideoFilename(videoFile) + const tasks = [] - const tasks = [] + tasks.push( + video.createTorrentAndSetInfoHash(videoFile), + video.createThumbnail(videoFile), + video.createPreview(videoFile) + ) + await Promise.all(tasks) - tasks.push( - video.createTorrentAndSetInfoHash(videoFile), - video.createThumbnail(videoFile), - video.createPreview(videoFile) - ) + return db.sequelize.transaction(async t => { + const sequelizeOptions = { transaction: t } if (CONFIG.TRANSCODING.ENABLED === true) { // Put uuid because we don't have id auto incremented for now @@ -217,20 +219,17 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil videoUUID: video.uuid } - tasks.push( - transcodingJobScheduler.createJob(t, 'videoFileOptimizer', dataInput) - ) + await transcodingJobScheduler.createJob(t, 'videoFileOptimizer', dataInput) } - await Promise.all(tasks) const videoCreated = await video.save(sequelizeOptions) // Do not forget to add video channel information to the created video videoCreated.VideoChannel = res.locals.videoChannel videoFile.videoId = video.id - await videoFile.save(sequelizeOptions) - video.VideoFiles = [videoFile] + + video.VideoFiles = [ videoFile ] if (videoInfo.tags) { const tagInstances = await db.Tag.findOrCreateTags(videoInfo.tags, t) -- cgit v1.2.3 From f595d3947708114deeed4312cc5ffd285745b090 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Dec 2017 17:31:21 +0100 Subject: Finish admin design --- server/controllers/api/videos/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 0f71a7f7f..63de662a7 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -280,7 +280,7 @@ async function updateVideo (req: express.Request, res: express.Response) { if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence) if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) - if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', videoInfoToUpdate.privacy) + if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10)) if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) @@ -298,9 +298,9 @@ async function updateVideo (req: express.Request, res: express.Response) { } // Video is not private anymore, send a create action to remote servers - if (wasPrivateVideo === true && videoInstance.privacy !== VideoPrivacy.PRIVATE) { - await sendAddVideo(videoInstance, t) - await shareVideoByServer(videoInstance, t) + if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { + await sendAddVideo(videoInstanceUpdated, t) + await shareVideoByServer(videoInstanceUpdated, t) } }) -- cgit v1.2.3