Skip to content

Commit

Permalink
Move default media files to regional storage (#2407)
Browse files Browse the repository at this point in the history
* Moved default media files to regional storage and change endpoints to use them accordingly

* fixed default.json conflicts

* code review changes
  • Loading branch information
malincrist authored Feb 23, 2024
1 parent dc7e69e commit 4a51397
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/services/provisioningService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as Constants from "../constants";
import { MapiClient } from "./mapiClient";
import { KnownMimeTypes } from "../models/knownMimeTypes";
import { KnownHttpHeaders } from "../models/knownHttpHeaders";
import { ISettingsProvider } from "@paperbits/common/configuration";

export class ProvisionService {
constructor(
Expand All @@ -15,7 +16,8 @@ export class ProvisionService {
private readonly authenticator: IAuthenticator,
private readonly viewManager: ViewManager,
private readonly router: Router,
private readonly blobStorage: AzureBlobStorage
private readonly blobStorage: AzureBlobStorage,
private readonly settingsProvider: ISettingsProvider
) { }

private async fetchData(url: string): Promise<Object> {
Expand All @@ -27,6 +29,9 @@ export class ProvisionService {
const dataUrl = `/editors/templates/default.json`;
const dataObj = await this.fetchData(dataUrl);
const keys = Object.keys(dataObj);

await this.setUpDefaultContent(dataObj);

const accessToken = await this.authenticator.getAccessTokenAsString();

if (!accessToken) {
Expand Down Expand Up @@ -106,4 +111,24 @@ export class ProvisionService {
await this.cleanupBlobs();
await this.cleanupContent();
}

private async setUpDefaultContent(dataObj: object): Promise<void> {
const backendUrl = await this.settingsProvider.getSetting<string>("backendUrl") || `https://${location.hostname}`;
const defaultMedias: { [name: string]: string } = {
"hero-gradient": "hero-gradient.jpg",
"featured-1": "featured-1.jpg",
"featured-2": "featured-2.jpg",
"featured-3": "featured-3.jpg",
"contoso-black": "contoso-black.png",
"logo-contoso-small": "logo-contoso-small.png"
}

const keyPath = "/contentTypes/blob/contentItems";
const downloadUrl = "/assets/images/";

for (const key in defaultMedias) {
const media = defaultMedias[key];
dataObj[`${keyPath}/${key}`]["properties"]["downloadUrl"] = backendUrl + downloadUrl + media;
}
}
}
Binary file added src/themes/website/images/contoso-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/themes/website/images/featured-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/themes/website/images/featured-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/themes/website/images/featured-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/themes/website/images/hero-gradient.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/themes/website/images/logo-contoso-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion templates/default.json

Large diffs are not rendered by default.

0 comments on commit 4a51397

Please sign in to comment.