Skip to content

Commit a34b004

Browse files
committed
force relogin in get ali_open token
1 parent c78f72b commit a34b004

File tree

1 file changed

+65
-46
lines changed

1 file changed

+65
-46
lines changed

docs/.vuepress/components/aliyundrive/Request.vue

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,105 @@
11
<script lang="ts" setup>
2-
import { NButton, NSpace, NAlert, NImage, useMessage, NSelect } from 'naive-ui';
3-
import { ref } from 'vue';
4-
import { api } from '../api'
5-
6-
const alist_redirect_uri = "https://alist.nn.ci/tool/aliyundrive/callback"
7-
const app_id = "76917ccccd4441c39457a04f6084fb2f"
8-
2+
import { NButton, NSpace, NAlert, NImage, useMessage, NSelect } from "naive-ui";
3+
import { ref } from "vue";
4+
import { api } from "../api";
95
6+
const alist_redirect_uri = "https://alist.nn.ci/tool/aliyundrive/callback";
7+
const app_id = "76917ccccd4441c39457a04f6084fb2f";
108
119
function goGet() {
1210
const url = new URL("https://open.aliyundrive.com/oauth/authorize");
1311
url.searchParams.set("client_id", app_id);
1412
url.searchParams.set("redirect_uri", alist_redirect_uri);
15-
url.searchParams.set(
16-
"scope",
17-
"user:base,file:all:read,file:all:write"
18-
);
13+
url.searchParams.set("scope", "user:base,file:all:read,file:all:write");
1914
url.searchParams.set("response_type", "code");
20-
url.searchParams.set(
21-
"state", ""
22-
);
15+
url.searchParams.set("state", "");
16+
url.searchParams.set("relogin", "true");
2317
window.open(url.toString(), "_blank");
2418
}
2519
2620
interface QrCodeResp {
2721
qrCodeUrl: string;
2822
sid: string;
29-
error: string
23+
error: string;
3024
}
3125
32-
const qrcode = ref<QrCodeResp>()
26+
const qrcode = ref<QrCodeResp>();
3327
34-
const gettingQrCode = ref(false)
28+
const gettingQrCode = ref(false);
3529
3630
async function getQrCode() {
3731
try {
38-
gettingQrCode.value = true
32+
gettingQrCode.value = true;
3933
const resp = await fetch(api() + "/alist/ali_open/qr", {
4034
method: "POST",
4135
headers: {
42-
"Content-Type": "application/json"
36+
"Content-Type": "application/json",
4337
},
44-
body: JSON.stringify({})
45-
})
46-
const res: QrCodeResp = await resp.json()
47-
qrcode.value = res
38+
body: JSON.stringify({}),
39+
});
40+
const res: QrCodeResp = await resp.json();
41+
qrcode.value = res;
4842
} catch (e) {
49-
console.log(e)
43+
console.log(e);
5044
qrcode.value = {
5145
error: "error",
5246
qrCodeUrl: "",
53-
sid: ""
54-
}
47+
sid: "",
48+
};
5549
} finally {
56-
gettingQrCode.value = false
50+
gettingQrCode.value = false;
5751
}
5852
}
5953
6054
interface ScanStatus {
61-
status: string
62-
authCode: string
55+
status: string;
56+
authCode: string;
6357
}
6458
65-
const scanStatus = ref<ScanStatus>()
66-
const gettingScanStatus = ref(false)
59+
const scanStatus = ref<ScanStatus>();
60+
const gettingScanStatus = ref(false);
6761
68-
const message = useMessage()
62+
const message = useMessage();
6963
7064
async function haveScan() {
7165
try {
72-
gettingScanStatus.value = true
73-
const resp = await fetch(`${api()}/proxy/https://open.aliyundrive.com/oauth/qrcode/${qrcode.value?.sid}/status`)
74-
const res: ScanStatus = await resp.json()
75-
scanStatus.value = res
66+
gettingScanStatus.value = true;
67+
const resp = await fetch(
68+
`${api()}/proxy/https://open.aliyundrive.com/oauth/qrcode/${
69+
qrcode.value?.sid
70+
}/status`
71+
);
72+
const res: ScanStatus = await resp.json();
73+
scanStatus.value = res;
7674
if (res.status === "LoginSuccess") {
7775
const url = new URL(alist_redirect_uri);
7876
url.searchParams.set("code", res.authCode);
7977
window.open(url.toString(), "_blank");
8078
} else {
81-
message.warning(res.status)
79+
message.warning(res.status);
8280
}
8381
} catch (e) {
84-
console.log(e)
85-
message.error(String(e))
82+
console.log(e);
83+
message.error(String(e));
8684
} finally {
87-
gettingScanStatus.value = false
85+
gettingScanStatus.value = false;
8886
}
8987
}
90-
9188
</script>
9289

9390
<template>
9491
<NSpace vertical size="large">
95-
<NButton size="large" type="primary" @click="goGet" block>Go to login</NButton>
96-
<NButton size="large" type="info" @click="getQrCode" block :loading="gettingQrCode" :disabled="!!qrcode">Scan QrCode
92+
<NButton size="large" type="primary" @click="goGet" block
93+
>Go to login</NButton
94+
>
95+
<NButton
96+
size="large"
97+
type="info"
98+
@click="getQrCode"
99+
block
100+
:loading="gettingQrCode"
101+
:disabled="!!qrcode"
102+
>Scan QrCode
97103
</NButton>
98104
<NAlert title="Error" type="error" v-if="qrcode?.error">
99105
{{ qrcode.error }}
@@ -102,10 +108,23 @@ async function haveScan() {
102108
<NSpace justify="center">
103109
<NImage width="300" :src="qrcode.qrCodeUrl" />
104110
</NSpace>
105-
<NAlert title="Scan the QrCode" type="info">Use AliyunDrive APP To Scan Then Click the Button Below</NAlert>
106-
<NButton size="large" @click="haveScan" type="info" block :loading="gettingScanStatus">I have scan</NButton>
111+
<NAlert title="Scan the QrCode" type="info"
112+
>Use AliyunDrive APP To Scan Then Click the Button Below</NAlert
113+
>
114+
<NButton
115+
size="large"
116+
@click="haveScan"
117+
type="info"
118+
block
119+
:loading="gettingScanStatus"
120+
>I have scan</NButton
121+
>
107122
</NSpace>
108-
<NAlert title="Warning" type="warning" v-if="scanStatus && scanStatus.status !== 'LoginSuccess'">
123+
<NAlert
124+
title="Warning"
125+
type="warning"
126+
v-if="scanStatus && scanStatus.status !== 'LoginSuccess'"
127+
>
109128
{{ scanStatus.status }}
110129
</NAlert>
111130
</NSpace>

0 commit comments

Comments
 (0)