Skip to content

Commit 4965a7b

Browse files
committed
feat(115): Add token retrieval component and API support
- 新增 115 网盘 Token 获取组件 Token.vue - 更新 VuePress 配置以支持新组件路径 - 扩展 API 模块以支持动态路径和 API 选择 - 添加 115 Token 获取文档页面
1 parent 881c97d commit 4965a7b

File tree

4 files changed

+123
-3
lines changed

4 files changed

+123
-3
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<script setup lang="ts">
2+
import { NButton, NSpace, NImage, NAlert, NSpin, NInput } from 'naive-ui';
3+
import { ref } from 'vue';
4+
import { api } from '../api';
5+
const codeVerifier = ref('');
6+
const codeResp = ref({
7+
uid: '',
8+
time: 0,
9+
qrcode: '',
10+
sign: '',
11+
});
12+
const error1 = ref('');
13+
const qrCode = ref('');
14+
const gettingQrCode = ref(false);
15+
async function generateQrcode() {
16+
gettingQrCode.value = true;
17+
error1.value = '';
18+
const res = await fetch(api('/alist/115/auth_device_code'))
19+
const data = await res.json()
20+
gettingQrCode.value = false;
21+
if (data.error) {
22+
error1.value = data.error;
23+
return;
24+
}
25+
codeVerifier.value = data.code_verifier;
26+
codeResp.value = data.resp;
27+
const url = new URL(api('/qr'))
28+
url.searchParams.set("text", codeResp.value.qrcode)
29+
qrCode.value = url.toString();
30+
}
31+
const gettingToken = ref(false);
32+
const error2 = ref('');
33+
const tokenResp = ref({
34+
access_token: '',
35+
refresh_token: '',
36+
expires_in: 0,
37+
});
38+
async function getToken() {
39+
gettingToken.value = true;
40+
error2.value = '';
41+
const res = await fetch(api('/alist/115/get_token'), {
42+
method: 'POST',
43+
body: JSON.stringify({
44+
code_verifier: codeVerifier.value,
45+
uid: codeResp.value.uid,
46+
}),
47+
})
48+
const data = await res.json()
49+
gettingToken.value = false;
50+
if (data.error) {
51+
error2.value = data.error;
52+
return;
53+
}
54+
tokenResp.value = data.resp;
55+
}
56+
</script>
57+
58+
<template>
59+
<NSpace vertical size="large">
60+
<NButton block type="primary" @click="generateQrcode" v-if="!codeVerifier" :loading="gettingQrCode">Generate Qrcode</NButton>
61+
<NAlert title="Error" type="error" v-if="error1">
62+
{{ error1 }}
63+
</NAlert>
64+
<NSpace v-if="qrCode" vertical>
65+
<NSpace justify="center">
66+
<NImage width="300" :src="qrCode" />
67+
</NSpace>
68+
<NAlert title="Scan the QrCode" type="info"
69+
>Use 115 APP To Scan Then Click the Button Below</NAlert
70+
>
71+
<NButton
72+
size="large"
73+
@click="getToken"
74+
type="info"
75+
block
76+
:loading="gettingToken"
77+
>I have scan</NButton
78+
>
79+
<NAlert title="Error" type="error" v-if="error2">
80+
{{ error2 }}
81+
</NAlert>
82+
</NSpace>
83+
<NSpace vertical v-if="tokenResp.refresh_token">
84+
<b>refresh_token:</b>
85+
<NInput
86+
type="textarea"
87+
autosize
88+
readonly
89+
:value="tokenResp.refresh_token"
90+
/>
91+
<b>access_token:</b>
92+
<NInput
93+
type="textarea"
94+
autosize
95+
readonly
96+
:value="tokenResp.access_token"
97+
/>
98+
</NSpace>
99+
</NSpace>
100+
</template>

docs/.vuepress/components/api/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const apis: Record<string, string> = {
22
cf: "https://api.nn.ci",
33
cn: "https://api.xhofe.top",
4+
de: "http://api-my-api-5hw5ou-b810d8-80-75-218-107.traefik.me"
45
};
56

67
if (typeof location !== "undefined") {
@@ -13,9 +14,15 @@ if (typeof location !== "undefined") {
1314
}
1415

1516
export const defaultApi = "cf";
16-
export const api = () => {
17+
export const api = (path?: string) => {
18+
let _api = "";
1719
if (typeof localStorage === "undefined") {
18-
return apis[defaultApi];
20+
_api = apis[defaultApi];
21+
} else {
22+
_api = apis[localStorage.getItem("api_name") || defaultApi];
1923
}
20-
return apis[localStorage.getItem("api_name") || defaultApi];
24+
if (path) {
25+
return _api + path;
26+
}
27+
return _api;
2128
};

docs/.vuepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ export default defineUserConfig({
150150
__dirname,
151151
"./components/dropbox/Callback.vue"
152152
),
153+
"@115/Token": path.resolve(__dirname, "./components/115/Token.vue"),
153154
},
154155
});

docs/tool/115/token.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: "Get 115 Refresh Token"
3+
toc: false
4+
---
5+
6+
<NaiveClient>
7+
<Token />
8+
</NaiveClient>
9+
10+
<script setup lang="ts">
11+
import Token from "@115/Token";
12+
</script>

0 commit comments

Comments
 (0)