[MM-36432][MM-37072][MM-37073] Logic to support Focalboard and Playbooks tabs (#1680)
* Tab stuff * Inter-tab navigation * Close tab functionality * [MM-36342][MM-37072] Logic to support Focalboard and Playbooks tabs * Update to version 5.0 * Update config.yml * Updated routes * Update names for products * [MM-37073] Close unneeded tabs when not using v6.0 * Merge'd * Update config.yml * Update config.yml * Fix menu names * PR feedback * blank * blank * blank * PR feedback * Update config.yml * PR feedback Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
55
src/main/server/serverAPI.ts
Normal file
55
src/main/server/serverAPI.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {net, session} from 'electron';
|
||||
import log from 'electron-log';
|
||||
|
||||
export async function getServerAPI<T>(url: URL, isAuthenticated: boolean, onSuccess?: (data: T) => void, onAbort?: () => void, onError?: (error: Error) => void) {
|
||||
if (isAuthenticated) {
|
||||
const cookies = await session.defaultSession.cookies.get({});
|
||||
if (!cookies) {
|
||||
log.error('Cannot authenticate, no cookies present');
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter out cookies that aren't part of our domain
|
||||
const filteredCookies = cookies.filter((cookie) => cookie.domain && url.toString().indexOf(cookie.domain) >= 0);
|
||||
|
||||
const userId = filteredCookies.find((cookie) => cookie.name === 'MMUSERID');
|
||||
const csrf = filteredCookies.find((cookie) => cookie.name === 'MMCSRF');
|
||||
const authToken = filteredCookies.find((cookie) => cookie.name === 'MMAUTHTOKEN');
|
||||
|
||||
if (!userId || !csrf || !authToken) {
|
||||
// Missing cookies needed for req
|
||||
log.error(`Cannot authenticate, required cookies for ${url.origin} not found`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const req = net.request({
|
||||
url: url.toString(),
|
||||
session: session.defaultSession,
|
||||
useSessionCookies: true,
|
||||
});
|
||||
|
||||
if (onSuccess) {
|
||||
req.on('response', (response: Electron.IncomingMessage) => {
|
||||
if (response.statusCode === 200) {
|
||||
response.on('data', (chunk: Buffer) => {
|
||||
const raw = `${chunk}`;
|
||||
const data = JSON.parse(raw) as T;
|
||||
onSuccess(data);
|
||||
});
|
||||
} else {
|
||||
onError?.(new Error(`Bad status code requesting from ${url.toString()}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (onAbort) {
|
||||
req.on('abort', onAbort);
|
||||
}
|
||||
if (onError) {
|
||||
req.on('error', onError);
|
||||
}
|
||||
req.end();
|
||||
}
|
Reference in New Issue
Block a user