generated from mnao305/webextension-typescript-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: APIリクエストにx-requested-withヘッダーを追加 (#428)
Fantia側の変更対応 #427
- Loading branch information
Showing
3 changed files
with
14 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import ky from 'ky' | ||
|
||
/** | ||
* Fantiaのget APIにアクセスするためのヘッダーなどを設定済みのラッパー | ||
*/ | ||
export const get = async <T>(url: string) => { | ||
const csrfToken = document.getElementsByName('csrf-token')[0].getAttribute('content') ?? '' | ||
|
||
return await ky.get(url, { headers: { 'x-csrf-token': csrfToken, 'x-requested-with': 'XMLHttpRequest' } }).json<T>() | ||
} |
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,12 +1,11 @@ | ||
import ky from 'ky' | ||
import { Backnumber, BacknumberResponse } from '../../types/backnumber' | ||
import { get } from './api' | ||
|
||
export const fetchBacknumberData = async (): Promise<Backnumber> => { | ||
const url = new URL((document.getElementsByClassName('tab-item tab-item-text active')[1] as HTMLAnchorElement).href) | ||
const plan = url.searchParams.get('plan') | ||
const month = url.searchParams.get('month') | ||
const csrfToken = document.getElementsByName('csrf-token')[0].getAttribute('content') ?? '' | ||
const json = await ky.get(`https://fantia.jp/api/v1/fanclub/backnumbers/monthly_contents/plan/${plan}/month/${month}`, { headers: { 'x-csrf-token': csrfToken } }).json<BacknumberResponse>() | ||
const json = await get<BacknumberResponse>(`https://fantia.jp/api/v1/fanclub/backnumbers/monthly_contents/plan/${plan}/month/${month}`) | ||
|
||
return json.backnumber | ||
} |
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