videoModelToFormattedDetailsJSON,
videoModelToFormattedJSON
} from './video-format-utils'
+import * as 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: Sequelize.DefineIndexesOptions[] = [
required: false,
include: [
{
+ attributes: [ 'fileUrl' ],
model: () => VideoRedundancyModel.unscoped(),
required: false
}
return VideoModel.getAvailableForApi(query, queryOptions)
}
- static load (id: number, t?: Sequelize.Transaction) {
- return VideoModel.findById(id, { transaction: t })
- }
-
- static loadWithFile (id: number, t?: Sequelize.Transaction, logging?: boolean) {
- return VideoModel.scope(ScopeNames.WITH_FILES)
- .findById(id, { transaction: t, logging })
- }
-
- static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
- const query: IFindOptions<VideoModel> = {
- where: {
- url
- }
+ static load (id: number | string, t?: Sequelize.Transaction) {
+ const where = VideoModel.buildWhereIdOrUUID(id)
+ const options = {
+ where,
+ transaction: t
}
- if (t !== undefined) query.transaction = t
-
- return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query)
+ return VideoModel.findOne(options)
}
- static loadAndPopulateAccountAndServerAndTags (id: number) {
+ static loadOnlyId (id: number | string, t?: Sequelize.Transaction) {
+ const where = VideoModel.buildWhereIdOrUUID(id)
+
const options = {
- order: [ [ 'Tags', 'name', 'ASC' ] ]
+ attributes: [ 'id' ],
+ where,
+ transaction: t
}
- return VideoModel
- .scope([
- ScopeNames.WITH_TAGS,
- ScopeNames.WITH_BLACKLISTED,
- ScopeNames.WITH_FILES,
- ScopeNames.WITH_ACCOUNT_DETAILS,
- ScopeNames.WITH_SCHEDULED_UPDATE
- ])
- .findById(id, options)
+ return VideoModel.findOne(options)
+ }
+
+ static loadWithFile (id: number, t?: Sequelize.Transaction, logging?: boolean) {
+ return VideoModel.scope(ScopeNames.WITH_FILES)
+ .findById(id, { transaction: t, logging })
}
- static loadByUUID (uuid: string) {
+ static loadByUUIDWithFile (uuid: string) {
const options = {
where: {
uuid
.findOne(options)
}
- static loadByUUIDAndPopulateAccountAndServerAndTags (uuid: string, t?: Sequelize.Transaction) {
+ static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
+ const query: IFindOptions<VideoModel> = {
+ where: {
+ url
+ }
+ }
+
+ if (t !== undefined) query.transaction = t
+
+ return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query)
+ }
+
+ static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Sequelize.Transaction) {
+ const where = VideoModel.buildWhereIdOrUUID(id)
+
const options = {
order: [ [ 'Tags', 'name', 'ASC' ] ],
- where: {
- uuid
- },
+ where,
transaction: t
}
return VIDEO_STATES[ id ] || 'Unknown'
}
+ static buildWhereIdOrUUID (id: number | string) {
+ return validator.isInt('' + id) ? { id } : { uuid: id }
+ }
+
getOriginalFile () {
if (Array.isArray(this.VideoFiles) === false) return undefined