diff --git a/src/utils/api.ts b/src/apis/api.ts similarity index 100% rename from src/utils/api.ts rename to src/apis/api.ts diff --git a/src/utils/checkLogin.ts b/src/apis/checkLogin.ts similarity index 100% rename from src/utils/checkLogin.ts rename to src/apis/checkLogin.ts diff --git a/src/utils/checkQRCode.ts b/src/apis/checkQRCode.ts similarity index 100% rename from src/utils/checkQRCode.ts rename to src/apis/checkQRCode.ts diff --git a/src/utils/gennerateQRCode.ts b/src/apis/gennerateQRCode.ts similarity index 100% rename from src/utils/gennerateQRCode.ts rename to src/apis/gennerateQRCode.ts diff --git a/src/utils/getCid.ts b/src/apis/getCid.ts similarity index 100% rename from src/utils/getCid.ts rename to src/apis/getCid.ts diff --git a/src/utils/getConclsion.ts b/src/apis/getConclsion.ts similarity index 94% rename from src/utils/getConclsion.ts rename to src/apis/getConclsion.ts index f339ed6..1e1b82d 100644 --- a/src/utils/getConclsion.ts +++ b/src/apis/getConclsion.ts @@ -1,6 +1,6 @@ import got from "got"; import { Cache } from "@raycast/api"; -import { encWbi } from "./tools"; +import { encWbi } from "../utils"; import { API } from "./api"; export async function getConclsion(bvid: string, cid: number, up_mid: number) { diff --git a/src/utils/getDynamicFeed.ts b/src/apis/getDynamicFeed.ts similarity index 100% rename from src/utils/getDynamicFeed.ts rename to src/apis/getDynamicFeed.ts diff --git a/src/utils/getPlayUrl.ts b/src/apis/getPlayUrl.ts similarity index 100% rename from src/utils/getPlayUrl.ts rename to src/apis/getPlayUrl.ts diff --git a/src/utils/getRcmd.ts b/src/apis/getRcmd.ts similarity index 100% rename from src/utils/getRcmd.ts rename to src/apis/getRcmd.ts diff --git a/src/utils/getSearchVideos.ts b/src/apis/getSearchVideos.ts similarity index 100% rename from src/utils/getSearchVideos.ts rename to src/apis/getSearchVideos.ts diff --git a/src/utils/getVideoInfo.ts b/src/apis/getVideoInfo.ts similarity index 100% rename from src/utils/getVideoInfo.ts rename to src/apis/getVideoInfo.ts diff --git a/src/apis/index.ts b/src/apis/index.ts new file mode 100644 index 0000000..41ea7c9 --- /dev/null +++ b/src/apis/index.ts @@ -0,0 +1,13 @@ +export * from "./api"; +export * from "./logout"; +export * from "./getCid"; +export * from "./getRcmd"; +export * from "./checkLogin"; +export * from "./getPlayUrl"; +export * from "./checkQRCode"; +export * from "./getConclsion"; +export * from "./getVideoInfo"; +export * from "./postHeartbeat"; +export * from "./getDynamicFeed"; +export * from "./gennerateQRCode"; +export * from "./getSearchVideos"; diff --git a/src/utils/logout.ts b/src/apis/logout.ts similarity index 100% rename from src/utils/logout.ts rename to src/apis/logout.ts diff --git a/src/utils/postHeartbeat.ts b/src/apis/postHeartbeat.ts similarity index 100% rename from src/utils/postHeartbeat.ts rename to src/apis/postHeartbeat.ts diff --git a/src/components/conslusionView.tsx b/src/components/conslusionView.tsx index 35f1e6a..762c0ea 100644 --- a/src/components/conslusionView.tsx +++ b/src/components/conslusionView.tsx @@ -1,6 +1,6 @@ import { Detail, List, showToast, Toast } from "@raycast/api"; import { useState, useEffect } from "react"; -import { getCid, getConclsion } from "../utils"; +import { getCid, getConclsion } from "../apis"; type Props = { bvid: string; cid: number; up_mid: number }; export function ConclusionView(props: Props) { diff --git a/src/dynamicFeed.tsx b/src/dynamicFeed.tsx index a589d03..59ecb6d 100644 --- a/src/dynamicFeed.tsx +++ b/src/dynamicFeed.tsx @@ -1,5 +1,6 @@ import { useDynamicFeed } from "./hooks"; -import { checkLogin, formatUrl, getVideoInfo, postHeartbeat } from "./utils"; +import { formatUrl } from "./utils"; +import { checkLogin, getVideoInfo, postHeartbeat } from "./apis"; import { NoLoginView, Post, Video } from "./components"; import { List, showToast, Toast } from "@raycast/api"; import { useState } from "react"; @@ -88,21 +89,21 @@ export default function Command() { markAsWatchedCallback={ last_play_time === 0 ? async () => { - try { - const videoInfo = await getVideoInfo(aid); - - await postHeartbeat(videoInfo.aid, videoInfo.cid); - if (!watchedList.includes(bvid)) setWatchedList([bvid, ...watchedList].slice(0, 200)); - - refetch({}); - await showToast({ style: Toast.Style.Success, title: "Make as watched successfully" }); - } catch { - await showToast({ - style: Toast.Style.Failure, - title: "Make as watched failed, please retry later", - }); - } + try { + const videoInfo = await getVideoInfo(aid); + + await postHeartbeat(videoInfo.aid, videoInfo.cid); + if (!watchedList.includes(bvid)) setWatchedList([bvid, ...watchedList].slice(0, 200)); + + refetch({}); + await showToast({ style: Toast.Style.Success, title: "Make as watched successfully" }); + } catch { + await showToast({ + style: Toast.Style.Failure, + title: "Make as watched failed, please retry later", + }); } + } : undefined } /> diff --git a/src/hooks/useDynamicFeed.ts b/src/hooks/useDynamicFeed.ts index 00d8869..5813530 100644 --- a/src/hooks/useDynamicFeed.ts +++ b/src/hooks/useDynamicFeed.ts @@ -1,4 +1,4 @@ -import { getDynamicFeed, getPlayUrl, getVideoInfo } from "../utils"; +import { getDynamicFeed, getPlayUrl, getVideoInfo } from "../apis"; import { useEffect, useState } from "react"; import { showToast, Toast } from "@raycast/api"; diff --git a/src/hooks/useLogin.ts b/src/hooks/useLogin.ts index f637044..19256c8 100644 --- a/src/hooks/useLogin.ts +++ b/src/hooks/useLogin.ts @@ -1,4 +1,4 @@ -import { checkLogin, checkQRCode, gennerateQRCode } from "../utils"; +import { checkLogin, checkQRCode, gennerateQRCode } from "../apis"; import { useState, useEffect } from "react"; import { Cache, showToast, Toast } from "@raycast/api"; diff --git a/src/hooks/useRcmdVideos.ts b/src/hooks/useRcmdVideos.ts index 2e02124..83ed327 100644 --- a/src/hooks/useRcmdVideos.ts +++ b/src/hooks/useRcmdVideos.ts @@ -1,4 +1,4 @@ -import { getRcmd } from "../utils"; +import { getRcmd } from "../apis"; import { useState, useEffect } from "react"; import { showToast, Toast } from "@raycast/api"; diff --git a/src/hooks/useSearchVideos.ts b/src/hooks/useSearchVideos.ts index b594828..9c82792 100644 --- a/src/hooks/useSearchVideos.ts +++ b/src/hooks/useSearchVideos.ts @@ -1,4 +1,4 @@ -import { getSearchVideos } from "../utils"; +import { getSearchVideos } from "../apis"; import { useState, useEffect } from "react"; import { showToast, Toast } from "@raycast/api"; diff --git a/src/login.tsx b/src/login.tsx index 3963913..de803d8 100644 --- a/src/login.tsx +++ b/src/login.tsx @@ -1,4 +1,4 @@ -import { logout } from "./utils"; +import { logout } from "./apis"; import { useLogin } from "./hooks"; import { diff --git a/src/notifications.tsx b/src/notifications.tsx index a11cb47..ea50b30 100644 --- a/src/notifications.tsx +++ b/src/notifications.tsx @@ -1,7 +1,9 @@ +import { formatUrl } from "./utils"; +import { checkLogin, getDynamicFeed } from "./apis"; + +import { spawnSync } from "child_process"; import { runAppleScript } from "run-applescript"; -import { checkLogin, formatUrl, getDynamicFeed } from "./utils"; import { getPreferenceValues, LocalStorage } from "@raycast/api"; -import { spawnSync } from "child_process"; interface Preferences { justNotifyVideos: boolean; diff --git a/src/rcmdVideos.tsx b/src/rcmdVideos.tsx index 10e7442..62baa08 100644 --- a/src/rcmdVideos.tsx +++ b/src/rcmdVideos.tsx @@ -1,6 +1,7 @@ import { useRcmdVideos } from "./hooks"; import { NoLoginView, Video } from "./components"; -import { checkLogin, formatNumber, secondToDate } from "./utils"; +import { checkLogin } from "./apis"; +import { formatNumber, secondToDate } from "./utils"; import { useState } from "react"; import { List } from "@raycast/api"; diff --git a/src/searchVideos.tsx b/src/searchVideos.tsx index d2ee40f..21e95b2 100644 --- a/src/searchVideos.tsx +++ b/src/searchVideos.tsx @@ -1,5 +1,6 @@ import { NoLoginView, Video } from "./components"; -import { checkLogin, formatNumber, removeEmHTMLTag } from "./utils"; +import { checkLogin } from "./apis"; +import {formatNumber, removeEmHTMLTag} from "./utils"; import { useState } from "react"; import { useSearchVideos } from "./hooks"; import { List } from "@raycast/api"; diff --git a/src/types.ts b/src/types.ts index d7f293a..f88109a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -305,6 +305,7 @@ declare global { like_num: number; model_result: ModelResult; } + export interface VideoConclusionResponse extends Omit { data: VideoConclusionResponseData; } diff --git a/src/utils/index.ts b/src/utils/index.ts index ec975c0..2eed217 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,14 +1 @@ -export * from "./api"; export * from "./tools"; -export * from "./logout"; -export * from "./getCid"; -export * from "./getRcmd"; -export * from "./checkLogin"; -export * from "./getPlayUrl"; -export * from "./checkQRCode"; -export * from "./getConclsion"; -export * from "./getVideoInfo"; -export * from "./postHeartbeat"; -export * from "./getDynamicFeed"; -export * from "./gennerateQRCode"; -export * from "./getSearchVideos";