feat: support novelai new api endpoint (#248)

This commit is contained in:
Maiko Sinkyaet Tan 2024-05-30 04:06:38 +08:00 committed by GitHub
parent 8490f26c2b
commit aaf624cc3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -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',

View File

@ -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)