mirror of
https://github.com/koishijs/novelai-bot
synced 2025-01-07 07:06:54 +08:00
feat: support novelai new api endpoint (#248)
This commit is contained in:
parent
8490f26c2b
commit
aaf624cc3d
@ -209,6 +209,7 @@ export interface Config extends PromptConfig, ParamConfig {
|
||||
authLvDefault?: Computed<number>
|
||||
output?: Computed<'minimal' | 'default' | 'verbose'>
|
||||
features?: FeatureConfig
|
||||
apiEndpoint?: string
|
||||
endpoint?: string
|
||||
headers?: Dict<string>
|
||||
nsfw?: Computed<'disallow' | 'censor' | 'allow'>
|
||||
@ -246,7 +247,8 @@ export const Config = Schema.intersect([
|
||||
}),
|
||||
]),
|
||||
Schema.object({
|
||||
endpoint: Schema.string().description('API 服务器地址。').default('https://api.novelai.net'),
|
||||
apiEndpoint: Schema.string().description('API 服务器地址。').default('https://api.novelai.net'),
|
||||
endpoint: Schema.string().description('图片生成服务器地址。').default('https://image.novelai.net'),
|
||||
headers: Schema.dict(String).role('table').description('要附加的额外请求头。').default({
|
||||
'referer': 'https://novelai.net/',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
|
||||
|
@ -105,13 +105,13 @@ export class NetworkError extends Error {
|
||||
|
||||
export async function login(ctx: Context): Promise<string> {
|
||||
if (ctx.config.type === 'token') {
|
||||
await ctx.http.get<Subscription>(ctx.config.endpoint + '/user/subscription', {
|
||||
await ctx.http.get<Subscription>(ctx.config.apiEndpoint + '/user/subscription', {
|
||||
timeout: 30000,
|
||||
headers: { authorization: 'Bearer ' + ctx.config.token },
|
||||
}).catch(NetworkError.catch({ 401: '.invalid-token' }))
|
||||
return ctx.config.token
|
||||
} else if (ctx.config.type === 'login' && process.env.KOISHI_ENV !== 'browser') {
|
||||
return ctx.http.post(ctx.config.endpoint + '/user/login', {
|
||||
return ctx.http.post(ctx.config.apiEndpoint + '/user/login', {
|
||||
timeout: 30000,
|
||||
key: await calcAccessKey(ctx.config.email, ctx.config.password),
|
||||
}).catch(NetworkError.catch({ 401: '.invalid-password' })).then(res => res.accessToken)
|
||||
|
Loading…
Reference in New Issue
Block a user