From 8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 10 Jan 2023 11:09:30 +0100 Subject: Refactor model utils --- .../video/sql/comment/video-comment-list-query-builder.ts | 2 +- .../video/sql/video/shared/abstract-video-query-builder.ts | 2 +- .../models/video/sql/video/videos-id-list-query-builder.ts | 7 ++++--- server/models/video/tag.ts | 2 +- server/models/video/video-blacklist.ts | 6 +++--- server/models/video/video-caption.ts | 2 +- server/models/video/video-change-ownership.ts | 2 +- server/models/video/video-channel-sync.ts | 2 +- server/models/video/video-channel.ts | 12 +++++++++--- server/models/video/video-comment.ts | 2 +- server/models/video/video-file.ts | 11 +++++------ server/models/video/video-import.ts | 2 +- server/models/video/video-playlist-element.ts | 2 +- server/models/video/video-playlist.ts | 12 ++++-------- server/models/video/video-share.ts | 2 +- server/models/video/video-streaming-playlist.ts | 7 +++---- server/models/video/video.ts | 7 +++---- 17 files changed, 41 insertions(+), 41 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/sql/comment/video-comment-list-query-builder.ts b/server/models/video/sql/comment/video-comment-list-query-builder.ts index 49b41b6d8..3960f6b13 100644 --- a/server/models/video/sql/comment/video-comment-list-query-builder.ts +++ b/server/models/video/sql/comment/video-comment-list-query-builder.ts @@ -1,7 +1,7 @@ import { Model, Sequelize, Transaction } from 'sequelize' import { AbstractRunQuery, ModelBuilder } from '@server/models/shared' -import { createSafeIn, getCommentSort, parseRowCountResult } from '@server/models/utils' import { ActorImageType, VideoPrivacy } from '@shared/models' +import { createSafeIn, getCommentSort, parseRowCountResult } from '../../../shared' import { VideoCommentTableAttributes } from './video-comment-table-attributes' export interface ListVideoCommentsOptions { diff --git a/server/models/video/sql/video/shared/abstract-video-query-builder.ts b/server/models/video/sql/video/shared/abstract-video-query-builder.ts index f0ce69501..cbd57ad8c 100644 --- a/server/models/video/sql/video/shared/abstract-video-query-builder.ts +++ b/server/models/video/sql/video/shared/abstract-video-query-builder.ts @@ -1,9 +1,9 @@ import { Sequelize } from 'sequelize' import validator from 'validator' -import { createSafeIn } from '@server/models/utils' import { MUserAccountId } from '@server/types/models' import { ActorImageType } from '@shared/models' import { AbstractRunQuery } from '../../../../shared/abstract-run-query' +import { createSafeIn } from '../../../../shared' import { VideoTableAttributes } from './video-table-attributes' /** diff --git a/server/models/video/sql/video/videos-id-list-query-builder.ts b/server/models/video/sql/video/videos-id-list-query-builder.ts index 7c864bf27..62f1855c7 100644 --- a/server/models/video/sql/video/videos-id-list-query-builder.ts +++ b/server/models/video/sql/video/videos-id-list-query-builder.ts @@ -2,11 +2,12 @@ import { Sequelize, Transaction } from 'sequelize' import validator from 'validator' import { exists } from '@server/helpers/custom-validators/misc' import { WEBSERVER } from '@server/initializers/constants' -import { buildDirectionAndField, createSafeIn, parseRowCountResult } from '@server/models/utils' +import { buildSortDirectionAndField } from '@server/models/shared' import { MUserAccountId, MUserId } from '@server/types/models' +import { forceNumber } from '@shared/core-utils' import { VideoInclude, VideoPrivacy, VideoState } from '@shared/models' +import { createSafeIn, parseRowCountResult } from '../../../shared' import { AbstractRunQuery } from '../../../shared/abstract-run-query' -import { forceNumber } from '@shared/core-utils' /** * @@ -665,7 +666,7 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { } private buildOrder (value: string) { - const { direction, field } = buildDirectionAndField(value) + const { direction, field } = buildSortDirectionAndField(value) if (field.match(/^[a-zA-Z."]+$/) === null) throw new Error('Invalid sort column ' + field) if (field.toLowerCase() === 'random') return 'ORDER BY RANDOM()' diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index 653b9694b..cebde3755 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts @@ -4,7 +4,7 @@ import { MTag } from '@server/types/models' import { AttributesOnly } from '@shared/typescript-utils' import { VideoPrivacy, VideoState } from '../../../shared/models/videos' import { isVideoTagValid } from '../../helpers/custom-validators/videos' -import { throwIfNotValid } from '../utils' +import { throwIfNotValid } from '../shared' import { VideoModel } from './video' import { VideoTagModel } from './video-tag' diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 1cd8224c0..9247d0e2b 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -5,7 +5,7 @@ import { AttributesOnly } from '@shared/typescript-utils' import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' -import { getBlacklistSort, searchAttribute, SortType, throwIfNotValid } from '../utils' +import { getBlacklistSort, searchAttribute, throwIfNotValid } from '../shared' import { ThumbnailModel } from './thumbnail' import { VideoModel } from './video' import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' @@ -57,7 +57,7 @@ export class VideoBlacklistModel extends Model ({ diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 132c8f021..b71f5a197 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -43,8 +43,14 @@ import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor' import { ActorFollowModel } from '../actor/actor-follow' import { ActorImageModel } from '../actor/actor-image' import { ServerModel } from '../server/server' -import { setAsUpdated } from '../shared' -import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' +import { + buildServerIdsFollowedBy, + buildTrigramSearchIndex, + createSimilarityAttribute, + getSort, + setAsUpdated, + throwIfNotValid +} from '../shared' import { VideoModel } from './video' import { VideoPlaylistModel } from './video-playlist' @@ -831,6 +837,6 @@ export class VideoChannelModel extends Model static doesInfohashExist (infoHash: string) { const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' - return doesExist(query, { infoHash }) + return doesExist(this.sequelize, query, { infoHash }) } static async doesVideoExistForVideoFile (id: number, videoIdOrUUID: number | string) { @@ -282,14 +281,14 @@ export class VideoFileModel extends Model 'LEFT JOIN "video" "hlsVideo" ON "hlsVideo"."id" = "videoStreamingPlaylist"."videoId" AND "hlsVideo"."remote" IS FALSE ' + 'WHERE "torrentFilename" = $filename AND ("hlsVideo"."id" IS NOT NULL OR "webtorrent"."id" IS NOT NULL) LIMIT 1' - return doesExist(query, { filename }) + return doesExist(this.sequelize, query, { filename }) } static async doesOwnedWebTorrentVideoFileExist (filename: string) { const query = 'SELECT 1 FROM "videoFile" INNER JOIN "video" ON "video"."id" = "videoFile"."videoId" AND "video"."remote" IS FALSE ' + `WHERE "filename" = $filename AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` - return doesExist(query, { filename }) + return doesExist(this.sequelize, query, { filename }) } static loadByFilename (filename: string) { diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts index da6b92c7a..c040e0fda 100644 --- a/server/models/video/video-import.ts +++ b/server/models/video/video-import.ts @@ -22,7 +22,7 @@ import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../help import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers/constants' import { UserModel } from '../user/user' -import { getSort, searchAttribute, throwIfNotValid } from '../utils' +import { getSort, searchAttribute, throwIfNotValid } from '../shared' import { ScopeNames as VideoModelScopeNames, VideoModel } from './video' import { VideoChannelSyncModel } from './video-channel-sync' diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index 7181b5599..48f4ed5a9 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts @@ -31,7 +31,7 @@ import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' import { AccountModel } from '../account/account' -import { getSort, throwIfNotValid } from '../utils' +import { getSort, throwIfNotValid } from '../shared' import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' import { VideoPlaylistModel } from './video-playlist' diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 8bbe54c49..faf4bea78 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -21,12 +21,8 @@ import { activityPubCollectionPagination } from '@server/lib/activitypub/collect import { MAccountId, MChannelId } from '@server/types/models' import { buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils' import { buildUUID, uuidToShort } from '@shared/extra-utils' +import { ActivityIconObject, PlaylistObject, VideoPlaylist, VideoPlaylistPrivacy, VideoPlaylistType } from '@shared/models' import { AttributesOnly } from '@shared/typescript-utils' -import { ActivityIconObject } from '../../../shared/models/activitypub/objects' -import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' -import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' -import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' -import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { isVideoPlaylistDescriptionValid, @@ -53,7 +49,6 @@ import { } from '../../types/models/video/video-playlist' import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account' import { ActorModel } from '../actor/actor' -import { setAsUpdated } from '../shared' import { buildServerIdsFollowedBy, buildTrigramSearchIndex, @@ -61,8 +56,9 @@ import { createSimilarityAttribute, getPlaylistSort, isOutdated, + setAsUpdated, throwIfNotValid -} from '../utils' +} from '../shared' import { ThumbnailModel } from './thumbnail' import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel' import { VideoPlaylistElementModel } from './video-playlist-element' @@ -641,7 +637,7 @@ export class VideoPlaylistModel extends Model>> { } setAsRefreshed (transaction?: Transaction) { - return setAsUpdated('video', this.id, transaction) + return setAsUpdated({ sequelize: this.sequelize, table: 'video', id: this.id, transaction }) } // --------------------------------------------------------------------------- -- cgit v1.2.3