|
@@ -24,59 +24,77 @@ export class GrowiInfoService {
|
|
|
this.crowi = crowi;
|
|
this.crowi = crowi;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async getGrowiInfo(): Promise<IGrowiInfo<IGrowiAppAdditionalInfo>> {
|
|
|
|
|
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
- const User = mongoose.model<IUser, Model<IUser>>('User');
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Get GROWI information
|
|
|
|
|
+ */
|
|
|
|
|
+ getGrowiInfo(): Promise<IGrowiInfo<Record<string, never>>>;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Get GROWI information with additional information
|
|
|
|
|
+ * @param includeAdditionalInfo whether to include additional information
|
|
|
|
|
+ */
|
|
|
|
|
+ getGrowiInfo(includeAdditionalInfo: true): Promise<IGrowiInfo<IGrowiAppAdditionalInfo>>;
|
|
|
|
|
+
|
|
|
|
|
+ async getGrowiInfo(includeAdditionalInfo?: boolean): Promise<IGrowiInfo<Record<string, never>> | IGrowiInfo<IGrowiAppAdditionalInfo>> {
|
|
|
|
|
|
|
|
const appSiteUrl = this.crowi.appService.getSiteUrl();
|
|
const appSiteUrl = this.crowi.appService.getSiteUrl();
|
|
|
const hasher = crypto.createHash('sha256');
|
|
const hasher = crypto.createHash('sha256');
|
|
|
hasher.update(appSiteUrl);
|
|
hasher.update(appSiteUrl);
|
|
|
const appSiteUrlHashed = hasher.digest('hex');
|
|
const appSiteUrlHashed = hasher.digest('hex');
|
|
|
|
|
|
|
|
|
|
+ const isGuestAllowedToRead = aclService.isGuestAllowedToRead();
|
|
|
|
|
+ const wikiType = isGuestAllowedToRead ? GrowiWikiType.open : GrowiWikiType.closed;
|
|
|
|
|
+
|
|
|
|
|
+ const baseInfo = {
|
|
|
|
|
+ version: this.crowi.version,
|
|
|
|
|
+ osInfo: {
|
|
|
|
|
+ type: os.type(),
|
|
|
|
|
+ platform: os.platform(),
|
|
|
|
|
+ arch: os.arch(),
|
|
|
|
|
+ totalmem: os.totalmem(),
|
|
|
|
|
+ },
|
|
|
|
|
+ appSiteUrl: configManager.getConfig('questionnaire:isAppSiteUrlHashed') ? undefined : appSiteUrl,
|
|
|
|
|
+ appSiteUrlHashed,
|
|
|
|
|
+ type: configManager.getConfig('app:serviceType'),
|
|
|
|
|
+ wikiType,
|
|
|
|
|
+ deploymentType: configManager.getConfig('app:deploymentType'),
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if (!includeAdditionalInfo) {
|
|
|
|
|
+ return baseInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...baseInfo,
|
|
|
|
|
+ additionalInfo: await this.getAdditionalInfo(),
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private async getAdditionalInfo(): Promise<IGrowiAppAdditionalInfo> {
|
|
|
|
|
+ const User = mongoose.model<IUser, Model<IUser>>('User');
|
|
|
|
|
+
|
|
|
// Get the oldest user who probably installed this GROWI.
|
|
// Get the oldest user who probably installed this GROWI.
|
|
|
const user = await User.findOne({ createdAt: { $ne: null } }).sort({ createdAt: 1 });
|
|
const user = await User.findOne({ createdAt: { $ne: null } }).sort({ createdAt: 1 });
|
|
|
-
|
|
|
|
|
const installedAtByOldestUser = user ? user.createdAt : null;
|
|
const installedAtByOldestUser = user ? user.createdAt : null;
|
|
|
|
|
|
|
|
const appInstalledConfig = await Config.findOne({ key: 'app:installed' });
|
|
const appInstalledConfig = await Config.findOne({ key: 'app:installed' });
|
|
|
const oldestConfig = await Config.findOne().sort({ createdAt: 1 });
|
|
const oldestConfig = await Config.findOne().sort({ createdAt: 1 });
|
|
|
-
|
|
|
|
|
- // oldestConfig must not be null because there is at least one config
|
|
|
|
|
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
const installedAt = installedAtByOldestUser ?? appInstalledConfig?.createdAt ?? oldestConfig!.createdAt ?? null;
|
|
const installedAt = installedAtByOldestUser ?? appInstalledConfig?.createdAt ?? oldestConfig!.createdAt ?? null;
|
|
|
|
|
|
|
|
const currentUsersCount = await User.countDocuments();
|
|
const currentUsersCount = await User.countDocuments();
|
|
|
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
const currentActiveUsersCount = await (User as any).countActiveUsers();
|
|
const currentActiveUsersCount = await (User as any).countActiveUsers();
|
|
|
|
|
|
|
|
- const isGuestAllowedToRead = aclService.isGuestAllowedToRead();
|
|
|
|
|
- const wikiType = isGuestAllowedToRead ? GrowiWikiType.open : GrowiWikiType.closed;
|
|
|
|
|
-
|
|
|
|
|
const activeExternalAccountTypes: IExternalAuthProviderType[] = Object.values(IExternalAuthProviderType).filter((type) => {
|
|
const activeExternalAccountTypes: IExternalAuthProviderType[] = Object.values(IExternalAuthProviderType).filter((type) => {
|
|
|
return configManager.getConfig(`security:passport-${type}:isEnabled`);
|
|
return configManager.getConfig(`security:passport-${type}:isEnabled`);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
- version: this.crowi.version,
|
|
|
|
|
- osInfo: {
|
|
|
|
|
- type: os.type(),
|
|
|
|
|
- platform: os.platform(),
|
|
|
|
|
- arch: os.arch(),
|
|
|
|
|
- totalmem: os.totalmem(),
|
|
|
|
|
- },
|
|
|
|
|
- appSiteUrl: configManager.getConfig('questionnaire:isAppSiteUrlHashed') ? undefined : appSiteUrl,
|
|
|
|
|
- appSiteUrlHashed,
|
|
|
|
|
- type: configManager.getConfig('app:serviceType'),
|
|
|
|
|
- wikiType,
|
|
|
|
|
- deploymentType: configManager.getConfig('app:deploymentType'),
|
|
|
|
|
- additionalInfo: {
|
|
|
|
|
- installedAt,
|
|
|
|
|
- installedAtByOldestUser,
|
|
|
|
|
- currentUsersCount,
|
|
|
|
|
- currentActiveUsersCount,
|
|
|
|
|
- attachmentType: configManager.getConfig('app:fileUploadType'),
|
|
|
|
|
- activeExternalAccountTypes,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ installedAt,
|
|
|
|
|
+ installedAtByOldestUser,
|
|
|
|
|
+ currentUsersCount,
|
|
|
|
|
+ currentActiveUsersCount,
|
|
|
|
|
+ attachmentType: configManager.getConfig('app:fileUploadType'),
|
|
|
|
|
+ activeExternalAccountTypes,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|