|
| 1 | +<script lang="ts" setup> |
| 2 | +import { NAlert, NButton, NInput, NSpace, NSpin } from "naive-ui"; |
| 3 | +import { reactive } from "vue"; |
| 4 | +import { api } from "../api"; |
| 5 | +
|
| 6 | +const cur = "http://localhost:8080"; |
| 7 | +const redirect_uri = `${cur}/tool/dropbox/callback`; |
| 8 | +
|
| 9 | +const url = new URL(window.location.href); |
| 10 | +const code = url.searchParams.get("code"); |
| 11 | +const client = url.searchParams.get("state"); |
| 12 | +const error = url.searchParams.get("error"); |
| 13 | +const error_description = url.searchParams.get("error_description"); |
| 14 | +
|
| 15 | +const [client_id, client_secret] = atob(client as string).split("::"); |
| 16 | +
|
| 17 | +const data = reactive({ |
| 18 | + refreshToken: "", |
| 19 | + accessToken: "", |
| 20 | + error1: "", |
| 21 | + errorMessage1: "", |
| 22 | +}); |
| 23 | +
|
| 24 | +const getToken = () => { |
| 25 | + fetch(`${api()}/alist/dropbox/token`, { |
| 26 | + method: "POST", |
| 27 | + headers: { |
| 28 | + "Content-Type": "application/json", |
| 29 | + }, |
| 30 | + body: JSON.stringify({ |
| 31 | + code, |
| 32 | + client_id, |
| 33 | + client_secret, |
| 34 | + grant_type: "authorization_code", |
| 35 | + redirect_uri: redirect_uri, |
| 36 | + }), |
| 37 | + }) |
| 38 | + .then((resp) => resp.json()) |
| 39 | + .then((res) => { |
| 40 | + console.log(res); |
| 41 | + if (res.error) { |
| 42 | + data.error1 = res.error; |
| 43 | + data.errorMessage1 = res.error_description; |
| 44 | + return; |
| 45 | + } |
| 46 | + data.refreshToken = res.refresh_token; |
| 47 | + data.accessToken = res.access_token; |
| 48 | + }); |
| 49 | +}; |
| 50 | +
|
| 51 | +if (code && client && !error) { |
| 52 | + getToken(); |
| 53 | +} |
| 54 | +</script> |
| 55 | + |
| 56 | +<template> |
| 57 | + <NAlert |
| 58 | + :title="error || 'Error'" |
| 59 | + type="error" |
| 60 | + v-if="!code || !client || error" |
| 61 | + > |
| 62 | + {{ error_description }} |
| 63 | + </NAlert> |
| 64 | + <NSpace v-else vertical size="large"> |
| 65 | + <p><b>client_id: </b>{{ client_id }}</p> |
| 66 | + <p><b>client_secret: </b>{{ client_secret }}</p> |
| 67 | + <p><b>redirect_uri: </b>{{ redirect_uri }}</p> |
| 68 | + <NAlert |
| 69 | + :title="data.error1" |
| 70 | + type="error" |
| 71 | + v-if="data.error1 || data.errorMessage1" |
| 72 | + > |
| 73 | + {{ data.errorMessage1 }} |
| 74 | + </NAlert> |
| 75 | + <NSpace vertical> |
| 76 | + <b>refresh_token:</b> |
| 77 | + <NSpin v-if="!data.refreshToken && !data.errorMessage1" /> |
| 78 | + <NInput |
| 79 | + v-else |
| 80 | + type="textarea" |
| 81 | + autosize |
| 82 | + readonly |
| 83 | + :value="data.refreshToken" |
| 84 | + /> |
| 85 | + </NSpace> |
| 86 | + </NSpace> |
| 87 | +</template> |
| 88 | + |
| 89 | +<style scoped> |
| 90 | +p { |
| 91 | + margin: 0; |
| 92 | + font-size: large; |
| 93 | +} |
| 94 | +</style> |
0 commit comments