-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from extractus/4.0.5
v4.0.5
- Loading branch information
Showing
21 changed files
with
295 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"name": "@extractus/oembed-extractor", | ||
"description": "Get oEmbed data from given URL.", | ||
"homepage": "https://github.com/extractus/oembed-extractor", | ||
|
@@ -11,10 +11,12 @@ | |
"main": "./src/main.js", | ||
"type": "module", | ||
"imports": { | ||
"cross-fetch": "./src/deno/cross-fetch.js" | ||
"cross-fetch": "./src/deno/cross-fetch.js", | ||
"linkedom": "https://deno.land/x/[email protected]/deno-dom-wasm.ts" | ||
}, | ||
"browser": { | ||
"cross-fetch": "./src/deno/cross-fetch.js" | ||
"cross-fetch": "./src/deno/cross-fetch.js", | ||
"linkedom": "./src/browser/linkedom.js" | ||
}, | ||
"types": "./index.d.ts", | ||
"engines": { | ||
|
@@ -30,11 +32,12 @@ | |
"reset": "node reset" | ||
}, | ||
"dependencies": { | ||
"cross-fetch": "^4.0.0" | ||
"cross-fetch": "^4.0.0", | ||
"linkedom": "^0.16.11" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^9.1.1", | ||
"globals": "^15.0.0", | ||
"eslint": "^9.2.0", | ||
"globals": "^15.1.0", | ||
"https-proxy-agent": "^7.0.4", | ||
"jest": "^29.7.0", | ||
"nock": "^13.5.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const DOMParser = window.DOMParser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// utils -> autoDiscovery.js | ||
|
||
import { DOMParser } from 'linkedom' | ||
|
||
import { getHtml, getJson } from './retrieve.js' | ||
|
||
export default async (url, params = {}, options = {}) => { | ||
const html = await getHtml(url, options) | ||
const doc = new DOMParser().parseFromString(html, 'text/html') | ||
const elm = doc.querySelector('link[type="application/json+oembed"]') | ||
const href = elm.getAttribute('href') | ||
const q = new URL(href) | ||
const { origin, pathname, searchParams } = q | ||
Object.keys(params).forEach((key) => { | ||
if (!searchParams.has(key)) { | ||
searchParams.append(key, params[key]) | ||
} | ||
}) | ||
const link = `${origin}${pathname}?${searchParams.toString()}` | ||
const body = await getJson(link, options) | ||
body.method = 'auto-discovery' | ||
return body | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// autoDiscovery.test | ||
/* eslint-env jest */ | ||
|
||
import nock from 'nock' | ||
|
||
import autoDiscovery from './autoDiscovery.js' | ||
|
||
const parseUrl = (url) => { | ||
const re = new URL(url) | ||
return { | ||
baseUrl: `${re.protocol}//${re.host}`, | ||
path: re.pathname, | ||
} | ||
} | ||
|
||
describe('test if autoDiscovery() works correctly', () => { | ||
const url = 'https://www.bitchute.com/video/8hXWnkvA8Ao/' | ||
test(`check fetchEmbed("${url}")`, async () => { | ||
const htmlFile = './test-data/bitchute.html' | ||
const jsonFile = './test-data/bitchute.json' | ||
|
||
const { baseUrl, path } = parseUrl(url) | ||
const scope = nock(baseUrl) | ||
scope.get(path) | ||
.replyWithFile(200, htmlFile, { | ||
'Content-Type': 'text/html', | ||
}) | ||
|
||
const endpoint = 'https://www.bitchute.com/oembed/' | ||
const { baseUrl: endpointBaseUrl, path: endpointPath } = parseUrl(endpoint) | ||
|
||
const params = { | ||
maxwidth: 600, | ||
maxheight: 400, | ||
} | ||
|
||
const jsonScope = nock(endpointBaseUrl, { encodedQueryParams: true }) | ||
const queries = new URLSearchParams({ | ||
url: 'https://www.bitchute.com/video/8hXWnkvA8Ao/', | ||
format: 'json', | ||
...params, | ||
}) | ||
jsonScope.get(endpointPath) | ||
.query(queries) | ||
.replyWithFile(200, jsonFile, { | ||
'Content-Type': 'application/json', | ||
}) | ||
|
||
const result = await autoDiscovery(url, params) | ||
expect(result).toBeTruthy() | ||
nock.cleanAll() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.