Skip to content

Commit 34873da

Browse files
authored
Merge pull request #448 from impresso/develop
Release v3.0.4
2 parents b8d64a3 + 4f61fd7 commit 34873da

18 files changed

+736
-599
lines changed

package-lock.json

Lines changed: 402 additions & 309 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"moment": "^2.24.0",
104104
"multer": "^1.4.5-lts.1",
105105
"mustache": "^2.3.2",
106-
"mysql2": "^2.3.3",
106+
"mysql2": "^3.11.3",
107107
"nanoid": "^2.0.1",
108108
"neo4j-driver": "^1.7.2",
109109
"node-eta": "^0.9.0",

src/hooks/access-rights.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const obfuscate = () => context => {
7878
}
7979
break
8080
case 'articles.get':
81+
case 'content-items.get':
8182
if (shouldBeObfuscated(context.result.issue.accessRights)) {
8283
debug(
8384
`${prefix} issue obfuscated due to context.result.issue.accessRights: ${context.result.issue.accessRights}`
@@ -86,6 +87,7 @@ const obfuscate = () => context => {
8687
}
8788
break
8889
case 'articles.find':
90+
case 'content-items.find':
8991
case 'articles-suggestions.get':
9092
debug(`${prefix} verify accessRights per article issue`)
9193
for (let i = 0, l = context.result.data.length; i < l; i += 1) {

src/schema/schemas/Article.json renamed to src/schema/schemas/ContentItem.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"title": "Article",
4-
"description": "A journal/magazine article",
3+
"title": "ContentItem",
4+
"description": "A journal/magazine content item (article, advertisement, etc.)",
55
"type": "object",
66
"additionalProperties": false,
77
"properties": {
88
"uid": {
99
"type": "string",
10-
"description": "The unique identifier of the article"
10+
"description": "The unique identifier of the content item"
1111
},
1212
"type": {
1313
"type": "string",
14-
"description": "The type of the article. NOTE: may be empty."
14+
"description": "The type of the content item. NOTE: may be empty."
1515
},
1616
"title": {
1717
"type": "string",
18-
"description": "The title of the article"
18+
"description": "The title of the content item"
1919
},
2020
"size": {
2121
"type": "integer",
22-
"description": "The size of the article in characters"
22+
"description": "The size of the content item in characters"
2323
},
2424
"nbPages": {
2525
"type": "integer",
26-
"description": "The number of pages in this article"
26+
"description": "The number of pages in this content item"
2727
},
2828
"pages": {
2929
"type": "array",
@@ -37,7 +37,7 @@
3737
},
3838
"excerpt": {
3939
"type": "string",
40-
"description": "The excerpt of the article"
40+
"description": "The excerpt of the content item"
4141
},
4242
"locations": {
4343
"type": "array",
@@ -53,21 +53,21 @@
5353
},
5454
"language": {
5555
"type": "string",
56-
"description": "The language code of the article"
56+
"description": "The language code of the content item"
5757
},
5858
"issue": {
5959
"$ref": "./NewspaperIssue.json"
6060
},
6161
"matches": {
6262
"type": "array",
6363
"items": {
64-
"$ref": "./ArticleMatch.json"
64+
"$ref": "./ContentItemMatch.json"
6565
}
6666
},
6767
"regions": {
6868
"type": "array",
6969
"items": {
70-
"$ref": "./ArticleRegion.json"
70+
"$ref": "./ContentItemRegion.json"
7171
}
7272
},
7373
"regionBreaks": {
@@ -93,17 +93,17 @@
9393
},
9494
"date": {
9595
"oneOf": [
96-
{ "type": "string", "description": "The date of the article", "format": "date-time" },
96+
{ "type": "string", "description": "The date of the content item", "format": "date-time" },
9797
{ "type": "null" }
9898
]
9999
},
100100
"year": {
101101
"type": "integer",
102-
"description": "The year of the article"
102+
"description": "The year of the content item"
103103
},
104104
"country": {
105105
"type": "string",
106-
"description": "The country code of the article"
106+
"description": "The country code of the content item"
107107
},
108108
"tags": {
109109
"type": "array",
@@ -119,15 +119,15 @@
119119
"$ref": "./Newspaper.json"
120120
},
121121
"dataProvider": {
122-
"oneOf": [{ "type": "string", "description": "The provider article" }, { "type": "null" }]
122+
"oneOf": [{ "type": "string", "description": "The provider of the content item" }, { "type": "null" }]
123123
},
124124
"topics": {
125125
"type": "array",
126-
"items": { "$ref": "./ArticleTopic.json" }
126+
"items": { "$ref": "./ContentItemTopic.json" }
127127
},
128128
"content": {
129129
"type": "string",
130-
"description": "The content of the article"
130+
"description": "The content of the content item"
131131
},
132132
"mentions": {
133133
"type": "array",

src/schema/schemas/ArticleMatch.json renamed to src/schema/schemas/ContentItemMatch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"title": "ArticleMatch",
3+
"title": "ContentItemMatch",
44
"description": "TODO",
55
"type": "object",
66
"additionalProperties": false,

src/schema/schemas/ArticleRegion.json renamed to src/schema/schemas/ContentItemRegion.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"title": "ArticleRegion",
3+
"title": "ContentItemRegion",
44
"description": "TODO",
55
"type": "object",
66
"additionalProperties": false,

src/schema/schemas/ArticleTopic.json renamed to src/schema/schemas/ContentItemTopic.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"title": "ArticleTopic",
3+
"title": "ContentItemTopic",
44
"description": "TODO",
55
"type": "object",
66
"additionalProperties": false,

src/services/articles-search/articles-search.class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ArticlesSearch {
1414
this.options = options || {}
1515
/** @type {import('../../cachedSolr').CachedSolrClient} */
1616
this.solr = app.service('cachedSolr')
17-
this.articlesService = app.service('articles')
17+
this.articlesService = app.service('content-items')
1818
}
1919

2020
/**

src/services/articles/articles.schema.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ const findParameters: MethodParameter[] = [
3030
* NOTE: Keep this in sync with validators in search.hooks.ts
3131
*/
3232
export const docs: ServiceSwaggerOptions = {
33-
description: 'Articles',
33+
description: 'Content items',
3434
securities: ['find', 'get'],
3535
operations: {
3636
find: {
37-
operationId: 'findArticles',
38-
description: 'Find articles that match the given query',
37+
operationId: 'findContentItem',
38+
description: 'Find content items that match the given query',
3939
parameters: findParameters,
4040
responses: getStandardResponses({
4141
method: 'find',
42-
schema: 'Article',
42+
schema: 'ContentItem',
4343
}),
4444
},
4545
get: {
46-
operationId: 'getArticle',
47-
description: 'Get an article by its UID',
46+
operationId: 'getContentItem',
47+
description: 'Get a content item by its UID',
4848
parameters: [
4949
{
5050
in: 'path',
@@ -53,12 +53,12 @@ export const docs: ServiceSwaggerOptions = {
5353
schema: {
5454
type: 'string',
5555
},
56-
description: 'UID of the article',
56+
description: 'UID of the content item',
5757
},
5858
],
5959
responses: getStandardResponses({
6060
method: 'get',
61-
schema: 'Article',
61+
schema: 'ContentItem',
6262
}),
6363
},
6464
},

src/services/articles/articles.service.js

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { ServiceOptions } from '@feathersjs/feathers'
2+
import { createSwaggerServiceOptions } from 'feathers-swagger'
3+
import { ImpressoApplication } from '../../types'
4+
import { docs } from './articles.schema'
5+
6+
// Initializes the `articles` service on path `/articles`
7+
const createService = require('./articles.class')
8+
const hooks = require('./articles.hooks')
9+
10+
export default function (app: ImpressoApplication) {
11+
const paginate = app.get('paginate')
12+
13+
/**
14+
* Even though the service is historically called 'articles'
15+
* it technically deals with content items. We keep the original prefix
16+
* for the internal use (web app), but expose it as 'content-items' for the public API.
17+
*/
18+
const prefix = app.get('isPublicApi') ? '/content-items' : '/articles'
19+
20+
const options = {
21+
name: 'articles',
22+
paginate,
23+
app,
24+
}
25+
26+
const svc = createService(options)
27+
28+
// Initialize our service with any options it requires
29+
app.use('/content-items', svc, {
30+
events: [],
31+
docs: createSwaggerServiceOptions({ schemas: {}, docs }),
32+
} as ServiceOptions)
33+
34+
// Get our initialized service so that we can register hooks and filters
35+
const service = app.service('content-items')
36+
37+
service.hooks(hooks)
38+
39+
if (!app.get('isPublicApi')) {
40+
// Expose the service as 'articles' for the web app
41+
app.use('/articles', service)
42+
}
43+
}
Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,66 @@
11
/* eslint-disable no-unused-vars */
2-
const debug = require('debug')('impresso/services:search');
3-
const { NotFound, NotImplemented } = require('@feathersjs/errors');
4-
const { protobuf } = require('impresso-jscommons');
5-
const solr = require('../../solr');
6-
const article = require('../../models/articles.model');
2+
const debug = require('debug')('impresso/services:search-exporter')
3+
const { NotFound, NotImplemented } = require('@feathersjs/errors')
4+
const { protobuf } = require('impresso-jscommons')
5+
const solr = require('../../solr')
6+
const article = require('../../models/articles.model')
77

88
class Service {
9-
constructor (options) {
10-
this.solr = solr.client(options.app.get('solr'), options.app.get('solrConnectionPool'));
11-
this.name = options.name;
12-
this.options = options || {};
13-
this.app = options.app;
9+
constructor(options) {
10+
this.solr = solr.client(options.app.get('solr'), options.app.get('solrConnectionPool'))
11+
this.name = options.name
12+
this.options = options || {}
13+
this.app = options.app
14+
debug('Service created')
1415
}
1516

16-
async create (data, params) {
17-
const client = this.app.get('celeryClient');
17+
async create(data, params) {
18+
const client = this.app.get('celeryClient')
1819
if (!client) {
19-
return {};
20+
return {}
2021
}
2122

22-
const q = params.sanitized.sq;
23-
debug('[create] from solr query:', q, 'filters:', params.sanitized.filters);
23+
const q = params.sanitized.sq
24+
debug('[create] from solr query:', q, 'filters:', params.sanitized.filters)
2425

2526
const pq = protobuf.searchQuery.serialize({
2627
filters: params.sanitized.filters,
27-
});
28-
debug('[create] protobuffered:', pq);
28+
})
29+
debug('[create] protobuffered:', pq)
2930

30-
return client.run({
31-
task: 'impresso.tasks.export_query_as_csv',
32-
args: [
33-
// user id
34-
params.user.id,
35-
// query
36-
q,
37-
// description
38-
data.sanitized.description || '',
39-
// query_hash
40-
pq,
41-
],
42-
}).catch((err) => {
43-
if (err.result.exc_type === 'DoesNotExist') {
44-
throw new NotFound(err.result.exc_message);
45-
} else if (err.result.exc_type === 'OperationalError') {
46-
// probably db is not availabe
47-
throw new NotImplemented();
48-
}
49-
console.error(err);
50-
throw new NotImplemented();
51-
});
31+
return client
32+
.run({
33+
task: 'impresso.tasks.export_query_as_csv',
34+
args: [
35+
// user id
36+
params.user.id,
37+
// query
38+
q,
39+
// description
40+
data.sanitized.description || '',
41+
// query_hash
42+
pq,
43+
],
44+
})
45+
.then(result => {
46+
debug('[create] result:', result)
47+
return { taskId: result.taskId }
48+
})
49+
.catch(err => {
50+
if (err.result.exc_type === 'DoesNotExist') {
51+
throw new NotFound(err.result.exc_message)
52+
} else if (err.result.exc_type === 'OperationalError') {
53+
// probably db is not availabe
54+
throw new NotImplemented()
55+
}
56+
console.error(err)
57+
throw new NotImplemented()
58+
})
5259
}
5360
}
5461

5562
module.exports = function (options) {
56-
return new Service(options);
57-
};
63+
return new Service(options)
64+
}
5865

59-
module.exports.Service = Service;
66+
module.exports.Service = Service

0 commit comments

Comments
 (0)