123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714 |
- import { DB } from '../../generated/indexer'
- import { Channel } from '../../generated/graphql-server/src/modules/channel/channel.model'
- import { Category } from '../../generated/graphql-server/src/modules/category/category.model'
- import { KnownLicense } from '../../generated/graphql-server/src/modules/known-license/known-license.model'
- import { UserDefinedLicense } from '../../generated/graphql-server/src/modules/user-defined-license/user-defined-license.model'
- import { JoystreamMediaLocation } from '../../generated/graphql-server/src/modules/joystream-media-location/joystream-media-location.model'
- import { HttpMediaLocation } from '../../generated/graphql-server/src/modules/http-media-location/http-media-location.model'
- import { VideoMedia } from '../../generated/graphql-server/src/modules/video-media/video-media.model'
- import { Video } from '../../generated/graphql-server/src/modules/video/video.model'
- import { Block, Network } from '../../generated/graphql-server/src/modules/block/block.model'
- import { Language } from '../../generated/graphql-server/src/modules/language/language.model'
- import { VideoMediaEncoding } from '../../generated/graphql-server/src/modules/video-media-encoding/video-media-encoding.model'
- import { ClassEntity } from '../../generated/graphql-server/src/modules/class-entity/class-entity.model'
- import { License } from '../../generated/graphql-server/src/modules/license/license.model'
- import { MediaLocation } from '../../generated/graphql-server/src/modules/media-location/media-location.model'
- import { contentDirectoryClassNamesWithId } from './content-dir-consts'
- import {
- ClassEntityMap,
- ICategory,
- IChannel,
- ICreateEntityOperation,
- IDBBlockId,
- IEntity,
- IHttpMediaLocation,
- IJoystreamMediaLocation,
- IKnownLicense,
- ILanguage,
- ILicense,
- IMediaLocation,
- IUserDefinedLicense,
- IVideo,
- IVideoMedia,
- IVideoMediaEncoding,
- IWhereCond,
- } from '../types'
- import { getOrCreate } from './get-or-create'
- import BN from 'bn.js'
- async function createBlockOrGetFromDatabase(db: DB, blockNumber: number): Promise<Block> {
- let b = await db.get(Block, { where: { block: blockNumber } })
- if (b === undefined) {
- // TODO: get timestamp from the event or extrinsic
- b = new Block({ block: blockNumber, network: Network.BABYLON, timestamp: new BN(Date.now()) })
- await db.save<Block>(b)
- }
- return b
- }
- async function createChannel(
- { db, block, id }: IDBBlockId,
- classEntityMap: ClassEntityMap,
- p: IChannel
- ): Promise<Channel> {
- const record = await db.get(Channel, { where: { id } })
- if (record) return record
- const channel = new Channel()
- channel.version = block
- channel.id = id
- channel.title = p.title
- channel.description = p.description
- channel.isCurated = p.isCurated || false
- channel.isPublic = p.isPublic
- channel.coverPhotoUrl = p.coverPhotoURL
- channel.avatarPhotoUrl = p.avatarPhotoURL
- const { language } = p
- if (language !== undefined) {
- if (language.existing) {
- const r = await db.get(Language, { where: { id: language.entityId.toString() } })
- if (!r) throw Error(`Language entity not found`)
- channel.language = r
- } else {
- // Language entity id is based on the index so we increase the entityid to make it correct
- channel.language = await getOrCreate.language({ db, block, id }, classEntityMap, language.entityId)
- }
- }
- channel.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save(channel)
- return channel
- }
- async function createCategory({ db, block, id }: IDBBlockId, p: ICategory): Promise<Category> {
- const record = await db.get(Category, { where: { id } })
- if (record) return record
- const category = new Category()
- category.id = id
- category.name = p.name
- category.description = p.description
- category.version = block
- category.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save(category)
- return category
- }
- async function createKnownLicense({ db, block, id }: IDBBlockId, p: IKnownLicense): Promise<KnownLicense> {
- const record = await db.get(KnownLicense, { where: { id } })
- if (record) return record
- const knownLicence = new KnownLicense()
- knownLicence.id = id
- knownLicence.code = p.code
- knownLicence.name = p.name
- knownLicence.description = p.description
- knownLicence.url = p.url
- knownLicence.version = block
- knownLicence.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save(knownLicence)
- return knownLicence
- }
- async function createUserDefinedLicense(
- { db, block, id }: IDBBlockId,
- p: IUserDefinedLicense
- ): Promise<UserDefinedLicense> {
- const record = await db.get(UserDefinedLicense, { where: { id } })
- if (record) return record
- const userDefinedLicense = new UserDefinedLicense()
- userDefinedLicense.id = id
- userDefinedLicense.content = p.content
- userDefinedLicense.version = block
- userDefinedLicense.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save<UserDefinedLicense>(userDefinedLicense)
- return userDefinedLicense
- }
- async function createJoystreamMediaLocation(
- { db, block, id }: IDBBlockId,
- p: IJoystreamMediaLocation
- ): Promise<JoystreamMediaLocation> {
- const record = await db.get(JoystreamMediaLocation, { where: { id } })
- if (record) return record
- const joyMediaLoc = new JoystreamMediaLocation()
- joyMediaLoc.id = id
- joyMediaLoc.dataObjectId = p.dataObjectId
- joyMediaLoc.version = block
- joyMediaLoc.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save(joyMediaLoc)
- return joyMediaLoc
- }
- async function createHttpMediaLocation(
- { db, block, id }: IDBBlockId,
- p: IHttpMediaLocation
- ): Promise<HttpMediaLocation> {
- const record = await db.get(HttpMediaLocation, { where: { id } })
- if (record) return record
- const httpMediaLoc = new HttpMediaLocation()
- httpMediaLoc.id = id
- httpMediaLoc.url = p.url
- httpMediaLoc.port = p.port
- httpMediaLoc.version = block
- httpMediaLoc.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save(httpMediaLoc)
- return httpMediaLoc
- }
- async function createVideoMedia(
- { db, block, id }: IDBBlockId,
- classEntityMap: ClassEntityMap,
- p: IVideoMedia
- ): Promise<VideoMedia> {
- const videoMedia = new VideoMedia()
- videoMedia.id = id
- videoMedia.pixelHeight = p.pixelHeight
- videoMedia.pixelWidth = p.pixelWidth
- videoMedia.size = p.size
- videoMedia.version = block
- const { encoding, location } = p
- if (encoding !== undefined) {
- if (encoding.existing) {
- const e = await db.get(VideoMediaEncoding, { where: { id: encoding.entityId.toString() } })
- if (!e) throw Error(`VideoMediaEncoding not found: ${encoding.entityId}`)
- videoMedia.encoding = e
- } else {
- videoMedia.encoding = await getOrCreate.videoMediaEncoding({ db, block, id }, classEntityMap, encoding.entityId)
- }
- }
- if (location !== undefined) {
- if (location.existing) {
- const l = await db.get(MediaLocation, { where: { id: location.entityId.toString() } })
- if (!l) throw Error(`MediaLocation not found: ${location.entityId}`)
- videoMedia.location = l
- } else {
- videoMedia.location = await getOrCreate.mediaLocation({ db, block, id }, classEntityMap, location.entityId)
- }
- }
- videoMedia.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save(videoMedia)
- return videoMedia
- }
- async function createVideo({ db, block, id }: IDBBlockId, classEntityMap: ClassEntityMap, p: IVideo): Promise<Video> {
- const record = await db.get(Video, { where: { id } })
- if (record) return record
- const video = new Video()
- video.id = id
- video.title = p.title
- video.description = p.description
- video.duration = p.duration
- video.hasMarketing = p.hasMarketing
- // TODO: needs to be handled correctly, from runtime CurationStatus is coming
- video.isCurated = p.isCurated || true
- video.isExplicit = p.isExplicit
- video.isPublic = p.isPublic
- video.publishedBeforeJoystream = p.publishedBeforeJoystream
- video.skippableIntroDuration = p.skippableIntroDuration
- video.thumbnailUrl = p.thumbnailURL
- video.version = block
- const { language, license, category, channel, media } = p
- if (language !== undefined) {
- if (language.existing) {
- const l = await db.get(Language, { where: { id: language.entityId.toString() } })
- if (!l) throw Error(`Language entity not found`)
- video.language = l
- } else {
- video.language = await getOrCreate.language({ db, block, id }, classEntityMap, language.entityId)
- }
- }
- if (license !== undefined) {
- if (license.existing) {
- const lic = await db.get(License, { where: { id: license.entityId.toString() } })
- if (!lic) throw Error(`License entity not found`)
- video.license = lic
- } else {
- video.license = await getOrCreate.license({ db, block, id }, classEntityMap, license.entityId)
- }
- }
- if (category !== undefined) {
- if (category.existing) {
- const ca = await db.get(Category, { where: { id: category.entityId.toString() } })
- if (!ca) throw Error(`Category not found`)
- video.category = ca
- } else {
- video.category = await getOrCreate.category({ db, block, id }, classEntityMap, category.entityId)
- }
- }
- if (channel !== undefined) {
- if (channel.existing) {
- const c = await db.get(Channel, { where: { id: channel.entityId.toString() } })
- if (!c) throw Error(`Channel not found: ${channel.entityId}`)
- video.channel = c
- } else {
- video.channel = await getOrCreate.channel({ db, block, id }, classEntityMap, channel.entityId)
- }
- }
- if (media !== undefined) {
- if (media.existing) {
- const m = await db.get(VideoMedia, { where: { id: media.entityId.toString() } })
- if (!m) throw Error(`VideoMedia not found: ${media.entityId}`)
- video.media = m
- } else {
- video.media = await getOrCreate.videoMedia({ db, block, id }, classEntityMap, media.entityId)
- }
- }
- video.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save<Video>(video)
- return video
- }
- async function createLanguage({ db, block, id }: IDBBlockId, p: ILanguage): Promise<Language> {
- const record = await db.get(Language, { where: { id } })
- if (record) return record
- const language = new Language()
- language.id = id
- language.name = p.name
- language.code = p.code
- language.version = block
- language.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save<Language>(language)
- return language
- }
- async function createVideoMediaEncoding(
- { db, block, id }: IDBBlockId,
- p: IVideoMediaEncoding
- ): Promise<VideoMediaEncoding> {
- const record = await db.get(VideoMediaEncoding, { where: { id } })
- if (record) return record
- const encoding = new VideoMediaEncoding()
- encoding.id = id
- encoding.name = p.name
- encoding.version = block
- encoding.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save<VideoMediaEncoding>(encoding)
- return encoding
- }
- async function createLicense(
- { db, block, id }: IDBBlockId,
- classEntityMap: ClassEntityMap,
- p: ILicense
- ): Promise<License> {
- const record = await db.get(License, { where: { id } })
- if (record) return record
- const { knownLicense, userDefinedLicense } = p
- const license = new License()
- license.id = id
- if (knownLicense !== undefined) {
- if (knownLicense.existing) {
- const kl = await db.get(KnownLicense, { where: { id: knownLicense.entityId.toString() } })
- if (!kl) throw Error(`KnownLicense not found: ${knownLicense.entityId}`)
- license.knownLicense = kl
- } else {
- license.knownLicense = await getOrCreate.knownLicense({ db, block, id }, classEntityMap, knownLicense.entityId)
- }
- }
- if (userDefinedLicense !== undefined) {
- if (userDefinedLicense.existing) {
- const udl = await db.get(UserDefinedLicense, { where: { id: userDefinedLicense.entityId.toString() } })
- if (!udl) throw Error(`UserDefinedLicense not found: ${userDefinedLicense.entityId}`)
- license.userdefinedLicense = udl
- } else {
- license.userdefinedLicense = await getOrCreate.userDefinedLicense(
- { db, block, id },
- classEntityMap,
- userDefinedLicense.entityId
- )
- }
- }
- license.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save<License>(license)
- return license
- }
- async function createMediaLocation(
- { db, block, id }: IDBBlockId,
- classEntityMap: ClassEntityMap,
- p: IMediaLocation
- ): Promise<MediaLocation> {
- const { httpMediaLocation, joystreamMediaLocation } = p
- const location = new MediaLocation()
- location.id = id
- console.log(p)
- if (httpMediaLocation !== undefined) {
- const { existing, entityId } = httpMediaLocation
- if (existing) {
- const hml = await db.get(HttpMediaLocation, { where: { id: entityId.toString() } })
- if (!hml) throw Error(`HttpMediaLocation not found: ${entityId}`)
- } else {
- location.httpMediaLocation = await getOrCreate.httpMediaLocation({ db, block, id }, classEntityMap, entityId)
- }
- }
- if (joystreamMediaLocation !== undefined) {
- const { entityId, existing } = joystreamMediaLocation
- if (existing) {
- const jml = await db.get(JoystreamMediaLocation, { where: { id: entityId.toString() } })
- if (!jml) throw Error(`JoystreamMediaLocation not found: ${entityId}`)
- location.joystreamMediaLocation = jml
- } else {
- location.joystreamMediaLocation = await getOrCreate.joystreamMediaLocation(
- { db, block, id },
- classEntityMap,
- entityId
- )
- }
- }
- location.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save<License>(location)
- return location
- }
- async function batchCreateClassEntities(db: DB, block: number, operations: ICreateEntityOperation[]): Promise<void> {
- let entityId = 1 // Entity id starts at 1
- // Create entities before adding schema support
- operations.map(async ({ classId }) => {
- const c = new ClassEntity()
- c.id = entityId.toString()
- c.classId = classId
- c.version = block
- c.happenedIn = await createBlockOrGetFromDatabase(db, block)
- await db.save<ClassEntity>(c)
- entityId++
- })
- }
- async function getClassName(
- db: DB,
- entity: IEntity,
- createEntityOperations: ICreateEntityOperation[]
- ): Promise<string | undefined> {
- const { entityId, indexOf } = entity
- if (entityId === undefined && indexOf === undefined) {
- throw Error(`Can not determine class of the entity`)
- }
- let classId: number | undefined
- // Is newly created entity in the same transaction
- if (indexOf !== undefined) {
- classId = createEntityOperations[indexOf].classId
- } else {
- const ce = await db.get(ClassEntity, { where: { id: entityId } })
- if (ce === undefined) console.log(`Class not found for the entity: ${entityId}`)
- classId = ce ? ce.classId : undefined
- }
- const c = contentDirectoryClassNamesWithId.find((c) => c.classId === classId)
- // TODO: stop execution, class should be created before entity creation
- if (c === undefined) console.log(`Not recognized class id: ${classId}`)
- return c ? c.name : undefined
- }
- async function removeChannel(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(Channel, where)
- if (record === undefined) throw Error(`Channel not found`)
- if (record.videos) record.videos.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
- await db.remove<Channel>(record)
- }
- async function removeCategory(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(Category, where)
- if (record === undefined) throw Error(`Category not found`)
- if (record.videos) record.videos.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
- await db.remove<Category>(record)
- }
- async function removeVideoMedia(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(VideoMedia, where)
- if (record === undefined) throw Error(`VideoMedia not found`)
- if (record.video) await db.remove<Video>(record.video)
- await db.remove<VideoMedia>(record)
- }
- async function removeVideo(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(Video, where)
- if (record === undefined) throw Error(`Video not found`)
- await db.remove<Video>(record)
- }
- async function removeLicense(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(License, where)
- if (record === undefined) throw Error(`License not found`)
- // Remove all the videos under this license
- if (record.videolicense) record.videolicense.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
- await db.remove<License>(record)
- }
- async function removeUserDefinedLicense(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(UserDefinedLicense, where)
- if (record === undefined) throw Error(`UserDefinedLicense not found`)
- if (record.licenseuserdefinedLicense)
- record.licenseuserdefinedLicense.map(async (l) => await removeLicense(db, { where: { id: l.id } }))
- await db.remove<UserDefinedLicense>(record)
- }
- async function removeKnownLicense(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(KnownLicense, where)
- if (record === undefined) throw Error(`KnownLicense not found`)
- if (record.licenseknownLicense)
- record.licenseknownLicense.map(async (k) => await removeLicense(db, { where: { id: k.id } }))
- await db.remove<KnownLicense>(record)
- }
- async function removeMediaLocation(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(MediaLocation, where)
- if (record === undefined) throw Error(`MediaLocation not found`)
- if (record.videoMedia) await removeVideo(db, { where: { id: record.videoMedia.id } })
- await db.remove<MediaLocation>(record)
- }
- async function removeHttpMediaLocation(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(HttpMediaLocation, where)
- if (record === undefined) throw Error(`HttpMediaLocation not found`)
- if (record.medialocationhttpMediaLocation)
- record.medialocationhttpMediaLocation.map(async (v) => await removeMediaLocation(db, { where: { id: v.id } }))
- await db.remove<HttpMediaLocation>(record)
- }
- async function removeJoystreamMediaLocation(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(JoystreamMediaLocation, where)
- if (record === undefined) throw Error(`JoystreamMediaLocation not found`)
- if (record.medialocationjoystreamMediaLocation)
- record.medialocationjoystreamMediaLocation.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
- await db.remove<JoystreamMediaLocation>(record)
- }
- async function removeLanguage(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(Language, where)
- if (record === undefined) throw Error(`Language not found`)
- if (record.channellanguage) record.channellanguage.map(async (c) => await removeChannel(db, { where: { id: c.id } }))
- if (record.videolanguage) record.videolanguage.map(async (v) => await removeVideo(db, { where: { id: v.id } }))
- await db.remove<Language>(record)
- }
- async function removeVideoMediaEncoding(db: DB, where: IWhereCond): Promise<void> {
- const record = await db.get(VideoMediaEncoding, where)
- if (record === undefined) throw Error(`Language not found`)
- await db.remove<VideoMediaEncoding>(record)
- }
- // ========Entity property value updates========
- async function updateMediaLocationEntityPropertyValues(
- db: DB,
- where: IWhereCond,
- props: IMediaLocation
- ): Promise<void> {
- const { httpMediaLocation, joystreamMediaLocation } = props
- const record = await db.get(MediaLocation, where)
- if (record === undefined) throw Error(`MediaLocation entity not found: ${where.where.id}`)
- if (httpMediaLocation) {
- record.httpMediaLocation = await db.get(HttpMediaLocation, { where: { id: httpMediaLocation.toString() } })
- }
- if (joystreamMediaLocation) {
- record.joystreamMediaLocation = await db.get(JoystreamMediaLocation, {
- where: { id: joystreamMediaLocation.toString() },
- })
- }
- await db.save<MediaLocation>(record)
- }
- async function updateLicenseEntityPropertyValues(db: DB, where: IWhereCond, props: ILicense): Promise<void> {
- const { knownLicense, userDefinedLicense } = props
- const record = await db.get(License, where)
- if (record === undefined) throw Error(`License entity not found: ${where.where.id}`)
- if (knownLicense) {
- record.knownLicense = await db.get(KnownLicense, { where: { id: knownLicense.toString() } })
- }
- if (userDefinedLicense) {
- record.userdefinedLicense = await db.get(UserDefinedLicense, {
- where: { id: userDefinedLicense.toString() },
- })
- }
- await db.save<License>(record)
- }
- async function updateCategoryEntityPropertyValues(db: DB, where: IWhereCond, props: ICategory): Promise<void> {
- const record = await db.get(Category, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- Object.assign(record, props)
- await db.save<Category>(record)
- }
- async function updateChannelEntityPropertyValues(db: DB, where: IWhereCond, props: IChannel): Promise<void> {
- const record = await db.get(Channel, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- if (props.language) {
- const l = await db.get(Language, { where: { id: props.language.toString() } })
- if (l === undefined) throw Error(`Language entity not found: ${props.language}`)
- record.language = l
- props.language = undefined
- }
- Object.assign(record, props)
- await db.save<Channel>(record)
- }
- async function updateVideoMediaEntityPropertyValues(db: DB, where: IWhereCond, props: IVideoMedia): Promise<void> {
- const record = await db.get(VideoMedia, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- const { encoding, location } = props
- if (encoding) {
- const e = await db.get(VideoMediaEncoding, { where: { id: encoding.toString() } })
- if (e === undefined) throw Error(`VideoMediaEncoding entity not found: ${encoding}`)
- record.encoding = e
- props.encoding = undefined
- }
- if (location) {
- const mediaLoc = await db.get(MediaLocation, { where: { id: location.toString() } })
- if (!mediaLoc) throw Error(`MediaLocation entity not found: ${location}`)
- record.location = mediaLoc
- props.location = undefined
- }
- Object.assign(record, props)
- await db.save<VideoMedia>(record)
- }
- async function updateVideoEntityPropertyValues(db: DB, where: IWhereCond, props: IVideo): Promise<void> {
- const record = await db.get<Video>(Video, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- const { channel, category, language, media, license } = props
- if (channel) {
- const c = await db.get(Channel, { where: { id: channel.toString() } })
- if (c === undefined) throw Error(`Channel entity not found: ${channel}`)
- record.channel = c
- props.channel = undefined
- }
- if (category) {
- const c = await db.get(Category, { where: { id: category.toString() } })
- if (c === undefined) throw Error(`Category entity not found: ${category}`)
- record.category = c
- props.category = undefined
- }
- if (media) {
- const m = await db.get(VideoMedia, { where: { id: media.toString() } })
- if (m === undefined) throw Error(`VideoMedia entity not found: ${channel}`)
- record.media = m
- props.media = undefined
- }
- if (license) {
- const l = await db.get(License, { where: { id: license.toString() } })
- if (!l) throw Error(`License entity not found: ${license}`)
- record.license = l
- props.license = undefined
- }
- if (language) {
- const l = await db.get(Language, { where: { id: language.toString() } })
- if (l === undefined) throw Error(`Language entity not found: ${language}`)
- record.language = l
- props.language = undefined
- }
- Object.assign(record, props)
- await db.save<Video>(record)
- }
- async function updateUserDefinedLicenseEntityPropertyValues(
- db: DB,
- where: IWhereCond,
- props: IUserDefinedLicense
- ): Promise<void> {
- const record = await db.get(UserDefinedLicense, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- Object.assign(record, props)
- await db.save<UserDefinedLicense>(record)
- }
- async function updateKnownLicenseEntityPropertyValues(db: DB, where: IWhereCond, props: IKnownLicense): Promise<void> {
- const record = await db.get(KnownLicense, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- Object.assign(record, props)
- await db.save<KnownLicense>(record)
- }
- async function updateHttpMediaLocationEntityPropertyValues(
- db: DB,
- where: IWhereCond,
- props: IHttpMediaLocation
- ): Promise<void> {
- const record = await db.get(HttpMediaLocation, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- Object.assign(record, props)
- await db.save<HttpMediaLocation>(record)
- }
- async function updateJoystreamMediaLocationEntityPropertyValues(
- db: DB,
- where: IWhereCond,
- props: IJoystreamMediaLocation
- ): Promise<void> {
- const record = await db.get(JoystreamMediaLocation, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- Object.assign(record, props)
- await db.save<JoystreamMediaLocation>(record)
- }
- async function updateLanguageEntityPropertyValues(db: DB, where: IWhereCond, props: ILanguage): Promise<void> {
- const record = await db.get(Language, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- Object.assign(record, props)
- await db.save<Language>(record)
- }
- async function updateVideoMediaEncodingEntityPropertyValues(
- db: DB,
- where: IWhereCond,
- props: IVideoMediaEncoding
- ): Promise<void> {
- const record = await db.get(VideoMediaEncoding, where)
- if (record === undefined) throw Error(`Entity not found: ${where.where.id}`)
- Object.assign(record, props)
- await db.save<VideoMediaEncoding>(record)
- }
- export {
- createCategory,
- createChannel,
- createVideoMedia,
- createVideo,
- createUserDefinedLicense,
- createKnownLicense,
- createHttpMediaLocation,
- createJoystreamMediaLocation,
- createLanguage,
- createVideoMediaEncoding,
- createLicense,
- createMediaLocation,
- removeCategory,
- removeChannel,
- removeVideoMedia,
- removeVideo,
- removeUserDefinedLicense,
- removeKnownLicense,
- removeHttpMediaLocation,
- removeJoystreamMediaLocation,
- removeLanguage,
- removeVideoMediaEncoding,
- removeMediaLocation,
- removeLicense,
- createBlockOrGetFromDatabase,
- batchCreateClassEntities,
- getClassName,
- updateCategoryEntityPropertyValues,
- updateChannelEntityPropertyValues,
- updateVideoMediaEntityPropertyValues,
- updateVideoEntityPropertyValues,
- updateUserDefinedLicenseEntityPropertyValues,
- updateHttpMediaLocationEntityPropertyValues,
- updateJoystreamMediaLocationEntityPropertyValues,
- updateKnownLicenseEntityPropertyValues,
- updateLanguageEntityPropertyValues,
- updateVideoMediaEncodingEntityPropertyValues,
- updateLicenseEntityPropertyValues,
- updateMediaLocationEntityPropertyValues,
- }
|