|
|
|
@ -6,8 +6,9 @@ import NcToolGui from 'nc-lib-gui';
|
|
|
|
|
import { IoAdapter } from '@nestjs/platform-socket.io'; |
|
|
|
|
import requestIp from 'request-ip'; |
|
|
|
|
import cookieParser from 'cookie-parser'; |
|
|
|
|
import { T } from 'nc-help'; |
|
|
|
|
import { v4 as uuidv4 } from 'uuid'; |
|
|
|
|
import { AppModule } from './app.module'; |
|
|
|
|
|
|
|
|
|
import { NC_LICENSE_KEY } from './constants'; |
|
|
|
|
import Store from './models/Store'; |
|
|
|
|
import type { IEventEmitter } from './modules/event-emitter/event-emitter.interface'; |
|
|
|
@ -125,4 +126,41 @@ export default class Noco {
|
|
|
|
|
public static get server(): Express { |
|
|
|
|
return Noco._server; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static async initJwt(): Promise<any> { |
|
|
|
|
if (this.config?.auth?.jwt) { |
|
|
|
|
if (!this.config.auth.jwt.secret) { |
|
|
|
|
let secret = ( |
|
|
|
|
await Noco._ncMeta.metaGet('', '', 'nc_store', { |
|
|
|
|
key: 'nc_auth_jwt_secret', |
|
|
|
|
}) |
|
|
|
|
)?.value; |
|
|
|
|
if (!secret) { |
|
|
|
|
await Noco._ncMeta.metaInsert('', '', 'nc_store', { |
|
|
|
|
key: 'nc_auth_jwt_secret', |
|
|
|
|
value: (secret = uuidv4()), |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
this.config.auth.jwt.secret = secret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.config.auth.jwt.options = this.config.auth.jwt.options || {}; |
|
|
|
|
if (!this.config.auth.jwt.options?.expiresIn) { |
|
|
|
|
this.config.auth.jwt.options.expiresIn = |
|
|
|
|
process.env.NC_JWT_EXPIRES_IN ?? '10h'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
let serverId = ( |
|
|
|
|
await Noco._ncMeta.metaGet('', '', 'nc_store', { |
|
|
|
|
key: 'nc_server_id', |
|
|
|
|
}) |
|
|
|
|
)?.value; |
|
|
|
|
if (!serverId) { |
|
|
|
|
await Noco._ncMeta.metaInsert('', '', 'nc_store', { |
|
|
|
|
key: 'nc_server_id', |
|
|
|
|
value: (serverId = T.id), |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
process.env.NC_SERVER_UUID = serverId; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|