@@ -5,7 +5,6 @@ import {pubLogin} from "../shares/oauthv2";
55import * as configs from "../shares/configs" ;
66import { pubParse } from "../shares/urlback" ;
77import { encodeCallbackData } from "../shares/secrets" ;
8- import { pubRenew } from "../shares/refresh" ;
98
109
1110const driver_map : string [ ] = [
@@ -14,6 +13,14 @@ const driver_map: string[] = [
1413 "https://www.123pan.com/auth"
1514]
1615
16+ function toQueryString ( params : Record < string , any > ) : string {
17+ return new URLSearchParams (
18+ Object . fromEntries ( Object . entries ( params )
19+ . filter ( ( [ _ , v ] ) => v !== undefined )
20+ . map ( ( [ k , v ] ) => [ k , String ( v ) ] ) )
21+ ) . toString ( ) ;
22+ }
23+
1724// 登录申请 ##############################################################################
1825export async function oneLogin ( c : Context ) {
1926 const clients_info : configs . Clients | undefined = configs . getInfo ( c ) ;
@@ -55,11 +62,7 @@ export async function oneToken(c: Context) {
5562 refresh_token : refresh_text || undefined
5663 }
5764 console . log ( params ) ;
58- const query_str = new URLSearchParams (
59- Object . fromEntries ( Object . entries ( params )
60- . filter ( ( [ _ , v ] ) => v !== undefined )
61- . map ( ( [ k , v ] ) => [ k , String ( v ) ] ) )
62- ) . toString ( ) ;
65+ const query_str = toQueryString ( params ) ;
6366 const result = await pubLogin (
6467 c , "" , `${ driver_map [ 1 ] } ?${ query_str } ` ,
6568 false , "POST" , "json" ) ;
@@ -69,6 +72,7 @@ export async function oneToken(c: Context) {
6972 return c . redirect ( "/#" + encodeCallbackData ( {
7073 access_token : result . access_token ,
7174 refresh_token : result . refresh_token ,
75+ expires_in : result . expires_in ,
7276 driver_txt : "123cloud_oa" ,
7377 server_use : true
7478 } ) ) ;
@@ -78,14 +82,23 @@ export async function oneToken(c: Context) {
7882export async function genToken ( c : Context ) {
7983 const refresh_text : string | undefined = c . req . query ( 'refresh_ui' ) ;
8084 if ( ! refresh_text ) return c . json ( { text : "缺少刷新令牌" } , 500 ) ;
81- const params : Record < string , string > = {
85+ const params : Record < string , any > = {
8286 client_id : c . env . cloud123_uid ,
8387 client_secret : c . env . cloud123_key ,
8488 grant_type : "refresh_token" ,
8589 redirect_uri : c . env . cloud123_url ,
8690 refresh_token : refresh_text
8791 } ;
88- return await pubRenew (
89- c , driver_map [ 1 ] , params ,
90- "POST" , "access_token" , "refresh_token" ) ;
92+ const result = await pubLogin (
93+ c , "" , `${ driver_map [ 1 ] } ?${ toQueryString ( params ) } ` ,
94+ false , "POST" , "json" ) ;
95+ if ( ! result || ! result . access_token )
96+ return c . json ( { text : result ?. error_description || "无法获取AccessToken" } , 500 ) ;
97+ const result_data : Record < string , any > = {
98+ refresh_token : result . refresh_token || refresh_text ,
99+ access_token : result . access_token ,
100+ } ;
101+ if ( result . expires_in !== undefined && result . expires_in !== null && result . expires_in !== "" )
102+ result_data . expires_in = result . expires_in ;
103+ return c . json ( result_data , 200 ) ;
91104}
0 commit comments