-
Notifications
You must be signed in to change notification settings - Fork 8k
/
get_custom_logo.ts
49 lines (41 loc) · 1.54 KB
/
get_custom_logo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { UI_SETTINGS_CUSTOM_PDF_LOGO } from '../../../common/constants';
import { ConditionalHeaders, ServerFacade } from '../../../types';
import { JobDocPayloadPDF } from '../../printable_pdf/types'; // Logo is PDF only
export const getCustomLogo = async ({
job,
conditionalHeaders,
server,
}: {
job: JobDocPayloadPDF;
conditionalHeaders: ConditionalHeaders;
server: ServerFacade;
}) => {
const serverBasePath: string = server.config().get('server.basePath');
const fakeRequest: any = {
headers: conditionalHeaders.headers,
// This is used by the spaces SavedObjectClientWrapper to determine the existing space.
// We use the basePath from the saved job, which we'll have post spaces being implemented;
// or we use the server base path, which uses the default space
getBasePath: () => job.basePath || serverBasePath,
path: '/',
route: { settings: {} },
url: {
href: '/',
},
raw: {
req: {
url: '/',
},
},
};
const savedObjects = server.savedObjects;
const savedObjectsClient = savedObjects.getScopedSavedObjectsClient(fakeRequest);
const uiSettings = server.uiSettingsServiceFactory({ savedObjectsClient });
const logo = await uiSettings.get(UI_SETTINGS_CUSTOM_PDF_LOGO);
return { job, conditionalHeaders, logo, server };
};