mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-03 08:35:29 +02:00
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { PluginSettings } from './services/plugins/PluginService';
|
|
import type PluginService from './services/plugins/PluginService';
|
|
import versionInfo, { PackageInfo } from './versionInfo';
|
|
|
|
const renderErrorBlock = (errors: any[]): string => {
|
|
if (!errors.length) return '';
|
|
return `\`\`\`\n${errors.map(e => typeof e === 'string' ? e.trim() : e.message.trim())}\n\`\`\``;
|
|
};
|
|
|
|
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 '';
|
|
};
|
|
|
|
export default (title: string, body: string, errors: any[], packageInfo: PackageInfo, pluginService: PluginService, pluginSettings: PluginSettings) => {
|
|
const v = versionInfo(packageInfo, pluginService.enabledPlugins(pluginSettings));
|
|
|
|
const errorBlock = renderErrorBlock(errors);
|
|
|
|
const query: Record<string, string> = {
|
|
title,
|
|
category: 'support',
|
|
version: packageInfo.version,
|
|
os: getOsName(process.platform),
|
|
'desktop-about-content': v.body,
|
|
content: `#### Body\n\n${body}${errorBlock ? `\n\n#### Errors\n\n${errorBlock}` : ''}`,
|
|
};
|
|
|
|
const queryString = Object.keys(query).map(k => `${k}=${encodeURIComponent(query[k])}`).join('&');
|
|
|
|
const url = `https://discourse.joplinapp.org/new-topic?${queryString}`;
|
|
return url;
|
|
};
|