Skip to content

Commit 509755b

Browse files
author
lilu
committed
提供alist兼容
1 parent 91701ab commit 509755b

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎index.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import path from "path";
44
import { fileURLToPath } from "url";
55
const __dirname = path.dirname(fileURLToPath(import.meta.url));
66
var app = express();
7+
// 解析 JSON 请求体
8+
app.use(express.json())
9+
// 解析 URL 编码请求体(如表单数据)
10+
app.use(express.urlencoded({ extended: true }))
711
async function refreshToken(refreshTokenValue) {
812
const t = Math.floor(Date.now() / 1000);
913

@@ -178,6 +182,40 @@ app.get("/token", async function (req, res) {
178182
}
179183
});
180184

185+
//刷新token alist兼容
186+
app.post("/token", async function (req, res) {
187+
try {
188+
189+
console.log('req.body',req.body)
190+
191+
const { refresh_token } = req.body;
192+
193+
if (!refresh_token) {
194+
return res.json({
195+
refresh_token: "",
196+
access_token: "",
197+
text: "refresh_token parameter is required",
198+
});
199+
}
200+
201+
const tokenInfo = await refreshToken(refresh_token);
202+
203+
console.log("tokenInfo", tokenInfo);
204+
205+
return res.json({
206+
refresh_token: tokenInfo.refresh_token,
207+
access_token: tokenInfo.access_token,
208+
text: "",
209+
});
210+
} catch (error) {
211+
return res.json({
212+
refresh_token: "",
213+
access_token: "",
214+
text: error.message || "Unexpected error",
215+
});
216+
}
217+
});
218+
181219
// 网页扫码
182220
app.get("/", function (req, res) {
183221
res.sendFile(path.join(__dirname, "public", "index.html"));

0 commit comments

Comments
 (0)