)
}
-function isVideoFileInfoHashValid (value: string) {
+function isVideoFileInfoHashValid (value: string | null | undefined) {
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
}
video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id)
}
- if (video && video !== null) {
+ if (video === null) {
res.status(404)
.json({ error: 'Video not found' })
.end()
async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
- if (videoChannel && videoChannel !== null) {
+ if (videoChannel === null) {
res.status(400)
.json({ error: 'Unknown video video channel on this instance.' })
.end()
}
const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
- if (videoChannel && videoChannel !== null) {
+ if (videoChannel === null) {
res.status(400)
.json({ error: 'Unknown video video channel for this account.' })
.end()
async function getServerActor () {
if (serverActor === undefined) {
const application = await ApplicationModel.load()
- if (!application) throw Error('Could not application.')
+ if (!application) throw Error('Could not load Application from database.')
+
serverActor = application.Account.Actor
}
}
async function createFunctions () {
- const query = `CREATE OR REPLACE FUNCTION immutable_unaccent(varchar)
- RETURNS text AS $$
- SELECT unaccent($1)
- $$ LANGUAGE sql IMMUTABLE;`
+ const query = `CREATE OR REPLACE FUNCTION immutable_unaccent(text)
+ RETURNS text AS
+$func$
+SELECT public.unaccent('public.unaccent', $1::text)
+$func$ LANGUAGE sql IMMUTABLE;`
return sequelizeTypescript.query(query, { raw: true })
}
import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'
+import { Migration } from '../../models/migrations'
function up (utils: {
transaction: Sequelize.Transaction,
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
allowNull: true
- }
+ } as Migration.UUID
return q.addColumn('Videos', 'uuid', dataUUID)
.then(() => {
return utils.sequelize.query(query)
})
.then(() => {
- dataUUID.defaultValue = null // FIXME:default value cannot be null if string
+ dataUUID.defaultValue = null
return q.changeColumn('Videos', 'uuid', dataUUID)
})
}) as VideoCaptionModel[]
}
- if (isNewVideo === true) {
+ if (isNewVideo) {
// Now we'll add the video's meta data to our followers
await sendCreateVideo(video, transaction)
await shareVideoByServerAndChannel(video, transaction)
if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href)
const parsed = magnetUtil.decode(magnet.href)
- if (!parsed ||
- (parsed.infoHash &&
- (isVideoFileInfoHashValid(parsed.infoHash) === false))) {
+ if (!parsed || isVideoFileInfoHashValid(parsed.infoHash) === false) {
throw new Error('Cannot parse magnet URI ' + magnet.href)
}
type CachedRoute = {
body: string,
- contentType: string
- statusCode: string
+ contentType?: string
+ statusCode?: string
}
class Redis {
interface BigInteger extends Sequelize.DefineAttributeColumnOptions {
defaultValue: Sequelize.DataTypeBigInt | number | null
}
+
+ interface UUID extends Sequelize.DefineAttributeColumnOptions {
+ defaultValue: Sequelize.DataTypeUUIDv4 | null
+ }
}
export {
// ---------------------------------------------------------------------------
function searchTrigramNormalizeValue (value: string) {
- return Sequelize.fn('lower', Sequelize.fn('unaccent', value))
+ return Sequelize.fn('lower', Sequelize.fn('immutable_unaccent', value))
}
function searchTrigramNormalizeCol (col: string) {
toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject {
let inReplyTo: string
// New thread, so in AS we reply to the video
- if ((this.inReplyToCommentId !== null) || (this.InReplyToVideoComment !== null)) {
+ if (this.inReplyToCommentId === null) {
inReplyTo = this.Video.url
} else {
inReplyTo = this.InReplyToVideoComment.url