From 4a7776c907811b0c6d1e09e7dd4082dca4458fba Mon Sep 17 00:00:00 2001 From: ascariandrea Date: Tue, 22 Nov 2022 15:13:46 +0100 Subject: [PATCH] fix(tk:shared): defined metadata filters based on nature type --- .../shared/src/endpoints/MinimalEndpoint.ts | 6 +- platforms/tktrex/backend/io/metadata.io.ts | 134 ++++++++++++++++++ .../backend/models/metadata/ForYouMetadata.ts | 16 +-- .../tktrex/backend/models/metadata/index.ts | 12 +- platforms/tktrex/backend/routes/metadata.ts | 129 ++++++++++++----- platforms/tktrex/backend/tsconfig.json | 1 + .../shared/src/arbitraries/Metadata.arb.ts | 8 +- .../src/endpoints/v2/metadata.endpoints.ts | 44 +----- .../src/endpoints/v2/public.endpoints.ts | 7 +- .../tktrex/shared/src/models/http/Search.ts | 13 ++ .../metadata/output/ListMetadata.output.ts | 17 +++ .../http/metadata/query/ListMetadata.query.ts | 37 +++++ .../src/models/metadata/FollowingMetadata.ts | 4 +- .../src/models/metadata/ForYouMetadata.ts | 18 +-- .../src/models/metadata/MetadataBase.ts | 28 +--- .../src/models/metadata/NativeMetadata.ts | 4 +- .../src/models/metadata/ProfileMetadata.ts | 4 +- .../src/models/metadata/SearchMetadata.ts | 4 +- .../shared/src/models/metadata/index.ts | 10 +- platforms/yttrex/backend/lib/automo.ts | 2 +- 20 files changed, 356 insertions(+), 142 deletions(-) create mode 100644 platforms/tktrex/backend/io/metadata.io.ts create mode 100644 platforms/tktrex/shared/src/models/http/metadata/output/ListMetadata.output.ts create mode 100644 platforms/tktrex/shared/src/models/http/metadata/query/ListMetadata.query.ts diff --git a/packages/shared/src/endpoints/MinimalEndpoint.ts b/packages/shared/src/endpoints/MinimalEndpoint.ts index 754734c53..9448a115a 100644 --- a/packages/shared/src/endpoints/MinimalEndpoint.ts +++ b/packages/shared/src/endpoints/MinimalEndpoint.ts @@ -22,10 +22,10 @@ export interface TypeOfEndpointInstance { ? // eslint-disable-next-line @typescript-eslint/no-invalid-void-type void : { - [k in keyof NonNullable]: NonNullable< + [K in keyof NonNullable]: NonNullable< E['Input'] - >[k] extends Codec - ? runtimeType[k]> + >[K] extends Codec + ? runtimeType[K]> : never; }; } diff --git a/platforms/tktrex/backend/io/metadata.io.ts b/platforms/tktrex/backend/io/metadata.io.ts new file mode 100644 index 000000000..fc79821db --- /dev/null +++ b/platforms/tktrex/backend/io/metadata.io.ts @@ -0,0 +1,134 @@ +import { APIError, toAPIError } from '@shared/errors/APIError'; +import { toValidationError } from '@shared/errors/ValidationError'; +import { Metadata } from '@shared/models/Metadata'; +import { string2Food } from '@shared/utils/food.utils'; +import { + FollowingVideoMetadata, + ForYouMetadata, + NativeMetadata, + ProfileMetadata, + SearchMetadata, + TKMetadata, +} from '@tktrex/shared/models/metadata'; +import { + CreatorType, + FollowingType, + ForYouType, + NativeType, + ProfileType, + SearchType, +} from '@tktrex/shared/models/Nature'; +import * as E from 'fp-ts/Either'; +import { pipe } from 'fp-ts/function'; +import { + FollowingVideoMetadataDB, + ForYouVideoMetadataDB, + NativeMetadataDB, + ProfileMetadataDB, + SearchMetadataDB, + TKMetadataDB, +} from '../models/metadata'; + +type SpecificM = Omit; + +export const toTKNativeMetadata = ( + { author, ...m }: SpecificM, + meta: Metadata +): NativeMetadata => { + return { + ...m, + ...meta, + author: author ?? undefined, + }; +}; + +export const toProfileMetadata = ( + m: SpecificM, + meta: Metadata +): ProfileMetadata => { + return { + ...m, + ...meta, + }; +}; + +export const toForYouMetadata = ( + { author, music, hashtags, ...m }: SpecificM, + meta: Metadata +): ForYouMetadata => { + return { + ...m, + ...meta, + author: author ?? undefined, + music: music ?? undefined, + hashtags: hashtags ?? [], + }; +}; + +export const toSearchMetadata = ( + m: SpecificM, + meta: Metadata +): SearchMetadata => { + return { ...m, ...meta }; +}; + +export const toFollowingMetadata = ( + m: SpecificM, + meta: Metadata +): FollowingVideoMetadata => { + return { ...m, ...meta }; +}; + +export const toTKMetadata = ({ + publicKey, + _id, + id, + blang, + href, + savingTime, + clientTime, + experimentId, + researchTag, + ...m +}: TKMetadataDB): E.Either => { + const meta: Metadata = { + id: id.substring(0, 10), + blang, + href, + supporter: string2Food(publicKey), + savingTime, + clientTime, + researchTag, + experimentId, + }; + + return pipe( + E.tryCatch(() => { + const mm: any = m; + switch (m.nature.type) { + case SearchType.value: { + return toSearchMetadata(mm, meta); + } + case ForYouType.value: { + return toForYouMetadata(mm, meta); + } + case FollowingType.value: { + return toFollowingMetadata(mm, meta); + } + case CreatorType.value: + case ProfileType.value: { + return toProfileMetadata(mm, meta); + } + case NativeType.value: { + return toTKNativeMetadata(mm, meta); + } + } + }, toAPIError), + E.chain((e) => + pipe( + TKMetadata.decode(e), + E.mapLeft((e) => toValidationError(TKMetadata.name, e)) + ) + ) + ); +}; diff --git a/platforms/tktrex/backend/models/metadata/ForYouMetadata.ts b/platforms/tktrex/backend/models/metadata/ForYouMetadata.ts index 5ffe547c1..3244f17e7 100644 --- a/platforms/tktrex/backend/models/metadata/ForYouMetadata.ts +++ b/platforms/tktrex/backend/models/metadata/ForYouMetadata.ts @@ -1,16 +1,16 @@ -import { ForYouVideoMetadata } from '@tktrex/shared/models/metadata/ForYouMetadata'; +import { ForYouMetadata } from '@tktrex/shared/models/metadata/ForYouMetadata'; import * as t from 'io-ts'; -const { supporter, ...metadataBaseProps } = ForYouVideoMetadata.types[0].props; -export const ForYouVideoMetadataDB = t.strict( +const { supporter, ...metadataBaseProps } = ForYouMetadata.types[0].props; +export const ForYouMetadataDB = t.strict( { ...metadataBaseProps, - ...ForYouVideoMetadata.types[1].type.props, - ...ForYouVideoMetadata.types[2].props, - ...ForYouVideoMetadata.types[3].props, + ...ForYouMetadata.types[1].type.props, + ...ForYouMetadata.types[2].props, + ...ForYouMetadata.types[3].props, _id: t.any, publicKey: t.string, }, - 'ForYouVideoMetadataDB' + 'ForYouMetadataDB' ); -export type ForYouVideoMetadataDB = t.TypeOf; +export type ForYouMetadataDB = t.TypeOf; diff --git a/platforms/tktrex/backend/models/metadata/index.ts b/platforms/tktrex/backend/models/metadata/index.ts index 272ccfc49..75d7b6034 100644 --- a/platforms/tktrex/backend/models/metadata/index.ts +++ b/platforms/tktrex/backend/models/metadata/index.ts @@ -1,6 +1,6 @@ import * as t from 'io-ts'; import { FollowingVideoMetadataDB } from './FollowingMetadata'; -import { ForYouVideoMetadataDB } from './ForYouMetadata'; +import { ForYouMetadataDB } from './ForYouMetadata'; import { NativeMetadataDB } from './NativeMetadata'; import { ProfileMetadataDB } from './ProfileMetadata'; import { SearchMetadataDB } from './SearchMetadata'; @@ -9,10 +9,18 @@ export const TKMetadataDB = t.union( [ NativeMetadataDB, SearchMetadataDB, - ForYouVideoMetadataDB, + ForYouMetadataDB, FollowingVideoMetadataDB, ProfileMetadataDB, ], 'MetadataDB' ); export type TKMetadataDB = t.TypeOf; + +export { + ProfileMetadataDB, + NativeMetadataDB, + SearchMetadataDB, + FollowingVideoMetadataDB, + ForYouMetadataDB as ForYouVideoMetadataDB, +}; diff --git a/platforms/tktrex/backend/routes/metadata.ts b/platforms/tktrex/backend/routes/metadata.ts index 2c727f56f..eee4c0237 100644 --- a/platforms/tktrex/backend/routes/metadata.ts +++ b/platforms/tktrex/backend/routes/metadata.ts @@ -1,30 +1,51 @@ +import { toAPIError } from '@shared/errors/APIError'; import { decodeOrThrowRequest } from '@shared/endpoints/helper'; -import * as foodUtils from '@shared/utils/food.utils'; -import endpoints, { - ListMetadataResponse, -} from '@tktrex/shared/endpoints/v2/metadata.endpoints'; +import endpoints from '@tktrex/shared/endpoints/v2/metadata.endpoints'; import createDebug from 'debug'; +import * as A from 'fp-ts/Array'; +import { pipe } from 'fp-ts/lib/function'; +import * as TE from 'fp-ts/TaskEither'; +import * as E from 'fp-ts/lib/Either'; +import { toTKMetadata } from '../io/metadata.io'; import _ from 'lodash'; import * as automo from '../lib/automo'; +import { throwTE } from '@shared/utils/task.utils'; +import { AppError } from '@shared/errors/AppError'; +import moment from 'moment'; +import CSV from '../lib/CSV'; +import { ListMetadataOutput } from '@tktrex/shared/models/http/metadata/output/ListMetadata.output'; +import { ListMetadataQuery } from '@tktrex/shared/models/http/metadata/query/ListMetadata.query'; const debug = createDebug('routes:public'); // This variables is used as cap in every readLimit below const PUBLIC_AMOUNT_ELEMS = 100; -const listMetadata = async ( - req: any -): Promise<{ json: ListMetadataResponse }> => { +type ListMetadataResponse = + | { json: ListMetadataOutput } + | { headers: any; text: string }; + +const listMetadata = async (req: any): Promise => { + const { query } = decodeOrThrowRequest( + endpoints.ListMetadata, + req + ) as any as { + query: ListMetadataQuery; + }; + + debug('Filter metadata with query %O', query); + const { - query: { - researchTag, - experimentId, - publicKey, - nature, - amount = PUBLIC_AMOUNT_ELEMS, - skip = 0, - }, - } = decodeOrThrowRequest(endpoints.ListMetadata, req); + researchTag, + experimentId, + publicKey, + nature, + amount = PUBLIC_AMOUNT_ELEMS, + skip = 0, + format, + } = query; + + debug('Filter metadata with query %O', query); const filter = {} as any; if (publicKey) { @@ -36,29 +57,71 @@ const listMetadata = async ( if (researchTag) { filter.researchTag = researchTag; } + if (nature) { filter['nature.type'] = nature; + switch (nature) { + case 'search': { + const { query: q } = query; + if (q) { + filter.query = { + $regex: q, + }; + } + break; + } + } } debug('Filtering metadata for %O (%d, %d)', filter, amount, skip); - const metadata = await automo - .getMetadataByFilter(filter, { - amount, - skip, - }) - .then(({ totals, data }) => ({ - totals, - data: data.map(({ publicKey, _id, id, ...m }) => ({ - ...m, - id: id.substring(0, 10), - supporter: foodUtils.string2Food(publicKey), - })), - })); - - debug('Fetched %d evidences of %d', _.size(metadata.data), metadata.totals); - - return { json: metadata }; + return pipe( + TE.tryCatch( + () => + automo.getMetadataByFilter(filter, { + amount, + skip, + }), + toAPIError + ), + TE.chain(({ totals, data }) => { + debug('Metadata by %O, %d evidences', filter, _.size(data)); + return pipe( + data.map(toTKMetadata), + A.sequence(E.Applicative), + E.map((d) => ({ data: d, totals })), + TE.fromEither + ); + }), + TE.chain((metadata): TE.TaskEither => { + if (format === 'csv') { + const csv = CSV.produceCSVv1(metadata.data); + let filename = `metadata`; + filename += experimentId ? `-experiment-${experimentId}` : ''; + filename += researchTag ? `-research_tag-${researchTag}` : ''; + filename += '-' + moment().format('YY-MM-DD') + '.csv'; + + debug( + 'VideoCSV: produced %d bytes, returning %s', + _.size(csv), + filename + ); + + // if (!_.size(csv)) return { text: 'Error, Zorry: 🤷' }; + + return TE.right({ + headers: { + 'Content-Type': 'csv/text', + 'Content-Disposition': `attachment; filename=${filename}`, + }, + text: csv, + }); + } + + return TE.right({ json: metadata }); + }), + throwTE + ); }; export { listMetadata }; diff --git a/platforms/tktrex/backend/tsconfig.json b/platforms/tktrex/backend/tsconfig.json index ba5529485..8e53690ae 100644 --- a/platforms/tktrex/backend/tsconfig.json +++ b/platforms/tktrex/backend/tsconfig.json @@ -28,6 +28,7 @@ "include": [ "./bin", "./lib", + "./io", "./models", "./routes", "./test", diff --git a/platforms/tktrex/shared/src/arbitraries/Metadata.arb.ts b/platforms/tktrex/shared/src/arbitraries/Metadata.arb.ts index 58bb5a8dd..5c33aad26 100644 --- a/platforms/tktrex/shared/src/arbitraries/Metadata.arb.ts +++ b/platforms/tktrex/shared/src/arbitraries/Metadata.arb.ts @@ -1,9 +1,9 @@ import { getArbitrary } from 'fast-check-io-ts'; import { SearchMetadata, - ForYouVideoMetadata, + ForYouMetadata, FollowingVideoMetadata, - MetadataBase, + TKMetadataBase, SearchMetadataResult, NativeMetadata, } from '../models/metadata'; @@ -12,7 +12,7 @@ import { fc } from '@shared/test'; import { subDays } from 'date-fns'; import * as t from 'io-ts'; -const metadataBaseProps = propsOmitType(MetadataBase, [ +const metadataBaseProps = propsOmitType(TKMetadataBase, [ 'id', 'clientTime', 'savingTime', @@ -101,7 +101,7 @@ export const SearchMetaDataArb = (opts: { * ForYouMetadata arbitrary * **/ -const forYouMetadataProps = propsOmitType(ForYouVideoMetadata.types[2], []); +const forYouMetadataProps = propsOmitType(ForYouMetadata.types[2], []); export const ForYouVideoMetaDataArb = getArbitrary( t.intersection([t.type(metadataBaseProps), t.type(forYouMetadataProps)]), diff --git a/platforms/tktrex/shared/src/endpoints/v2/metadata.endpoints.ts b/platforms/tktrex/shared/src/endpoints/v2/metadata.endpoints.ts index a76f42eb8..5ea5e0c66 100644 --- a/platforms/tktrex/shared/src/endpoints/v2/metadata.endpoints.ts +++ b/platforms/tktrex/shared/src/endpoints/v2/metadata.endpoints.ts @@ -1,45 +1,7 @@ import { DocumentedEndpoint } from '@shared/endpoints'; -import { Format } from '@shared/models/common'; import * as t from 'io-ts'; -import { NumberFromString } from 'io-ts-types/NumberFromString'; -import * as apiModel from '../../models'; - -export const ListMetadataOutput = t.strict( - { - totals: t.strict({ - native: t.number, - search: t.number, - foryou: t.number, - profile: t.number, - }), - data: t.array(apiModel.TKMetadata.TKMetadata), - }, - 'ListMetadataOutput', -); - -export const ListMetadataResponse = t.strict( - { - data: t.array(apiModel.TKMetadata.TKMetadata), - totals: t.record(apiModel.Nature.NatureType, t.number), - }, - 'ListMetadataResponse', -); -export type ListMetadataResponse = t.TypeOf; - -export const ListMetadataQuery = t.type( - { - publicKey: t.union([t.string, t.undefined]), - nature: t.union([apiModel.Nature.NatureType, t.undefined]), - experimentId: t.union([t.string, t.undefined]), - researchTag: t.union([t.string, t.undefined]), - amount: t.union([NumberFromString, t.number, t.undefined]), - skip: t.union([NumberFromString, t.number, t.undefined]), - format: t.union([Format, t.undefined]), - }, - 'ListMetadataQuery', -); - -export type ListMetadataQuery = t.TypeOf; +import { ListMetadataOutput } from '../../models/http/metadata/output/ListMetadata.output'; +import { ListMetadataQuery } from '../../models/http/metadata/query/ListMetadata.query'; const ListMetadata = DocumentedEndpoint({ title: 'List metadata by given filters', @@ -48,7 +10,7 @@ const ListMetadata = DocumentedEndpoint({ Method: 'GET', getPath: () => '/v2/metadata', Input: { - Query: ListMetadataQuery, + Query: ListMetadataQuery as any as t.TypeC, }, Output: ListMetadataOutput, }); diff --git a/platforms/tktrex/shared/src/endpoints/v2/public.endpoints.ts b/platforms/tktrex/shared/src/endpoints/v2/public.endpoints.ts index fb8c73bd1..34bbbf6e0 100644 --- a/platforms/tktrex/shared/src/endpoints/v2/public.endpoints.ts +++ b/platforms/tktrex/shared/src/endpoints/v2/public.endpoints.ts @@ -1,8 +1,8 @@ import { DocumentedEndpoint } from '@shared/endpoints'; -import { Format, What } from '@shared/models/common'; import { SearchQuery } from '@shared/models/http/SearchQuery'; import * as t from 'io-ts'; import * as apiModel from '../../models'; +import { GetSearchByQueryInputParams } from '../../models/http/Search'; export const Handshake = DocumentedEndpoint({ title: 'Handshake', @@ -42,10 +42,7 @@ const GetSearchByQuery = DocumentedEndpoint({ Method: 'GET', getPath: ({ query, format }) => `/v2/public/query/${query}/${format}`, Input: { - Params: t.type({ - query: What, - format: Format, - }), + Params: GetSearchByQueryInputParams, Query: SearchQuery, }, Output: apiModel.Public.GetSearchByQueryOutput, diff --git a/platforms/tktrex/shared/src/models/http/Search.ts b/platforms/tktrex/shared/src/models/http/Search.ts index 3eff3c275..7ee070610 100644 --- a/platforms/tktrex/shared/src/models/http/Search.ts +++ b/platforms/tktrex/shared/src/models/http/Search.ts @@ -1,4 +1,17 @@ import * as t from 'io-ts'; +import { What, Format } from '@shared/models/common'; + +export const GetSearchByQueryInputParams = t.type( + { + query: What, + format: Format, + }, + 'GetSearchByQueryInputParams', +); + +export type GetSearchByQueryInputParams = t.TypeOf< + typeof GetSearchByQueryInputParams +>; export const GetSearchByQueryOutput = t.type( { diff --git a/platforms/tktrex/shared/src/models/http/metadata/output/ListMetadata.output.ts b/platforms/tktrex/shared/src/models/http/metadata/output/ListMetadata.output.ts new file mode 100644 index 000000000..0c0f63d5a --- /dev/null +++ b/platforms/tktrex/shared/src/models/http/metadata/output/ListMetadata.output.ts @@ -0,0 +1,17 @@ +import * as t from 'io-ts'; +import * as TKMetadata from '../../../metadata'; + +export const ListMetadataOutput = t.strict( + { + totals: t.strict({ + native: t.number, + search: t.number, + foryou: t.number, + profile: t.number, + }), + data: t.array(TKMetadata.TKMetadata), + }, + 'ListMetadataOutput', +); + +export type ListMetadataOutput = t.TypeOf; diff --git a/platforms/tktrex/shared/src/models/http/metadata/query/ListMetadata.query.ts b/platforms/tktrex/shared/src/models/http/metadata/query/ListMetadata.query.ts new file mode 100644 index 000000000..3611a0cec --- /dev/null +++ b/platforms/tktrex/shared/src/models/http/metadata/query/ListMetadata.query.ts @@ -0,0 +1,37 @@ +import { Format } from '@shared/models/common'; +import * as t from 'io-ts'; +import { NumberFromString } from 'io-ts-types/NumberFromString'; +import * as Nature from '../../../Nature'; + +export const ListVideoMetadataQuery = t.type( + { + nature: Nature.VideoType, + }, + 'ListVideoMetadataQuery', +); + +export const ListSearchMetadataQuery = t.type( + { + nature: Nature.SearchType, + query: t.union([t.string, t.undefined]), + }, + 'ListSearchMetadataQuery', +); + +export const ListMetadataQuery = t.intersection( + [ + t.type({ + publicKey: t.union([t.string, t.undefined]), + nature: t.union([Nature.NatureType, t.undefined]), + experimentId: t.union([t.string, t.undefined]), + researchTag: t.union([t.string, t.undefined]), + amount: t.union([NumberFromString, t.number, t.undefined]), + skip: t.union([NumberFromString, t.number, t.undefined]), + format: t.union([Format, t.undefined]), + }), + t.union([ListVideoMetadataQuery, ListSearchMetadataQuery]), + ], + 'ListMetadataQuery', +); + +export type ListMetadataQuery = t.TypeOf; diff --git a/platforms/tktrex/shared/src/models/metadata/FollowingMetadata.ts b/platforms/tktrex/shared/src/models/metadata/FollowingMetadata.ts index 1df47d704..79b39b1ee 100644 --- a/platforms/tktrex/shared/src/models/metadata/FollowingMetadata.ts +++ b/platforms/tktrex/shared/src/models/metadata/FollowingMetadata.ts @@ -1,12 +1,12 @@ import * as t from 'io-ts'; import { FollowingN } from '../Nature'; import { Author } from './Author'; -import { MetadataBase } from './MetadataBase'; +import { TKMetadataBase } from './MetadataBase'; import { Music } from './Music'; export const FollowingVideoMetadata = t.intersection( [ - MetadataBase, + TKMetadataBase, FollowingN, t.type({ nature: FollowingN }), t.type( diff --git a/platforms/tktrex/shared/src/models/metadata/ForYouMetadata.ts b/platforms/tktrex/shared/src/models/metadata/ForYouMetadata.ts index 765fadeca..b57d49cb6 100644 --- a/platforms/tktrex/shared/src/models/metadata/ForYouMetadata.ts +++ b/platforms/tktrex/shared/src/models/metadata/ForYouMetadata.ts @@ -1,27 +1,27 @@ import * as t from 'io-ts'; import { ForYouN } from '../Nature'; import { Author } from './Author'; -import { MetadataBase } from './MetadataBase'; +import { TKMetadataBase } from './MetadataBase'; import { Metrics } from './Metrics'; import { Music } from './Music'; -export const ForYouVideoMetadata = t.intersection( +export const ForYouMetadata = t.intersection( [ - MetadataBase, + TKMetadataBase, ForYouN, t.type({ nature: ForYouN }), t.type( { // baretext is the smallest part of the description, // not including the tags - baretext: t.string, + baretext: t.union([t.string, t.undefined]), // description is the whole text written below the video, // including the tags - description: t.string, + description: t.union([t.string, t.undefined]), - author: Author, - music: Music, + author: t.union([Author, t.undefined]), + music: t.union([Music, t.undefined]), // the hashtags, with their leading # // note: they do not seem to be cleaned at the moment, // some have trailing whitespace @@ -31,7 +31,7 @@ export const ForYouVideoMetadata = t.intersection( 'foryou', ), ], - 'ForYouVideoMetadata', + 'ForYouMetadata', ); -export type ForYouVideoMetadata = t.TypeOf; +export type ForYouMetadata = t.TypeOf; diff --git a/platforms/tktrex/shared/src/models/metadata/MetadataBase.ts b/platforms/tktrex/shared/src/models/metadata/MetadataBase.ts index 6e46746ba..fdb353af4 100644 --- a/platforms/tktrex/shared/src/models/metadata/MetadataBase.ts +++ b/platforms/tktrex/shared/src/models/metadata/MetadataBase.ts @@ -1,30 +1,12 @@ +import { Metadata } from '@shared/models/Metadata'; import * as t from 'io-ts'; -import { date } from 'io-ts-types/lib/date'; -import { DateFromISOString } from 'io-ts-types/lib/DateFromISOString'; -export const MetadataBase = t.type( +export const TKMetadataBase = t.type( { - id: t.string, - /** - * The href where the evidence has been collected - */ - href: t.string, - /** - * The supporter publicKey - * - * TODO: it may be replaced by the supporter id - */ - supporter: t.string, + ...Metadata.type.props, timelineId: t.string, - researchTag: t.union([t.string, t.undefined]), - experimentId: t.union([t.string, t.undefined]), - /** - * DB saving time - */ - clientTime: t.union([date, DateFromISOString]), - savingTime: t.union([date, DateFromISOString]), }, - 'MetadataBase', + 'TKMetadataBase' ); -export type MetadataBase = t.TypeOf; +export type TKMetadataBase = t.TypeOf; diff --git a/platforms/tktrex/shared/src/models/metadata/NativeMetadata.ts b/platforms/tktrex/shared/src/models/metadata/NativeMetadata.ts index 14e8030af..8372a7cc4 100644 --- a/platforms/tktrex/shared/src/models/metadata/NativeMetadata.ts +++ b/platforms/tktrex/shared/src/models/metadata/NativeMetadata.ts @@ -1,13 +1,13 @@ import * as t from 'io-ts'; import { NativeVideoN } from '../Nature'; import { Author } from './Author'; -import { MetadataBase } from './MetadataBase'; +import { TKMetadataBase } from './MetadataBase'; import { Metrics } from './Metrics'; import { Music } from './Music'; export const NativeMetadata = t.intersection( [ - MetadataBase, + TKMetadataBase, NativeVideoN, t.type({ nature: NativeVideoN }, 'NativeMetadataType'), t.type( diff --git a/platforms/tktrex/shared/src/models/metadata/ProfileMetadata.ts b/platforms/tktrex/shared/src/models/metadata/ProfileMetadata.ts index e36e678cf..f8bd48443 100644 --- a/platforms/tktrex/shared/src/models/metadata/ProfileMetadata.ts +++ b/platforms/tktrex/shared/src/models/metadata/ProfileMetadata.ts @@ -1,6 +1,6 @@ import * as t from 'io-ts'; import { NativeVideoN, ProfileN } from '../Nature'; -import { MetadataBase } from './MetadataBase'; +import { TKMetadataBase } from './MetadataBase'; export const ProfileResult = t.type( { @@ -19,7 +19,7 @@ export type ProfileResult = t.TypeOf; export const ProfileMetadata = t.intersection( [ - MetadataBase, + TKMetadataBase, ProfileN, t.type({ nature: ProfileN }), t.type({ diff --git a/platforms/tktrex/shared/src/models/metadata/SearchMetadata.ts b/platforms/tktrex/shared/src/models/metadata/SearchMetadata.ts index e8a160d81..8a7d1acd0 100644 --- a/platforms/tktrex/shared/src/models/metadata/SearchMetadata.ts +++ b/platforms/tktrex/shared/src/models/metadata/SearchMetadata.ts @@ -1,6 +1,6 @@ import * as t from 'io-ts'; import { NativeVideoN, Nature, SearchN } from '../Nature'; -import { MetadataBase } from './MetadataBase'; +import { TKMetadataBase } from './MetadataBase'; export const ResultLinked = t.type( { link: Nature, desc: t.string }, @@ -21,7 +21,7 @@ export const SearchMetadataResult = t.type( ); export const SearchMetadata = t.intersection( [ - MetadataBase, + TKMetadataBase, SearchN, t.type({ nature: SearchN }), t.type( diff --git a/platforms/tktrex/shared/src/models/metadata/index.ts b/platforms/tktrex/shared/src/models/metadata/index.ts index 786e708f5..ff00b364a 100644 --- a/platforms/tktrex/shared/src/models/metadata/index.ts +++ b/platforms/tktrex/shared/src/models/metadata/index.ts @@ -1,15 +1,15 @@ import * as t from 'io-ts'; -import { MetadataBase } from './MetadataBase'; +import { TKMetadataBase } from './MetadataBase'; import { FollowingVideoMetadata } from './FollowingMetadata'; -import { ForYouVideoMetadata } from './ForYouMetadata'; +import { ForYouMetadata } from './ForYouMetadata'; import { NativeMetadata } from './NativeMetadata'; import { ProfileMetadata } from './ProfileMetadata'; import { SearchMetadata, SearchMetadataResult } from './SearchMetadata'; export const TKMetadata = t.union( [ + ForYouMetadata, SearchMetadata, - ForYouVideoMetadata, FollowingVideoMetadata, NativeMetadata, ProfileMetadata, @@ -20,9 +20,9 @@ export const TKMetadata = t.union( export type TKMetadata = t.TypeOf; export { - MetadataBase, + TKMetadataBase, FollowingVideoMetadata, - ForYouVideoMetadata, + ForYouMetadata, NativeMetadata, SearchMetadata, SearchMetadataResult, diff --git a/platforms/yttrex/backend/lib/automo.ts b/platforms/yttrex/backend/lib/automo.ts index 789cf044d..b5d219597 100644 --- a/platforms/yttrex/backend/lib/automo.ts +++ b/platforms/yttrex/backend/lib/automo.ts @@ -26,7 +26,7 @@ import { Supporter } from '@yttrex/shared/models/Supporter'; import { differenceInSeconds, formatDistance } from 'date-fns'; import D from 'debug'; import _ from 'lodash'; -import { Ad } from 'models/Ad'; +import { Ad } from '../models/Ad'; import moment from 'moment'; import { DeleteResult, Filter, MongoClient } from 'mongodb'; import nconf from 'nconf';