Niedzielski has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377695 )
Change subject: WIP: Chore: add page summary models and unmarshallers ...................................................................... WIP: Chore: add page summary models and unmarshallers Bug: T173323 Change-Id: Ib9d03bb247f4e97c1933a4bcce03ff5f0eee29ce --- A src/common/marshallers/page-restbase-mount-everest.test.json A src/common/marshallers/page-unmarshaller.test.ts A src/common/marshallers/page-unmarshaller.ts A src/common/models/page.ts M src/common/routers/router.ts 5 files changed, 190 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/95/377695/1 diff --git a/src/common/marshallers/page-restbase-mount-everest.test.json b/src/common/marshallers/page-restbase-mount-everest.test.json new file mode 100644 index 0000000..95940a3 --- /dev/null +++ b/src/common/marshallers/page-restbase-mount-everest.test.json @@ -0,0 +1,26 @@ +{ + "title": "Mount Everest", + "displaytitle": "<i>Mount Everest</i>", + "pageid": 42179, + "extract": "Mount Everest, known in Nepali as Sagarmāthā and in Tibetan as Chomolungma, is Earth's highest mountain, located in the Mahalangur Himal sub-range of the Himalayas. The international border between China (Tibet Autonomous Region) and Nepal runs across its summit point.\nThe current official height of 8,848 m (29,029 ft), recognised by China and Nepal, was established by a 1955 Indian survey and subsequently confirmed by a Chinese survey in 1975. In 2005, China remeasured the rock height of the mountain, with a result of 8844.43 m. There followed an argument between China and Nepal as to whether the official height should be the rock height (8,844 m., China) or the snow height (8,848 m., Nepal). In 2010, an agreement was reached by both sides that the height of Everest is 8,848 m, and Nepal recognises China's claim that the rock height of Everest is 8,844 m.\nIn 1865, Everest was given its official English name by the Royal Geographical Society, upon a recommendation by Andrew Waugh, the British Surveyor General of India.", + "extract_html": "<p><b>Mount Everest</b>, known in Nepali as <b>Sagarmāthā</b> and in Tibetan as <b>Chomolungma</b>, is Earth's highest mountain, located in the Mahalangur Himal sub-range of the Himalayas. The international border between China (Tibet Autonomous Region) and Nepal runs across its summit point.</p>\n<p>The current official height of 8,848 m (29,029 ft), recognised by China and Nepal, was established by a 1955 Indian survey and subsequently confirmed by a Chinese survey in 1975. In 2005, China remeasured the rock height of the mountain, with a result of 8844.43 m. There followed an argument between China and Nepal as to whether the official height should be the rock height (8,844 m., China) or the snow height (8,848 m., Nepal). In 2010, an agreement was reached by both sides that the height of Everest is 8,848 m, and Nepal recognises China's claim that the rock height of Everest is 8,844 m.</p>\n<p>In 1865, Everest was given its official English name by the Royal Geographical Society, upon a recommendation by Andrew Waugh, the British Surveyor General of India.", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Mount-Everest.jpg/320px-Mount-Everest.jpg", + "width": 320, + "height": 213, + "original": "http://upload.wikimedia.org/wikipedia/commons/c/c7/Mount-Everest.jpg" + }, + "originalimage": { + "source": "https://upload.wikimedia.org/wikipedia/commons/c/c7/Mount-Everest.jpg", + "width": 2679, + "height": 1781 + }, + "lang": "en", + "dir": "ltr", + "timestamp": "2017-09-11T16:00:59Z", + "description": "Earth's highest mountain, with a peak at 8,848 metres (29,029 feet) above sea level, part of the Himalaya mountain range between Nepal and China", + "coordinates": { + "lat": 27.98805556, + "lon": 86.92527778 + } +} diff --git a/src/common/marshallers/page-unmarshaller.test.ts b/src/common/marshallers/page-unmarshaller.test.ts new file mode 100644 index 0000000..9b2aac0 --- /dev/null +++ b/src/common/marshallers/page-unmarshaller.test.ts @@ -0,0 +1,43 @@ +import * as assert from "assert"; +import { PageSummary } from "../models/page"; +import { unmarshalPageSummary } from "./page-unmarshaller"; + +describe("page-unmarshaller", () => { + it("unmarshalPageSummary() unmarshals", () => { + const json = require("./page-restbase-mount-everest.test.json"); + const result = unmarshalPageSummary(json); + const expected: PageSummary = { + titleText: "Mount Everest", + titleHTML: "<i>Mount Everest</i>", + pageID: 42179, + extractText: + "Mount Everest, known in Nepali as Sagarmāthā and in Tibetan as Chomolungma, is Earth's highest mountain, located in the Mahalangur Himal sub-range of the Himalayas. The international border between China (Tibet Autonomous Region) and Nepal runs across its summit point.\nThe current official height of 8,848 m (29,029 ft), recognised by China and Nepal, was established by a 1955 Indian survey and subsequently confirmed by a Chinese survey in 1975. In 2005, China remeasured the rock height of the mountain, with a result of 8844.43 m. There followed an argument between China and Nepal as to whether the official height should be the rock height (8,844 m., China) or the snow height (8,848 m., Nepal). In 2010, an agreement was reached by both sides that the height of Everest is 8,848 m, and Nepal recognises China's claim that the rock height of Everest is 8,844 m.\nIn 1865, Everest was given its official English name by the Royal Geographical Society, upon a recommendation by Andrew Waugh, the British Surveyor General of India.", // eslint-disable-line max-len + extractHTML: + "<p><b>Mount Everest</b>, known in Nepali as <b>Sagarmāthā</b> and in Tibetan as <b>Chomolungma</b>, is Earth's highest mountain, located in the Mahalangur Himal sub-range of the Himalayas. The international border between China (Tibet Autonomous Region) and Nepal runs across its summit point.</p>\n<p>The current official height of 8,848 m (29,029 ft), recognised by China and Nepal, was established by a 1955 Indian survey and subsequently confirmed by a Chinese survey in 1975. In 2005, China remeasured the rock height of the mountain, with a result of 8844.43 m. There followed an argument between China and Nepal as to whether the official height should be the rock height (8,844 m., China) or the snow height (8,848 m., Nepal). In 2010, an agreement was reached by both sides that the height of Everest is 8,848 m, and Nepal recognises China's claim that the rock height of Everest is 8,844 m.</p>\n<p>In 1865, Everest was given its official English name by the Royal Geographical Society, upon a recommendation by Andrew Waugh, the British Surveyor General of India.", // eslint-disable-line max-len + thumbnail: { + URL: + "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Mount-Everest.jpg/320px-Mount-Everest.jpg", + originalURL: + "http://upload.wikimedia.org/wikipedia/commons/c/c7/Mount-Everest.jpg", + width: 320, + height: 213 + }, + image: { + URL: + "https://upload.wikimedia.org/wikipedia/commons/c/c7/Mount-Everest.jpg", + width: 2679, + height: 1781 + }, + wikiLanguageCode: "en", + localeDirection: "ltr", + lastModified: new Date("2017-09-11T16:00:59Z"), + descriptionText: + "Earth's highest mountain, with a peak at 8,848 metres (29,029 feet) above sea level, part of the Himalaya mountain range between Nepal and China", // eslint-disable-line max-len + geolocation: { + latitude: 27.98805556, + longitude: 86.92527778 + } + }; + assert.deepEqual(result, expected); + }); +}); diff --git a/src/common/marshallers/page-unmarshaller.ts b/src/common/marshallers/page-unmarshaller.ts new file mode 100644 index 0000000..48f5976 --- /dev/null +++ b/src/common/marshallers/page-unmarshaller.ts @@ -0,0 +1,88 @@ +import { + PageGeolocation, + PageImage, + PageSummary, + PageThumbnail +} from "../models/page"; + +const unmarshalPageThumbnailRESTBase = ( + json: RESTBase.PageThumbnail +): PageThumbnail => ({ + URL: json.source, + originalURL: json.original, + width: json.width, + height: json.height +}); +export const unmarshalPageThumbnail = (json: any): PageThumbnail => + unmarshalPageThumbnailRESTBase(json); + +const unmarshalPageImageRESTBase = (json: RESTBase.PageImage): PageImage => ({ + URL: json.source, + width: json.width, + height: json.height +}); +export const unmarshalPageImage = (json: any): PageImage => + unmarshalPageImageRESTBase(json); + +const unmarshalPageGeolocationRESTBase = ( + json: RESTBase.PageGeolocation +): PageGeolocation => ({ + latitude: json.lat, + longitude: json.lon +}); +export const unmarshalPageGeolocation = (json: any): PageGeolocation => + unmarshalPageGeolocationRESTBase(json); + +const unmarshalPageSummaryRESTBase = ( + json: RESTBase.PageSummary +): PageSummary => ({ + wikiLanguageCode: json.lang, + localeDirection: json.dir, + pageID: json.pageid, + lastModified: new Date(json.timestamp), + titleText: json.title, + titleHTML: json.displaytitle, + descriptionText: json.description, + extractText: json.extract, + extractHTML: json.extract_html, + thumbnail: json.thumbnail && unmarshalPageThumbnail(json.thumbnail), + image: json.originalimage && unmarshalPageImage(json.originalimage), + geolocation: json.coordinates && unmarshalPageGeolocation(json.coordinates) +}); +export const unmarshalPageSummary = (json: any): PageSummary => + unmarshalPageSummaryRESTBase(json); + +namespace RESTBase { + export interface PageThumbnail { + source: string; + original: string; + width: number; + height: number; + } + + export interface PageImage { + source: string; + width: number; + height: number; + } + + export interface PageGeolocation { + lat: number; + lon: number; + } + + export interface PageSummary { + title: string; + displaytitle: string; + pageid: number; + extract: string; + extract_html: string; // eslint-disable-line camelcase + thumbnail?: PageThumbnail; + originalimage?: PageImage; + lang: string; + dir: string; + timestamp: string; + description: string; + coordinates?: PageGeolocation; + } +} diff --git a/src/common/models/page.ts b/src/common/models/page.ts new file mode 100644 index 0000000..2e8169d --- /dev/null +++ b/src/common/models/page.ts @@ -0,0 +1,32 @@ +export interface PageThumbnail { + URL: string; + originalURL: string; + width: number; + height: number; +} + +export interface PageImage { + URL: string; + width: number; + height: number; +} + +export interface PageGeolocation { + latitude: number; + longitude: number; +} + +export interface PageSummary { + wikiLanguageCode: string; + localeDirection: string; + pageID: number; + lastModified: Date; + titleText: string; + titleHTML: string; + descriptionText: string; + extractText: string; + extractHTML: string; + thumbnail?: PageThumbnail; + image?: PageImage; + geolocation?: PageGeolocation; +} diff --git a/src/common/routers/router.ts b/src/common/routers/router.ts index 2f7c852..e99f3f3 100644 --- a/src/common/routers/router.ts +++ b/src/common/routers/router.ts @@ -59,6 +59,7 @@ return Promise.resolve({}); } +// typing const respond = ( route: ParsedRoute, url: string, -- To view, visit https://gerrit.wikimedia.org/r/377695 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib9d03bb247f4e97c1933a4bcce03ff5f0eee29ce Gerrit-PatchSet: 1 Gerrit-Project: marvin Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: Sniedzielski <sniedziel...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits