fix: branch.ioを用いたディープリンクをパースできるように修正 (#13)

* (fix) branch.ioのディープリンクでうまく作動しないのを修正

* Update changelog

* fix regex
This commit is contained in:
かっこかり 2023-11-15 19:23:03 +09:00 committed by GitHub
parent d2d8db4994
commit d2a3e07205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 2 deletions

View File

@ -1,3 +1,7 @@
4.x.x (Unreleased) / 2023-09-xx
------------------
* branch.ioを用いたディープリンクspotify.linkなどでパースに失敗する問題を修正
4.0.2 / 2023-04-20
------------------
* YouTubeをフルスクリーンにできない問題を修正

2
built/iplugin.d.ts vendored
View File

@ -3,5 +3,5 @@ import type { URL } from 'node:url';
import Summary from './summary.js';
export interface IPlugin {
test: (url: URL) => boolean;
summarize: (url: URL, lang?: string) => Promise<Summary>;
summarize: (url: URL, lang?: string) => Promise<Summary | null>;
}

5
built/plugins/branchio-deeplinks.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/// <reference types="node" />
import { URL } from 'node:url';
import Summary from '../summary.js';
export declare function test(url: URL): boolean;
export declare function summarize(url: URL, lang?: string | null): Promise<Summary | null>;

View File

@ -0,0 +1,12 @@
import general from '../general.js';
export function test(url) {
// Branch.io を使用したディープリンクにマッチ
return /^[a-zA-Z0-9]+\.app\.link$/.test(url.hostname) ||
url.hostname === 'spotify.link';
}
export async function summarize(url, lang = null) {
// https://help.branch.io/using-branch/docs/creating-a-deep-link#redirections
// Web版に強制リダイレクトすることでbranch.ioの独自ページが開くのを防ぐ
url.searchParams.append('$web_only', 'true');
return await general(url, lang);
}

View File

@ -1,6 +1,8 @@
import * as amazon from './amazon.js';
import * as wikipedia from './wikipedia.js';
import * as branchIoDeeplinks from './branchio-deeplinks.js';
export const plugins = [
amazon,
wikipedia,
branchIoDeeplinks,
];

View File

@ -3,5 +3,5 @@ import Summary from './summary.js';
export interface IPlugin {
test: (url: URL) => boolean;
summarize: (url: URL, lang?: string) => Promise<Summary>;
summarize: (url: URL, lang?: string) => Promise<Summary | null>;
}

View File

@ -0,0 +1,19 @@
import { URL } from 'node:url';
import { scpaping } from '../utils/got.js';
import general from '../general.js';
import Summary from '../summary.js';
export function test(url: URL): boolean {
// Branch.io を使用したディープリンクにマッチ
return /^[a-zA-Z0-9]+\.app\.link$/.test(url.hostname) ||
url.hostname === 'spotify.link';
}
export async function summarize(url: URL, lang: string | null = null): Promise<Summary | null> {
// https://help.branch.io/using-branch/docs/creating-a-deep-link#redirections
// Web版に強制リダイレクトすることでbranch.ioの独自ページが開くのを防ぐ
url.searchParams.append('$web_only', 'true');
return await general(url, lang);
}

View File

@ -1,8 +1,10 @@
import { IPlugin } from '@/iplugin.js';
import * as amazon from './amazon.js';
import * as wikipedia from './wikipedia.js';
import * as branchIoDeeplinks from './branchio-deeplinks.js';
export const plugins: IPlugin[] = [
amazon,
wikipedia,
branchIoDeeplinks,
];