Skip to content

Commit

Permalink
fix: branch.ioを用いたディープリンクをパースできるように修正 (#13)
Browse files Browse the repository at this point in the history
* (fix) branch.ioのディープリンクでうまく作動しないのを修正

* Update changelog

* fix regex
  • Loading branch information
kakkokari-gtyih committed Nov 15, 2023
1 parent d2d8db4 commit d2a3e07
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
4.x.x (Unreleased) / 2023-09-xx
------------------
* branch.ioを用いたディープリンク(spotify.link)などでパースに失敗する問題を修正

4.0.2 / 2023-04-20
------------------
* YouTubeをフルスクリーンにできない問題を修正
Expand Down
2 changes: 1 addition & 1 deletion built/iplugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 5 additions & 0 deletions built/plugins/branchio-deeplinks.d.ts
Original file line number Diff line number Diff line change
@@ -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>;
12 changes: 12 additions & 0 deletions built/plugins/branchio-deeplinks.js
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions built/plugins/index.js
Original file line number Diff line number Diff line change
@@ -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,
];
2 changes: 1 addition & 1 deletion src/iplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
19 changes: 19 additions & 0 deletions src/plugins/branchio-deeplinks.ts
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -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,
];

0 comments on commit d2a3e07

Please sign in to comment.