refractor: nutstore sdk changed to JS version (#4913)
Co-authored-by: shlroland <shlroland1995@gmail.com>
This commit is contained in:
parent
c10e5a9ca4
commit
f0c25f8108
14
src/main/integration/nutstore/sso/lib/index.d.mts
Normal file
14
src/main/integration/nutstore/sso/lib/index.d.mts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
interface CreateOAuthUrlArgs {
|
||||||
|
app: string;
|
||||||
|
}
|
||||||
|
declare function createOAuthUrl({ app }: CreateOAuthUrlArgs): Promise<string>;
|
||||||
|
declare function _dont_use_in_prod_createOAuthUrl({ app, }: CreateOAuthUrlArgs): Promise<string>;
|
||||||
|
|
||||||
|
interface DecryptSecretArgs {
|
||||||
|
app: string;
|
||||||
|
s: string;
|
||||||
|
}
|
||||||
|
declare function decryptSecret({ app, s }: DecryptSecretArgs): Promise<string>;
|
||||||
|
declare function _dont_use_in_prod_decryptSecret({ app, s, }: DecryptSecretArgs): Promise<string>;
|
||||||
|
|
||||||
|
export { type CreateOAuthUrlArgs, type DecryptSecretArgs, _dont_use_in_prod_createOAuthUrl, _dont_use_in_prod_decryptSecret, createOAuthUrl, decryptSecret };
|
||||||
@ -1,8 +0,0 @@
|
|||||||
declare function decrypt(app: string, s: string): string
|
|
||||||
|
|
||||||
interface Secret {
|
|
||||||
app: string
|
|
||||||
}
|
|
||||||
declare function createOAuthUrl(secret: Secret): string
|
|
||||||
|
|
||||||
export { type Secret, createOAuthUrl, decrypt }
|
|
||||||
File diff suppressed because it is too large
Load Diff
1
src/main/integration/nutstore/sso/lib/index.mjs
Normal file
1
src/main/integration/nutstore/sso/lib/index.mjs
Normal file
File diff suppressed because one or more lines are too long
@ -5,6 +5,8 @@ import { XMLParser } from 'fast-xml-parser'
|
|||||||
import { isNil, partial } from 'lodash'
|
import { isNil, partial } from 'lodash'
|
||||||
import { type FileStat } from 'webdav'
|
import { type FileStat } from 'webdav'
|
||||||
|
|
||||||
|
import { createOAuthUrl, decryptSecret } from '../integration/nutstore/sso/lib/index.mjs'
|
||||||
|
|
||||||
interface OAuthResponse {
|
interface OAuthResponse {
|
||||||
username: string
|
username: string
|
||||||
userid: string
|
userid: string
|
||||||
@ -30,18 +32,18 @@ interface WebDAVResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getNutstoreSSOUrl() {
|
export async function getNutstoreSSOUrl() {
|
||||||
const { createOAuthUrl } = await import('../integration/nutstore/sso/lib')
|
const url = await createOAuthUrl({
|
||||||
|
|
||||||
const url = createOAuthUrl({
|
|
||||||
app: 'cherrystudio'
|
app: 'cherrystudio'
|
||||||
})
|
})
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function decryptToken(token: string) {
|
export async function decryptToken(token: string) {
|
||||||
const { decrypt } = await import('../integration/nutstore/sso/lib')
|
|
||||||
try {
|
try {
|
||||||
const decrypted = decrypt('cherrystudio', token)
|
const decrypted = await decryptSecret({
|
||||||
|
app: 'cherrystudio',
|
||||||
|
s: token
|
||||||
|
})
|
||||||
return JSON.parse(decrypted) as OAuthResponse
|
return JSON.parse(decrypted) as OAuthResponse
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('解密失败:', error)
|
console.error('解密失败:', error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user