mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add history on server side
Add ability to disable, clear and list user videos history
This commit is contained in:
@@ -38,6 +38,7 @@ import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../h
|
||||
import { meRouter } from './me'
|
||||
import { deleteUserToken } from '../../../lib/oauth-model'
|
||||
import { myBlocklistRouter } from './my-blocklist'
|
||||
import { myVideosHistoryRouter } from './my-history'
|
||||
|
||||
const auditLogger = auditLoggerFactory('users')
|
||||
|
||||
@@ -55,6 +56,7 @@ const askSendEmailLimiter = new RateLimit({
|
||||
|
||||
const usersRouter = express.Router()
|
||||
usersRouter.use('/', myBlocklistRouter)
|
||||
usersRouter.use('/', myVideosHistoryRouter)
|
||||
usersRouter.use('/', meRouter)
|
||||
|
||||
usersRouter.get('/autocomplete',
|
||||
|
||||
@@ -330,6 +330,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr
|
||||
if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy
|
||||
if (body.webTorrentEnabled !== undefined) user.webTorrentEnabled = body.webTorrentEnabled
|
||||
if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
|
||||
if (body.videosHistoryEnabled !== undefined) user.videosHistoryEnabled = body.videosHistoryEnabled
|
||||
|
||||
await sequelizeTypescript.transaction(async t => {
|
||||
const userAccount = await AccountModel.load(user.Account.id)
|
||||
|
||||
57
server/controllers/api/users/my-history.ts
Normal file
57
server/controllers/api/users/my-history.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import * as express from 'express'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
asyncRetryTransactionMiddleware,
|
||||
authenticate,
|
||||
paginationValidator,
|
||||
setDefaultPagination,
|
||||
userHistoryRemoveValidator
|
||||
} from '../../../middlewares'
|
||||
import { UserModel } from '../../../models/account/user'
|
||||
import { getFormattedObjects } from '../../../helpers/utils'
|
||||
import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
|
||||
import { sequelizeTypescript } from '../../../initializers'
|
||||
|
||||
const myVideosHistoryRouter = express.Router()
|
||||
|
||||
myVideosHistoryRouter.get('/me/history/videos',
|
||||
authenticate,
|
||||
paginationValidator,
|
||||
setDefaultPagination,
|
||||
asyncMiddleware(listMyVideosHistory)
|
||||
)
|
||||
|
||||
myVideosHistoryRouter.post('/me/history/videos/remove',
|
||||
authenticate,
|
||||
userHistoryRemoveValidator,
|
||||
asyncRetryTransactionMiddleware(removeUserHistory)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
myVideosHistoryRouter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function listMyVideosHistory (req: express.Request, res: express.Response) {
|
||||
const user: UserModel = res.locals.oauth.token.User
|
||||
|
||||
const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count)
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
}
|
||||
|
||||
async function removeUserHistory (req: express.Request, res: express.Response) {
|
||||
const user: UserModel = res.locals.oauth.token.User
|
||||
const beforeDate = req.body.beforeDate || null
|
||||
|
||||
await sequelizeTypescript.transaction(t => {
|
||||
return UserVideoHistoryModel.removeHistoryBefore(user, beforeDate, t)
|
||||
})
|
||||
|
||||
// Do not send the delete to other instances, we delete OUR copy of this video abuse
|
||||
|
||||
return res.type('json').status(204).end()
|
||||
}
|
||||
Reference in New Issue
Block a user