1
0
Fork 0

Fix last commit

This commit is contained in:
Chocobozzz 2018-07-26 10:45:10 +02:00
parent c1e791bad0
commit 2cebd79701
No known key found for this signature in database
GPG key ID: 583A612D890159BE
9 changed files with 24 additions and 19 deletions

View file

@ -110,7 +110,7 @@ function isScheduleVideoUpdatePrivacyValid (value: number) {
) )
} }
function isVideoFileInfoHashValid (value: string) { function isVideoFileInfoHashValid (value: string | null | undefined) {
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
} }
@ -158,7 +158,7 @@ async function isVideoExist (id: string, res: Response) {
video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id)
} }
if (video && video !== null) { if (video === null) {
res.status(404) res.status(404)
.json({ error: 'Video not found' }) .json({ error: 'Video not found' })
.end() .end()
@ -173,7 +173,7 @@ async function isVideoExist (id: string, res: Response) {
async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
if (videoChannel && videoChannel !== null) { if (videoChannel === null) {
res.status(400) res.status(400)
.json({ error: 'Unknown video video channel on this instance.' }) .json({ error: 'Unknown video video channel on this instance.' })
.end() .end()
@ -186,7 +186,7 @@ async function isVideoChannelOfAccountExist (channelId: number, user: UserModel,
} }
const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
if (videoChannel && videoChannel !== null) { if (videoChannel === null) {
res.status(400) res.status(400)
.json({ error: 'Unknown video video channel for this account.' }) .json({ error: 'Unknown video video channel for this account.' })
.end() .end()

View file

@ -144,7 +144,8 @@ let serverActor: ActorModel
async function getServerActor () { async function getServerActor () {
if (serverActor === undefined) { if (serverActor === undefined) {
const application = await ApplicationModel.load() 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 serverActor = application.Account.Actor
} }

View file

@ -125,10 +125,11 @@ async function checkPostgresExtensions () {
} }
async function createFunctions () { async function createFunctions () {
const query = `CREATE OR REPLACE FUNCTION immutable_unaccent(varchar) const query = `CREATE OR REPLACE FUNCTION immutable_unaccent(text)
RETURNS text AS $$ RETURNS text AS
SELECT unaccent($1) $func$
$$ LANGUAGE sql IMMUTABLE;` SELECT public.unaccent('public.unaccent', $1::text)
$func$ LANGUAGE sql IMMUTABLE;`
return sequelizeTypescript.query(query, { raw: true }) return sequelizeTypescript.query(query, { raw: true })
} }

View file

@ -1,5 +1,6 @@
import * as Sequelize from 'sequelize' import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird' import * as Promise from 'bluebird'
import { Migration } from '../../models/migrations'
function up (utils: { function up (utils: {
transaction: Sequelize.Transaction, transaction: Sequelize.Transaction,
@ -12,7 +13,7 @@ function up (utils: {
type: Sequelize.UUID, type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4, defaultValue: Sequelize.UUIDV4,
allowNull: true allowNull: true
} } as Migration.UUID
return q.addColumn('Videos', 'uuid', dataUUID) return q.addColumn('Videos', 'uuid', dataUUID)
.then(() => { .then(() => {
@ -24,7 +25,7 @@ function up (utils: {
return utils.sequelize.query(query) return utils.sequelize.query(query)
}) })
.then(() => { .then(() => {
dataUUID.defaultValue = null // FIXME:default value cannot be null if string dataUUID.defaultValue = null
return q.changeColumn('Videos', 'uuid', dataUUID) return q.changeColumn('Videos', 'uuid', dataUUID)
}) })

View file

@ -38,7 +38,7 @@ async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, tr
}) as VideoCaptionModel[] }) as VideoCaptionModel[]
} }
if (isNewVideo === true) { if (isNewVideo) {
// Now we'll add the video's meta data to our followers // Now we'll add the video's meta data to our followers
await sendCreateVideo(video, transaction) await sendCreateVideo(video, transaction)
await shareVideoByServerAndChannel(video, transaction) await shareVideoByServerAndChannel(video, transaction)
@ -153,9 +153,7 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje
if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href) if (!magnet) throw new Error('Cannot find associated magnet uri for file ' + fileUrl.href)
const parsed = magnetUtil.decode(magnet.href) const parsed = magnetUtil.decode(magnet.href)
if (!parsed || if (!parsed || isVideoFileInfoHashValid(parsed.infoHash) === false) {
(parsed.infoHash &&
(isVideoFileInfoHashValid(parsed.infoHash) === false))) {
throw new Error('Cannot parse magnet URI ' + magnet.href) throw new Error('Cannot parse magnet URI ' + magnet.href)
} }

View file

@ -6,8 +6,8 @@ import { CONFIG, USER_PASSWORD_RESET_LIFETIME, VIDEO_VIEW_LIFETIME } from '../in
type CachedRoute = { type CachedRoute = {
body: string, body: string,
contentType: string contentType?: string
statusCode: string statusCode?: string
} }
class Redis { class Redis {

View file

@ -16,6 +16,10 @@ declare namespace Migration {
interface BigInteger extends Sequelize.DefineAttributeColumnOptions { interface BigInteger extends Sequelize.DefineAttributeColumnOptions {
defaultValue: Sequelize.DataTypeBigInt | number | null defaultValue: Sequelize.DataTypeBigInt | number | null
} }
interface UUID extends Sequelize.DefineAttributeColumnOptions {
defaultValue: Sequelize.DataTypeUUIDv4 | null
}
} }
export { export {

View file

@ -76,7 +76,7 @@ export {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function searchTrigramNormalizeValue (value: string) { 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) { function searchTrigramNormalizeCol (col: string) {

View file

@ -417,7 +417,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject { toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject {
let inReplyTo: string let inReplyTo: string
// New thread, so in AS we reply to the video // 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 inReplyTo = this.Video.url
} else { } else {
inReplyTo = this.InReplyToVideoComment.url inReplyTo = this.InReplyToVideoComment.url