Skip to content

Commit

Permalink
bye misskey-js
Browse files Browse the repository at this point in the history
  • Loading branch information
yamader committed Jun 22, 2024
1 parent 9438795 commit 8b29073
Show file tree
Hide file tree
Showing 25 changed files with 532 additions and 348 deletions.
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@
"@fontsource-variable/fira-code": "5.0.18",
"@fontsource-variable/inter": "5.0.18",
"@fontsource/zen-kaku-gothic-new": "5.0.19",
"@radix-ui/react-collapsible": "1.0.3",
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-dropdown-menu": "2.0.6",
"@radix-ui/react-radio-group": "1.1.3",
"@radix-ui/react-select": "2.0.0",
"@radix-ui/themes": "3.0.5",
"@serwist/next": "9.0.2",
"@radix-ui/react-collapsible": "1.1.0",
"@radix-ui/react-dialog": "1.1.1",
"@radix-ui/react-dropdown-menu": "2.1.1",
"@radix-ui/react-radio-group": "1.2.0",
"@radix-ui/react-select": "2.1.1",
"@radix-ui/themes": "3.1.1",
"@serwist/next": "9.0.3",
"ahooks": "3.8.0",
"clsx": "2.1.1",
"immer": "10.1.1",
"jotai": "2.8.2",
"lucide-react": "0.381.0",
"jotai": "2.8.3",
"lucide-react": "0.396.0",
"mfm-js": "0.24.0",
"misskey-js": "0.0.16",
"mitt": "3.0.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-hook-form": "7.51.5",
"react-hook-form": "7.52.0",
"react-mfm": "0.5.1",
"react-textarea-autosize": "8.5.3",
"serwist": "9.0.2",
"use-immer": "0.9.0",
"uuid": "9.0.1"
"serwist": "9.0.3",
"use-immer": "0.10.0",
"uuid": "10.0.0"
},
"devDependencies": {
"@tauri-apps/cli": "2.0.0-beta.20",
"@types/node": "20",
"@types/react": "18",
"@types/react-dom": "18",
"@types/uuid": "9",
"@typescript-eslint/eslint-plugin": "7.11.0",
"@typescript-eslint/parser": "7.11.0",
"@types/uuid": "10",
"@typescript-eslint/eslint-plugin": "7.13.1",
"@typescript-eslint/parser": "7.13.1",
"autoprefixer": "10.4.19",
"eslint": "8.57.0",
"eslint-config-next": "14.2.3",
"eslint": "<9",
"eslint-config-next": "14.2.4",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"next": "14.1.4",
"next": "<14.2",
"postcss": "8.4.38",
"postcss-import": "16.1.0",
"prettier": "3.2.5",
"prettier": "3.3.2",
"prettier-plugin-organize-imports": "3.2.4",
"prettier-plugin-tailwindcss": "0.6.1",
"tailwindcss": "3.4.3",
"prettier-plugin-tailwindcss": "0.6.5",
"tailwindcss": "3.4.4",
"tailwindcss-radix": "3.0.3",
"typescript": "5.4.5"
"typescript": "<5.5.0"
},
"private": true,
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions src/app/(center)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"use client"

import * as RadioGroup from "@radix-ui/react-radio-group"
import { permissions } from "misskey-js"
import { useRouter, useSearchParams } from "next/navigation"
import { Suspense, useEffect, useState } from "react"
import { useForm } from "react-hook-form"
import { v4 as uuidv4 } from "uuid"
import { detect } from "~/features/api/clients"
import { useAuth } from "~/features/auth"
import { permissions, useAuth } from "~/features/auth"
import { ensureproto } from "~/utils"

export default function LoginPage() {
Expand Down
40 changes: 14 additions & 26 deletions src/features/api/clients/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { dbg } from "~/utils"

//------------------------------------------------------------//

declare global {
var _minsk_api_cache: {
[key: string]: {
Expand All @@ -12,11 +14,7 @@ declare global {

globalThis._minsk_api_cache ??= {}

////////////////////////////////////////////////////////////////

/**
* 各バージョンごとに異なるAPIクライアントを作成するための基底クラス
*/
//------------------------------------------------------------//

type GetProps = Partial<{
opts: RequestInit
Expand All @@ -31,7 +29,7 @@ type PostProps = Partial<{

export default class BaseClient {
id: string
host: string
host: string // プロトコルを含む
token?: string
_cachePrefix: string

Expand All @@ -41,24 +39,17 @@ export default class BaseClient {
postLifespan = 10_000
postClock = 500

/**
* @param host - プロトコルを含むホスト名
* @param token - APIトークン
* @memberof BaseClient
*/
constructor(host: string, token?: string) {
this.id = "unknown"
this.host = host
this.token = token
this._cachePrefix = host + token
}

/**
* GETリクエストを送信する
* @param path - APIのパス
* @param opts - fetchのオプション
* @memberof BaseClient
*/
//----------------------------//
// GET
//----------------------------//

async get<T>(path: string, props: GetProps, volatile?: boolean) {
const key = this._cachePrefix + "g" + path + JSON.stringify(props)

Expand Down Expand Up @@ -87,19 +78,16 @@ export default class BaseClient {
return _minsk_api_cache[key].res as Promise<T | null>
}

private async rawGet<T>(path: string, { opts }: GetProps) {
private async rawGet(path: string, { opts }: GetProps) {
const res = await fetch(this.host + "/api/" + path, opts)
if (!res.ok) return null
return res.json()
}

/**
* POSTリクエストを送信する
* @param path - APIのパス
* @param body - リクエストボディ
* @param opts - fetchのオプション
* @memberof BaseClient
*/
//----------------------------//
// POST
//----------------------------//

async post<T>(path: string, props: PostProps, volatile?: boolean) {
const key = this._cachePrefix + "p" + path + JSON.stringify(props)

Expand Down Expand Up @@ -128,7 +116,7 @@ export default class BaseClient {
return _minsk_api_cache[key].res as Promise<T | null>
}

private async rawPost<T>(path: string, { body, opts }: PostProps) {
private async rawPost(path: string, { body, opts }: PostProps) {
const res = await fetch(this.host + "/api/" + path, {
method: "POST",
headers: { "Content-Type": "application/json" },
Expand Down
5 changes: 3 additions & 2 deletions src/features/api/clients/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export * from "./types"

import { APIClient } from "."
import MisskeyLatestClient from "./misskey-latest"
import MisskeyV12Client from "./misskey-v12"
import MisskeyV13Client from "./misskey-v13"

export type APIClient = MisskeyLatestClient

// host: `scheme:auth` ← ここ重要
export async function detect(host: string, token?: string): Promise<APIClient | null> {
try {
Expand Down
Loading

0 comments on commit 8b29073

Please sign in to comment.