2023-10-24 13:20:54 +02:00
|
|
|
import { PluginSettings } from './services/plugins/PluginService';
|
|
|
|
import type PluginService from './services/plugins/PluginService';
|
2023-11-11 19:38:16 +02:00
|
|
|
import versionInfo, { PackageInfo } from './versionInfo';
|
2023-10-24 13:20:54 +02:00
|
|
|
|
2023-12-16 15:12:00 +02:00
|
|
|
export const renderErrorBlock = (errors: (string | Error)[]): string => {
|
2023-10-24 13:20:54 +02:00
|
|
|
if (!errors.length) return '';
|
2023-12-16 15:12:00 +02:00
|
|
|
return `\`\`\`\n${errors.map(e => {
|
|
|
|
if (typeof e === 'string') return e.trim();
|
|
|
|
return e.message.trim() + e.stack ? `\n${e.stack}` : '';
|
|
|
|
}).map(l => l.trim()).join('\n\n')}\n\`\`\``;
|
2023-10-24 13:20:54 +02:00
|
|
|
};
|
|
|
|
|
2023-11-11 19:38:16 +02:00
|
|
|
const getOsName = (platform: typeof process.platform) => {
|
|
|
|
if (platform === 'win32') return 'Windows';
|
|
|
|
if (platform === 'darwin') return 'macOS';
|
|
|
|
if (platform === 'linux') return 'Linux';
|
|
|
|
if (platform === 'android') return 'Android';
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
2023-12-16 15:12:00 +02:00
|
|
|
export default (title: string, body: string, errors: (string | Error)[], packageInfo: PackageInfo, pluginService: PluginService, pluginSettings: PluginSettings) => {
|
2023-10-24 13:20:54 +02:00
|
|
|
const v = versionInfo(packageInfo, pluginService.enabledPlugins(pluginSettings));
|
|
|
|
|
|
|
|
const errorBlock = renderErrorBlock(errors);
|
|
|
|
|
|
|
|
const query: Record<string, string> = {
|
|
|
|
title,
|
|
|
|
category: 'support',
|
2023-11-11 19:38:16 +02:00
|
|
|
version: packageInfo.version,
|
|
|
|
os: getOsName(process.platform),
|
|
|
|
'desktop-about-content': v.body,
|
|
|
|
content: `#### Body\n\n${body}${errorBlock ? `\n\n#### Errors\n\n${errorBlock}` : ''}`,
|
2023-10-24 13:20:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const queryString = Object.keys(query).map(k => `${k}=${encodeURIComponent(query[k])}`).join('&');
|
|
|
|
|
|
|
|
const url = `https://discourse.joplinapp.org/new-topic?${queryString}`;
|
|
|
|
return url;
|
|
|
|
};
|