Skip to content

Commit

Permalink
save contenturl in content item
Browse files Browse the repository at this point in the history
  • Loading branch information
twallnerWaretec committed Feb 16, 2024
1 parent c28c955 commit 2af79e1
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 21 deletions.
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -56,16 +56,14 @@ http://localhost:3000
git pull
# check container status
docker compose -f "docker/docker-compose.build.yml" ps
# build new docker image
docker compose -f "docker/docker-compose.build.yml" build
# deploy docker image
docker compose -f "docker/docker-compose.build.yml" up -d
docker compose -f "docker/docker-compose.build.yml" up -d --build
# create default repo
docker compose -f "docker/docker-compose.build.yml" exec app yarn repco repo create default
# add cba datasource
docker compose -f "docker/docker-compose.build.yml" exec app yarn repco ds add -r default repco:datasource:cba '{"endpoint": "https://cba.media/wp-json/wp/v2"}'
# restart app container so it runs in a loop
docker restart docker-app-1
docker restart repco-app
```

### Logging
Expand Down
1 change: 1 addition & 0 deletions packages/repco-cli/src/commands/debug.ts
Expand Up @@ -83,6 +83,7 @@ function createItem() {
title: casual.catch_phrase,
content: casual.sentences(3),
summary: '{}',
contentUrl: '',
},
}
return item
Expand Down
1 change: 1 addition & 0 deletions packages/repco-core/src/datasources/activitypub.ts
Expand Up @@ -663,6 +663,7 @@ export class ActivityPubDataSource
MediaAssets: mediaAssetUris,
PrimaryGrouping: this._uriLink('account', this.account),
summary: {},
contentUrl: '',
}
const revisionUri = this._revisionUri(
'videoContent',
Expand Down
1 change: 1 addition & 0 deletions packages/repco-core/src/datasources/cba.ts
Expand Up @@ -797,6 +797,7 @@ export class CbaDataSource implements DataSource {
Concepts: conceptLinks,
MediaAssets: mediaAssetLinks,
PrimaryGrouping: this._uriLink('series', post.post_parent),
contentUrl: post._links.self[0].href,
//licenseUid
//primaryGroupingUid
//contributor
Expand Down
19 changes: 11 additions & 8 deletions packages/repco-core/src/datasources/rss.ts
Expand Up @@ -268,10 +268,10 @@ export class RssDataSource extends BaseDataSource implements DataSource {
}
}

async mapPage(feed: ParsedFeed) {
async mapPage(feed: any) {
const entities = []
for (const item of feed.items) {
entities.push(...(await this._mapItem(item)))
entities.push(...(await this._mapItem(item, feed.language)))
}
return entities
}
Expand Down Expand Up @@ -354,6 +354,7 @@ export class RssDataSource extends BaseDataSource implements DataSource {
async _extractMediaAssets(
itemUri: string,
item: RssParser.Item,
language: string,
): Promise<{ mediaAssets: Link[]; entities: EntityForm[] }> {
const entities: EntityForm[] = []
if (!item.enclosure) {
Expand All @@ -372,11 +373,11 @@ export class RssDataSource extends BaseDataSource implements DataSource {
const mediaUri = itemUri + '#media'

var titleJson: { [k: string]: any } = {}
titleJson['de'] = {
titleJson[language || 'de'] = {
value: item.title || item.guid || 'missing',
}
var descriptionJson: { [k: string]: any } = {}
descriptionJson['de'] = {
descriptionJson[language || 'de'] = {
value: '{}',
}

Expand All @@ -402,23 +403,24 @@ export class RssDataSource extends BaseDataSource implements DataSource {
return 'rss:uuid:' + createRandomId()
}

async _mapItem(item: RssParser.Item): Promise<EntityForm[]> {
async _mapItem(item: any, language: string): Promise<EntityForm[]> {
const itemUri = await this._deriveItemUri(item)
const { entities, mediaAssets } = await this._extractMediaAssets(
itemUri,
item,
language,
)

var titleJson: { [k: string]: any } = {}
titleJson['de'] = {
titleJson[language || 'de'] = {
value: item.title || item.guid || 'missing',
}
var summaryJson: { [k: string]: any } = {}
summaryJson['de'] = {
summaryJson[language || 'de'] = {
value: item.contentSnippet || '{}',
}
var contentJson: { [k: string]: any } = {}
contentJson['de'] = {
contentJson[language || 'de'] = {
value: item.content || '',
}

Expand All @@ -430,6 +432,7 @@ export class RssDataSource extends BaseDataSource implements DataSource {
pubDate: item.pubDate ? new Date(item.pubDate) : null,
PrimaryGrouping: { uri: this.endpoint.toString() },
MediaAssets: mediaAssets,
contentUrl: '',
}
const headers = {
EntityUris: [itemUri],
Expand Down
1 change: 1 addition & 0 deletions packages/repco-core/src/datasources/xrcb.ts
Expand Up @@ -451,6 +451,7 @@ export class XrcbDataSource extends BaseDataSource implements DataSource {
PublicationService: this._getPublicationService(post, { uri: '' }),
PrimaryGrouping: this._getPrimaryGrouping(post, { uri: '' }),
MediaAssets: mediaAssetUris.map((uri) => ({ uri })),
contentUrl: '',
},
headers: {
EntityUris: [this._uri('post', post.id)],
Expand Down
1 change: 1 addition & 0 deletions packages/repco-core/test/basic.ts
Expand Up @@ -35,6 +35,7 @@ test('update', async (assert) => {
content: 'badoo',
subtitle: 'asdf',
summary: 'yoo',
contentUrl: 'url',
},
}
await repo.saveEntity(input)
Expand Down
1 change: 1 addition & 0 deletions packages/repco-core/test/bench/basic.ts
Expand Up @@ -58,6 +58,7 @@ function createItem(i: number) {
title: 'Item #' + i,
content: 'foobar' + i,
summary: '{}',
contentUrl: '',
},
}
return item
Expand Down
1 change: 1 addition & 0 deletions packages/repco-core/test/datasource.ts
Expand Up @@ -71,6 +71,7 @@ class TestDataSource extends BaseDataSource implements DataSource {
content: 'helloworld',
contentFormat: 'text/plain',
summary: '{}',
contentUrl: '',
},
headers: { EntityUris: ['urn:test:content:1'] },
}
Expand Down
13 changes: 7 additions & 6 deletions packages/repco-frontend/app/graphql/types.ts
Expand Up @@ -1580,6 +1580,7 @@ export type ContentItem = {
contentFormat: Scalars['String']
/** Reads and enables pagination through a set of `ContentGrouping`. */
contentGroupings: ContentItemContentGroupingsByContentGroupingToContentItemBAndAManyToManyConnection
contentUrl: Scalars['String']
/** Reads and enables pagination through a set of `Contribution`. */
contributions: ContentItemContributionsByContentItemToContributionAAndBManyToManyConnection
/** Reads a single `License` that is related to this `ContentItem`. */
Expand Down Expand Up @@ -1717,6 +1718,8 @@ export type ContentItemCondition = {
content?: InputMaybe<Scalars['JSON']>
/** Checks for equality with the object’s `contentFormat` field. */
contentFormat?: InputMaybe<Scalars['String']>
/** Checks for equality with the object’s `contentUrl` field. */
contentUrl?: InputMaybe<Scalars['String']>
/** Checks for equality with the object’s `licenseUid` field. */
licenseUid?: InputMaybe<Scalars['String']>
/** Checks for equality with the object’s `primaryGroupingUid` field. */
Expand Down Expand Up @@ -1829,6 +1832,8 @@ export type ContentItemFilter = {
content?: InputMaybe<JsonFilter>
/** Filter by the object’s `contentFormat` field. */
contentFormat?: InputMaybe<StringFilter>
/** Filter by the object’s `contentUrl` field. */
contentUrl?: InputMaybe<StringFilter>
/** Filter by the object’s `license` relation. */
license?: InputMaybe<LicenseFilter>
/** A related `license` exists. */
Expand Down Expand Up @@ -1977,6 +1982,8 @@ export enum ContentItemsOrderBy {
ContentDesc = 'CONTENT_DESC',
ContentFormatAsc = 'CONTENT_FORMAT_ASC',
ContentFormatDesc = 'CONTENT_FORMAT_DESC',
ContentUrlAsc = 'CONTENT_URL_ASC',
ContentUrlDesc = 'CONTENT_URL_DESC',
LicenseUidAsc = 'LICENSE_UID_ASC',
LicenseUidDesc = 'LICENSE_UID_DESC',
Natural = 'NATURAL',
Expand Down Expand Up @@ -4553,7 +4560,6 @@ export type Query = {
revision?: Maybe<Revision>
/** Reads and enables pagination through a set of `Revision`. */
revisions?: Maybe<RevisionsConnection>
searchContentItems?: Maybe<Array<ContentItem>>
sourceRecord?: Maybe<SourceRecord>
/** Reads and enables pagination through a set of `SourceRecord`. */
sourceRecords?: Maybe<SourceRecordsConnection>
Expand Down Expand Up @@ -4907,11 +4913,6 @@ export type QueryRevisionsArgs = {
orderBy?: InputMaybe<Array<RevisionsOrderBy>>
}

/** The root query type which gives access points into the data universe. */
export type QuerySearchContentItemsArgs = {
searchText: Scalars['String']
}

/** The root query type which gives access points into the data universe. */
export type QuerySourceRecordArgs = {
uid: Scalars['String']
Expand Down
10 changes: 9 additions & 1 deletion packages/repco-graphql/generated/schema.graphql
Expand Up @@ -2663,6 +2663,7 @@ type ContentItem {
"""The method to use when ordering `ContentGrouping`."""
orderBy: [ContentGroupingsOrderBy!] = [PRIMARY_KEY_ASC]
): ContentItemContentGroupingsByContentGroupingToContentItemBAndAManyToManyConnection!
contentUrl: String!

"""Reads and enables pagination through a set of `Contribution`."""
contributions(
Expand Down Expand Up @@ -2867,6 +2868,9 @@ input ContentItemCondition {
"""Checks for equality with the object’s `contentFormat` field."""
contentFormat: String

"""Checks for equality with the object’s `contentUrl` field."""
contentUrl: String

"""Checks for equality with the object’s `licenseUid` field."""
licenseUid: String

Expand Down Expand Up @@ -3061,6 +3065,9 @@ input ContentItemFilter {
"""Filter by the object’s `contentFormat` field."""
contentFormat: StringFilter

"""Filter by the object’s `contentUrl` field."""
contentUrl: StringFilter

"""Filter by the object’s `license` relation."""
license: LicenseFilter

Expand Down Expand Up @@ -3300,6 +3307,8 @@ enum ContentItemsOrderBy {
CONTENT_DESC
CONTENT_FORMAT_ASC
CONTENT_FORMAT_DESC
CONTENT_URL_ASC
CONTENT_URL_DESC
LICENSE_UID_ASC
LICENSE_UID_DESC
NATURAL
Expand Down Expand Up @@ -8120,7 +8129,6 @@ type Query {
"""The method to use when ordering `Revision`."""
orderBy: [RevisionsOrderBy!] = [PRIMARY_KEY_ASC]
): RevisionsConnection
searchContentItems(searchText: String!): [ContentItem!]
sourceRecord(uid: String!): SourceRecord

"""Reads and enables pagination through a set of `SourceRecord`."""
Expand Down
19 changes: 19 additions & 0 deletions packages/repco-graphql/src/plugins/concept-filter.ts
@@ -0,0 +1,19 @@
import { makeAddPgTableConditionPlugin } from 'graphile-utils'

const ConceptFilterPlugin = makeAddPgTableConditionPlugin(
'public',
'ContentItem',
'filterName',
(build) => ({
description:
'Filters the list to ContentItems that have a specific keyword in title.',
type: build.graphql.GraphQLString,
defaultValue: '',
}),
(value, helpers, build) => {
const { sql, sqlTableAlias } = helpers
return sql.raw(`LOWER(title::text) LIKE LOWER('%${value}%')`)
},
)

export default ConceptFilterPlugin
2 changes: 1 addition & 1 deletion packages/repco-graphql/src/plugins/content-item-filter.ts
Expand Up @@ -24,7 +24,7 @@ const ContentItemFilterPlugin = makeAddPgTableConditionPlugin(
_source: false,
}

var url = 'http://localhost:9201/_search'
var url = 'http://localhost:9200/_search'
const response = fetch(url, {
method: 'POST',
headers: {
Expand Down
2 changes: 1 addition & 1 deletion packages/repco-graphql/src/plugins/elastic.ts
Expand Up @@ -23,7 +23,7 @@ const ElasticTest = makeExtendSchemaPlugin((build) => {
_source: false,
}

var url = 'http://localhost:9201/_search'
var url = 'http://localhost:9200/_search'
const response = fetch(url, {
method: 'POST',
headers: {
Expand Down
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `contentUrl` to the `ContentItem` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "ContentItem" ADD COLUMN "contentUrl" TEXT NOT NULL;
1 change: 1 addition & 0 deletions packages/repco-prisma/prisma/schema.prisma
Expand Up @@ -258,6 +258,7 @@ model ContentItem {
summary Json?
content Json @default("{}")
contentFormat String
contentUrl String
primaryGroupingUid String?
publicationServiceUid String?
Expand Down

0 comments on commit 2af79e1

Please sign in to comment.