Cleanup server fixme
This commit is contained in:
parent
2f1756a03c
commit
0374b6b5cd
|
@ -18,7 +18,7 @@ export {
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
function webfingerController (req: express.Request, res: express.Response) {
|
function webfingerController (req: express.Request, res: express.Response) {
|
||||||
const actor = res.locals.actorFull
|
const actor = res.locals.actorUrl
|
||||||
|
|
||||||
const json = {
|
const json = {
|
||||||
subject: req.query.resource,
|
subject: req.query.resource,
|
||||||
|
@ -32,5 +32,5 @@ function webfingerController (req: express.Request, res: express.Response) {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.json(json).end()
|
return res.json(json)
|
||||||
}
|
}
|
||||||
|
|
|
@ -639,7 +639,6 @@ async function videoActivityObjectToDBAttributes (videoChannel: MChannelId, vide
|
||||||
createdAt: new Date(videoObject.published),
|
createdAt: new Date(videoObject.published),
|
||||||
publishedAt: new Date(videoObject.published),
|
publishedAt: new Date(videoObject.published),
|
||||||
originallyPublishedAt: videoObject.originallyPublishedAt ? new Date(videoObject.originallyPublishedAt) : null,
|
originallyPublishedAt: videoObject.originallyPublishedAt ? new Date(videoObject.originallyPublishedAt) : null,
|
||||||
// FIXME: updatedAt does not seems to be considered by Sequelize
|
|
||||||
updatedAt: new Date(videoObject.updated),
|
updatedAt: new Date(videoObject.updated),
|
||||||
views: videoObject.views,
|
views: videoObject.views,
|
||||||
likes: 0,
|
likes: 0,
|
||||||
|
|
|
@ -144,8 +144,7 @@ class JobQueue {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Bull queue typings does not have getJobs method
|
const jobs = await queue.getJobs([ state ], 0, start + count, asc)
|
||||||
const jobs = await (queue as any).getJobs(state, 0, start + count, asc)
|
|
||||||
results = results.concat(jobs)
|
results = results.concat(jobs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@ const webfingerValidator = [
|
||||||
const nameWithHost = getHostWithPort(req.query.resource.substr(5))
|
const nameWithHost = getHostWithPort(req.query.resource.substr(5))
|
||||||
const [ name ] = nameWithHost.split('@')
|
const [ name ] = nameWithHost.split('@')
|
||||||
|
|
||||||
// FIXME: we don't need the full actor
|
const actor = await ActorModel.loadLocalUrlByName(name)
|
||||||
const actor = await ActorModel.loadLocalByName(name)
|
|
||||||
if (!actor) {
|
if (!actor) {
|
||||||
return res.status(404)
|
return res.status(404)
|
||||||
.send({ error: 'Actor not found' })
|
.send({ error: 'Actor not found' })
|
||||||
.end()
|
.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.actorFull = actor
|
res.locals.actorUrl = actor
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -80,7 +80,7 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
|
||||||
attributes: [ 'accountId', 'id' ],
|
attributes: [ 'accountId', 'id' ],
|
||||||
where: {
|
where: {
|
||||||
accountId: {
|
accountId: {
|
||||||
[Op.in]: accountIds // FIXME: sequelize ANY seems broken
|
[Op.in]: accountIds
|
||||||
},
|
},
|
||||||
targetAccountId
|
targetAccountId
|
||||||
},
|
},
|
||||||
|
|
|
@ -363,7 +363,7 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
|
||||||
where: {
|
where: {
|
||||||
userId,
|
userId,
|
||||||
id: {
|
id: {
|
||||||
[Op.in]: notificationIds // FIXME: sequelize ANY seems broken
|
[Op.in]: notificationIds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ import {
|
||||||
MActorFull,
|
MActorFull,
|
||||||
MActorHost,
|
MActorHost,
|
||||||
MActorServer,
|
MActorServer,
|
||||||
MActorSummaryFormattable,
|
MActorSummaryFormattable, MActorUrl,
|
||||||
MActorWithInboxes
|
MActorWithInboxes
|
||||||
} from '../../typings/models'
|
} from '../../typings/models'
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
|
@ -276,7 +276,8 @@ export class ActorModel extends Model<ActorModel> {
|
||||||
})
|
})
|
||||||
VideoChannel: VideoChannelModel
|
VideoChannel: VideoChannelModel
|
||||||
|
|
||||||
private static cache: { [ id: string ]: any } = {}
|
private static localNameCache: { [ id: string ]: any } = {}
|
||||||
|
private static localUrlCache: { [ id: string ]: any } = {}
|
||||||
|
|
||||||
static load (id: number): Bluebird<MActor> {
|
static load (id: number): Bluebird<MActor> {
|
||||||
return ActorModel.unscoped().findByPk(id)
|
return ActorModel.unscoped().findByPk(id)
|
||||||
|
@ -345,8 +346,8 @@ export class ActorModel extends Model<ActorModel> {
|
||||||
|
|
||||||
static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorFull> {
|
static loadLocalByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorFull> {
|
||||||
// The server actor never change, so we can easily cache it
|
// The server actor never change, so we can easily cache it
|
||||||
if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.cache[preferredUsername]) {
|
if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.localNameCache[preferredUsername]) {
|
||||||
return Bluebird.resolve(ActorModel.cache[preferredUsername])
|
return Bluebird.resolve(ActorModel.localNameCache[preferredUsername])
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
|
@ -361,7 +362,33 @@ export class ActorModel extends Model<ActorModel> {
|
||||||
.findOne(query)
|
.findOne(query)
|
||||||
.then(actor => {
|
.then(actor => {
|
||||||
if (preferredUsername === SERVER_ACTOR_NAME) {
|
if (preferredUsername === SERVER_ACTOR_NAME) {
|
||||||
ActorModel.cache[ preferredUsername ] = actor
|
ActorModel.localNameCache[ preferredUsername ] = actor
|
||||||
|
}
|
||||||
|
|
||||||
|
return actor
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static loadLocalUrlByName (preferredUsername: string, transaction?: Transaction): Bluebird<MActorUrl> {
|
||||||
|
// The server actor never change, so we can easily cache it
|
||||||
|
if (preferredUsername === SERVER_ACTOR_NAME && ActorModel.localUrlCache[preferredUsername]) {
|
||||||
|
return Bluebird.resolve(ActorModel.localUrlCache[preferredUsername])
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
attributes: [ 'url' ],
|
||||||
|
where: {
|
||||||
|
preferredUsername,
|
||||||
|
serverId: null
|
||||||
|
},
|
||||||
|
transaction
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActorModel.unscoped()
|
||||||
|
.findOne(query)
|
||||||
|
.then(actor => {
|
||||||
|
if (preferredUsername === SERVER_ACTOR_NAME) {
|
||||||
|
ActorModel.localUrlCache[ preferredUsername ] = actor
|
||||||
}
|
}
|
||||||
|
|
||||||
return actor
|
return actor
|
||||||
|
|
|
@ -81,7 +81,7 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
|
||||||
attributes: [ 'accountId', 'id' ],
|
attributes: [ 'accountId', 'id' ],
|
||||||
where: {
|
where: {
|
||||||
accountId: {
|
accountId: {
|
||||||
[Op.in]: accountIds // FIXME: sequelize ANY seems broken
|
[Op.in]: accountIds
|
||||||
},
|
},
|
||||||
targetServerId
|
targetServerId
|
||||||
},
|
},
|
||||||
|
|
|
@ -120,7 +120,7 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
|
||||||
language
|
language
|
||||||
}
|
}
|
||||||
|
|
||||||
return (VideoCaptionModel.upsert<VideoCaptionModel>(values, { transaction, returning: true }) as any) // FIXME: typings
|
return VideoCaptionModel.upsert(values, { transaction, returning: true })
|
||||||
.then(([ caption ]) => caption)
|
.then(([ caption ]) => caption)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,18 +43,6 @@ import {
|
||||||
MChannelSummaryFormattable
|
MChannelSummaryFormattable
|
||||||
} from '../../typings/models/video'
|
} from '../../typings/models/video'
|
||||||
|
|
||||||
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
|
|
||||||
const indexes: ModelIndexesOptions[] = [
|
|
||||||
buildTrigramSearchIndex('video_channel_name_trigram', 'name'),
|
|
||||||
|
|
||||||
{
|
|
||||||
fields: [ 'accountId' ]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'actorId' ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
export enum ScopeNames {
|
export enum ScopeNames {
|
||||||
FOR_API = 'FOR_API',
|
FOR_API = 'FOR_API',
|
||||||
WITH_ACCOUNT = 'WITH_ACCOUNT',
|
WITH_ACCOUNT = 'WITH_ACCOUNT',
|
||||||
|
@ -176,7 +164,16 @@ export type SummaryOptions = {
|
||||||
}))
|
}))
|
||||||
@Table({
|
@Table({
|
||||||
tableName: 'videoChannel',
|
tableName: 'videoChannel',
|
||||||
indexes
|
indexes: [
|
||||||
|
buildTrigramSearchIndex('video_channel_name_trigram', 'name'),
|
||||||
|
|
||||||
|
{
|
||||||
|
fields: [ 'accountId' ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'actorId' ]
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class VideoChannelModel extends Model<VideoChannelModel> {
|
export class VideoChannelModel extends Model<VideoChannelModel> {
|
||||||
|
|
||||||
|
|
|
@ -369,7 +369,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
|
||||||
model: VideoPlaylistElementModel.unscoped(),
|
model: VideoPlaylistElementModel.unscoped(),
|
||||||
where: {
|
where: {
|
||||||
videoId: {
|
videoId: {
|
||||||
[Op.in]: videoIds // FIXME: sequelize ANY seems broken
|
[Op.in]: videoIds
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
required: true
|
required: true
|
||||||
|
|
|
@ -1,18 +1,7 @@
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import { maxBy, minBy } from 'lodash'
|
import { maxBy, minBy } from 'lodash'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import {
|
import { CountOptions, FindOptions, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
|
||||||
CountOptions,
|
|
||||||
FindOptions,
|
|
||||||
IncludeOptions,
|
|
||||||
ModelIndexesOptions,
|
|
||||||
Op,
|
|
||||||
QueryTypes,
|
|
||||||
ScopeOptions,
|
|
||||||
Sequelize,
|
|
||||||
Transaction,
|
|
||||||
WhereOptions
|
|
||||||
} from 'sequelize'
|
|
||||||
import {
|
import {
|
||||||
AllowNull,
|
AllowNull,
|
||||||
BeforeDestroy,
|
BeforeDestroy,
|
||||||
|
@ -136,8 +125,7 @@ import {
|
||||||
MVideoThumbnailBlacklist,
|
MVideoThumbnailBlacklist,
|
||||||
MVideoWithAllFiles,
|
MVideoWithAllFiles,
|
||||||
MVideoWithFile,
|
MVideoWithFile,
|
||||||
MVideoWithRights,
|
MVideoWithRights
|
||||||
MStreamingPlaylistFiles
|
|
||||||
} from '../../typings/models'
|
} from '../../typings/models'
|
||||||
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
|
import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../typings/models/video/video-file'
|
||||||
import { MThumbnail } from '../../typings/models/video/thumbnail'
|
import { MThumbnail } from '../../typings/models/video/thumbnail'
|
||||||
|
@ -145,74 +133,6 @@ import { VideoFile } from '@shared/models/videos/video-file.model'
|
||||||
import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
|
import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
|
||||||
import validator from 'validator'
|
import validator from 'validator'
|
||||||
|
|
||||||
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
|
|
||||||
const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [
|
|
||||||
buildTrigramSearchIndex('video_name_trigram', 'name'),
|
|
||||||
|
|
||||||
{ fields: [ 'createdAt' ] },
|
|
||||||
{
|
|
||||||
fields: [
|
|
||||||
{ name: 'publishedAt', order: 'DESC' },
|
|
||||||
{ name: 'id', order: 'ASC' }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{ fields: [ 'duration' ] },
|
|
||||||
{ fields: [ 'views' ] },
|
|
||||||
{ fields: [ 'channelId' ] },
|
|
||||||
{
|
|
||||||
fields: [ 'originallyPublishedAt' ],
|
|
||||||
where: {
|
|
||||||
originallyPublishedAt: {
|
|
||||||
[Op.ne]: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'category' ], // We don't care videos with an unknown category
|
|
||||||
where: {
|
|
||||||
category: {
|
|
||||||
[Op.ne]: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'licence' ], // We don't care videos with an unknown licence
|
|
||||||
where: {
|
|
||||||
licence: {
|
|
||||||
[Op.ne]: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'language' ], // We don't care videos with an unknown language
|
|
||||||
where: {
|
|
||||||
language: {
|
|
||||||
[Op.ne]: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'nsfw' ], // Most of the videos are not NSFW
|
|
||||||
where: {
|
|
||||||
nsfw: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'remote' ], // Only index local videos
|
|
||||||
where: {
|
|
||||||
remote: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'uuid' ],
|
|
||||||
unique: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: [ 'url' ],
|
|
||||||
unique: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
export enum ScopeNames {
|
export enum ScopeNames {
|
||||||
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
|
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
|
||||||
FOR_API = 'FOR_API',
|
FOR_API = 'FOR_API',
|
||||||
|
@ -292,7 +212,7 @@ export type AvailableForListIDsOptions = {
|
||||||
if (options.ids) {
|
if (options.ids) {
|
||||||
query.where = {
|
query.where = {
|
||||||
id: {
|
id: {
|
||||||
[ Op.in ]: options.ids // FIXME: sequelize ANY seems broken
|
[ Op.in ]: options.ids
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -760,7 +680,72 @@ export type AvailableForListIDsOptions = {
|
||||||
}))
|
}))
|
||||||
@Table({
|
@Table({
|
||||||
tableName: 'video',
|
tableName: 'video',
|
||||||
indexes
|
indexes: [
|
||||||
|
buildTrigramSearchIndex('video_name_trigram', 'name'),
|
||||||
|
|
||||||
|
{ fields: [ 'createdAt' ] },
|
||||||
|
{
|
||||||
|
fields: [
|
||||||
|
{ name: 'publishedAt', order: 'DESC' },
|
||||||
|
{ name: 'id', order: 'ASC' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ fields: [ 'duration' ] },
|
||||||
|
{ fields: [ 'views' ] },
|
||||||
|
{ fields: [ 'channelId' ] },
|
||||||
|
{
|
||||||
|
fields: [ 'originallyPublishedAt' ],
|
||||||
|
where: {
|
||||||
|
originallyPublishedAt: {
|
||||||
|
[Op.ne]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'category' ], // We don't care videos with an unknown category
|
||||||
|
where: {
|
||||||
|
category: {
|
||||||
|
[Op.ne]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'licence' ], // We don't care videos with an unknown licence
|
||||||
|
where: {
|
||||||
|
licence: {
|
||||||
|
[Op.ne]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'language' ], // We don't care videos with an unknown language
|
||||||
|
where: {
|
||||||
|
language: {
|
||||||
|
[Op.ne]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'nsfw' ], // Most of the videos are not NSFW
|
||||||
|
where: {
|
||||||
|
nsfw: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'remote' ], // Only index local videos
|
||||||
|
where: {
|
||||||
|
remote: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'uuid' ],
|
||||||
|
unique: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'url' ],
|
||||||
|
unique: true
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
export class VideoModel extends Model<VideoModel> {
|
export class VideoModel extends Model<VideoModel> {
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import {
|
||||||
} from './models'
|
} from './models'
|
||||||
import { MVideoPlaylistFull, MVideoPlaylistFullSummary } from './models/video/video-playlist'
|
import { MVideoPlaylistFull, MVideoPlaylistFullSummary } from './models/video/video-playlist'
|
||||||
import { MVideoImportDefault } from '@server/typings/models/video/video-import'
|
import { MVideoImportDefault } from '@server/typings/models/video/video-import'
|
||||||
import { MAccountBlocklist, MStreamingPlaylist, MVideoFile } from '@server/typings/models'
|
import { MAccountBlocklist, MActorUrl, MStreamingPlaylist, MVideoFile } from '@server/typings/models'
|
||||||
import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/typings/models/video/video-playlist-element'
|
import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/typings/models/video/video-playlist-element'
|
||||||
import { MAccountVideoRateAccountVideo } from '@server/typings/models/video/video-rate'
|
import { MAccountVideoRateAccountVideo } from '@server/typings/models/video/video-rate'
|
||||||
import { MVideoChangeOwnershipFull } from './models/video/video-change-ownership'
|
import { MVideoChangeOwnershipFull } from './models/video/video-change-ownership'
|
||||||
|
@ -74,6 +74,7 @@ declare module 'express' {
|
||||||
|
|
||||||
account?: MAccountDefault
|
account?: MAccountDefault
|
||||||
|
|
||||||
|
actorUrl?: MActorUrl
|
||||||
actorFull?: MActorFull
|
actorFull?: MActorFull
|
||||||
|
|
||||||
user?: MUserDefault
|
user?: MUserDefault
|
||||||
|
|
|
@ -59,7 +59,6 @@ async function countVideoViewsOf (internalServerNumber: number, uuid: string) {
|
||||||
|
|
||||||
if (!total) return 0
|
if (!total) return 0
|
||||||
|
|
||||||
// FIXME: check if we really need parseInt
|
|
||||||
return parseInt(total + '', 10)
|
return parseInt(total + '', 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue