From c741547b1020ec966108f61cc54d26593e089fb0 Mon Sep 17 00:00:00 2001 From: Alex Ware Date: Mon, 21 Oct 2019 15:24:37 +0100 Subject: [PATCH 1/4] Add a flag to print sent articles showing them as such for analysis and sharing. --- projects/backend/capi/articles.ts | 10 ++++++++-- projects/common/src/index.ts | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/projects/backend/capi/articles.ts b/projects/backend/capi/articles.ts index 6b02ebfa6c..e65d7f3e65 100644 --- a/projects/backend/capi/articles.ts +++ b/projects/backend/capi/articles.ts @@ -87,6 +87,7 @@ const getMainMediaAtom = ( const parseArticleResult = async ( result: IContent, + print: boolean, ): Promise<[number, CAPIContent]> => { const path = result.id console.log(`Parsing CAPI response for ${path}`) @@ -148,6 +149,7 @@ const parseArticleResult = async ( elements, starRating, mainMedia: getMainMediaAtom(result.blocks), + print, }, ] return article @@ -167,6 +169,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', elements, + print, }, ] @@ -187,6 +190,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', elements, + print, }, ] @@ -228,6 +232,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', crossword, + print, }, ] @@ -258,6 +263,7 @@ const parseArticleResult = async ( html: `
${JSON.stringify(result.apiUrl)}
`, }, ], + print, }, ] } @@ -280,7 +286,7 @@ export const getArticles = async ( capi: 'printsent' | 'search', ): Promise<{ [key: string]: CAPIContent }> => { const paths = ids.map(_ => `internal-code/page/${_}`) - + const print = capi === 'printsent' const endpoint = capi === 'printsent' ? printsent(paths) : search(paths) if (endpoint.length > 1000) { console.warn( @@ -316,7 +322,7 @@ export const getArticles = async ( const data = SearchResponseCodec.decode(input) const results: IContent[] = data.results const articlePromises = await Promise.all( - results.map(result => attempt(parseArticleResult(result))), + results.map(result => attempt(parseArticleResult(result, print))), ) //If we fail to get an article in a collection we just ignore it and move on. diff --git a/projects/common/src/index.ts b/projects/common/src/index.ts index 46375c9a83..f72060857c 100644 --- a/projects/common/src/index.ts +++ b/projects/common/src/index.ts @@ -166,6 +166,7 @@ export interface Content extends WithKey { showQuotedHeadline: boolean mediaType: MediaType sportScore?: string + print: boolean } export interface Article extends Content { type: 'article' From be047c7a9f96cd6ceb2dabb854ec088d497065a6 Mon Sep 17 00:00:00 2001 From: Alex Ware Date: Mon, 21 Oct 2019 15:43:14 +0100 Subject: [PATCH 2/4] fix a test --- projects/backend/__tests__/helpers/fixtures.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/backend/__tests__/helpers/fixtures.ts b/projects/backend/__tests__/helpers/fixtures.ts index 9db92142fe..527ef89dc1 100644 --- a/projects/backend/__tests__/helpers/fixtures.ts +++ b/projects/backend/__tests__/helpers/fixtures.ts @@ -36,6 +36,7 @@ const Content = ( showQuotedHeadline, mediaType, sportScore, + print: false, }) const Article = ({ From 13c3f63a34eebab52b87abb55d11781f6ee64d5b Mon Sep 17 00:00:00 2001 From: Alex Ware Date: Tue, 22 Oct 2019 11:26:52 +0100 Subject: [PATCH 3/4] rename to fromPrint --- .../src/tasks/image/helpers/media.spec.ts | 1 + projects/backend/__tests__/helpers/fixtures.ts | 2 +- projects/backend/capi/articles.ts | 16 ++++++++-------- projects/common/src/index.ts | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/projects/archiver/src/tasks/image/helpers/media.spec.ts b/projects/archiver/src/tasks/image/helpers/media.spec.ts index 5d2be22c38..688fa491f1 100644 --- a/projects/archiver/src/tasks/image/helpers/media.spec.ts +++ b/projects/archiver/src/tasks/image/helpers/media.spec.ts @@ -20,6 +20,7 @@ test('getImage', () => { showQuotedHeadline: false, mediaType: 'Image', elements: [], + fromPrint: true, } expect(getImagesFromArticle(article)).toContain(image) }) diff --git a/projects/backend/__tests__/helpers/fixtures.ts b/projects/backend/__tests__/helpers/fixtures.ts index 527ef89dc1..033975589e 100644 --- a/projects/backend/__tests__/helpers/fixtures.ts +++ b/projects/backend/__tests__/helpers/fixtures.ts @@ -36,7 +36,7 @@ const Content = ( showQuotedHeadline, mediaType, sportScore, - print: false, + fromPrint: false, }) const Article = ({ diff --git a/projects/backend/capi/articles.ts b/projects/backend/capi/articles.ts index e65d7f3e65..746f3e58f2 100644 --- a/projects/backend/capi/articles.ts +++ b/projects/backend/capi/articles.ts @@ -87,7 +87,7 @@ const getMainMediaAtom = ( const parseArticleResult = async ( result: IContent, - print: boolean, + fromPrint: boolean, ): Promise<[number, CAPIContent]> => { const path = result.id console.log(`Parsing CAPI response for ${path}`) @@ -149,7 +149,7 @@ const parseArticleResult = async ( elements, starRating, mainMedia: getMainMediaAtom(result.blocks), - print, + fromPrint, }, ] return article @@ -169,7 +169,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', elements, - print, + fromPrint, }, ] @@ -190,7 +190,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', elements, - print, + fromPrint, }, ] @@ -232,7 +232,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', crossword, - print, + fromPrint, }, ] @@ -263,7 +263,7 @@ const parseArticleResult = async ( html: `
${JSON.stringify(result.apiUrl)}
`, }, ], - print, + fromPrint, }, ] } @@ -286,7 +286,7 @@ export const getArticles = async ( capi: 'printsent' | 'search', ): Promise<{ [key: string]: CAPIContent }> => { const paths = ids.map(_ => `internal-code/page/${_}`) - const print = capi === 'printsent' + const fromPrint = capi === 'printsent' const endpoint = capi === 'printsent' ? printsent(paths) : search(paths) if (endpoint.length > 1000) { console.warn( @@ -322,7 +322,7 @@ export const getArticles = async ( const data = SearchResponseCodec.decode(input) const results: IContent[] = data.results const articlePromises = await Promise.all( - results.map(result => attempt(parseArticleResult(result, print))), + results.map(result => attempt(parseArticleResult(result, fromPrint))), ) //If we fail to get an article in a collection we just ignore it and move on. diff --git a/projects/common/src/index.ts b/projects/common/src/index.ts index f72060857c..7456dbe8f5 100644 --- a/projects/common/src/index.ts +++ b/projects/common/src/index.ts @@ -166,7 +166,7 @@ export interface Content extends WithKey { showQuotedHeadline: boolean mediaType: MediaType sportScore?: string - print: boolean + fromPrint: boolean } export interface Article extends Content { type: 'article' From 7f2ced191100a668f518dec9977c25ea94406830 Mon Sep 17 00:00:00 2001 From: Alex Ware Date: Tue, 22 Oct 2019 14:19:14 +0100 Subject: [PATCH 4/4] rename --- .../src/tasks/image/helpers/media.spec.ts | 2 +- projects/backend/__tests__/helpers/fixtures.ts | 2 +- projects/backend/capi/articles.ts | 16 ++++++++-------- projects/common/src/index.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/projects/archiver/src/tasks/image/helpers/media.spec.ts b/projects/archiver/src/tasks/image/helpers/media.spec.ts index 688fa491f1..1f6183d9e9 100644 --- a/projects/archiver/src/tasks/image/helpers/media.spec.ts +++ b/projects/archiver/src/tasks/image/helpers/media.spec.ts @@ -20,7 +20,7 @@ test('getImage', () => { showQuotedHeadline: false, mediaType: 'Image', elements: [], - fromPrint: true, + isFromPrint: true, } expect(getImagesFromArticle(article)).toContain(image) }) diff --git a/projects/backend/__tests__/helpers/fixtures.ts b/projects/backend/__tests__/helpers/fixtures.ts index 033975589e..ed7be44903 100644 --- a/projects/backend/__tests__/helpers/fixtures.ts +++ b/projects/backend/__tests__/helpers/fixtures.ts @@ -36,7 +36,7 @@ const Content = ( showQuotedHeadline, mediaType, sportScore, - fromPrint: false, + isFromPrint: false, }) const Article = ({ diff --git a/projects/backend/capi/articles.ts b/projects/backend/capi/articles.ts index 746f3e58f2..4012f0e286 100644 --- a/projects/backend/capi/articles.ts +++ b/projects/backend/capi/articles.ts @@ -87,7 +87,7 @@ const getMainMediaAtom = ( const parseArticleResult = async ( result: IContent, - fromPrint: boolean, + isFromPrint: boolean, ): Promise<[number, CAPIContent]> => { const path = result.id console.log(`Parsing CAPI response for ${path}`) @@ -149,7 +149,7 @@ const parseArticleResult = async ( elements, starRating, mainMedia: getMainMediaAtom(result.blocks), - fromPrint, + isFromPrint, }, ] return article @@ -169,7 +169,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', elements, - fromPrint, + isFromPrint, }, ] @@ -190,7 +190,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', elements, - fromPrint, + isFromPrint, }, ] @@ -232,7 +232,7 @@ const parseArticleResult = async ( bylineHtml: bylineHtml || '', standfirst: trail || '', crossword, - fromPrint, + isFromPrint, }, ] @@ -263,7 +263,7 @@ const parseArticleResult = async ( html: `
${JSON.stringify(result.apiUrl)}
`, }, ], - fromPrint, + isFromPrint, }, ] } @@ -286,7 +286,7 @@ export const getArticles = async ( capi: 'printsent' | 'search', ): Promise<{ [key: string]: CAPIContent }> => { const paths = ids.map(_ => `internal-code/page/${_}`) - const fromPrint = capi === 'printsent' + const isFromPrint = capi === 'printsent' const endpoint = capi === 'printsent' ? printsent(paths) : search(paths) if (endpoint.length > 1000) { console.warn( @@ -322,7 +322,7 @@ export const getArticles = async ( const data = SearchResponseCodec.decode(input) const results: IContent[] = data.results const articlePromises = await Promise.all( - results.map(result => attempt(parseArticleResult(result, fromPrint))), + results.map(result => attempt(parseArticleResult(result, isFromPrint))), ) //If we fail to get an article in a collection we just ignore it and move on. diff --git a/projects/common/src/index.ts b/projects/common/src/index.ts index 7456dbe8f5..d986a19097 100644 --- a/projects/common/src/index.ts +++ b/projects/common/src/index.ts @@ -166,7 +166,7 @@ export interface Content extends WithKey { showQuotedHeadline: boolean mediaType: MediaType sportScore?: string - fromPrint: boolean + isFromPrint: boolean } export interface Article extends Content { type: 'article'