From a72470c1932067928336943c9ef307aff4ef296f Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Wed, 4 Aug 2021 12:11:19 +0200 Subject: [PATCH] feat(techdocs-common): lowercase entity triplet path for Azure Signed-off-by: Camila Belo --- .../src/stages/publish/azureBlobStorage.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts b/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts index fe8fe9c2ce..8af6137e0c 100644 --- a/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts +++ b/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts @@ -18,7 +18,11 @@ import { BlobServiceClient, StorageSharedKeyCredential, } from '@azure/storage-blob'; -import { Entity, EntityName } from '@backstage/catalog-model'; +import { + Entity, + EntityName, + ENTITY_DEFAULT_NAMESPACE, +} from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import express from 'express'; import JSON5 from 'json5'; @@ -159,8 +163,12 @@ export class AzureBlobStoragePublish implements PublisherBase { .join(path.posix.sep); // The / delimiter is intentional since it represents the cloud storage and not the local file system. - const entityRootDir = `${entity.metadata.namespace}/${entity.kind}/${entity.metadata.name}`; - const destination = `${entityRootDir}/${relativeFilePathPosix}`; // Azure Blob Storage Container file relative path + const entityRootDir = `${ + entity.metadata?.namespace ?? ENTITY_DEFAULT_NAMESPACE + }/${entity.kind}/${entity.metadata.name}`; + const destination = lowerCaseEntityTripletInStoragePath( + `${entityRootDir}/${relativeFilePathPosix}`, + ); // Azure Blob Storage Container file relative path return limiter(async () => { const response = await this.storageClient .getContainerClient(this.containerName) @@ -259,8 +267,11 @@ export class AzureBlobStoragePublish implements PublisherBase { docsRouter(): express.Handler { return (req, res) => { // Decode and trim the leading forward slash + const decodedUri = decodeURI(req.path.replace(/^\//, '')); + // filePath example - /default/Component/documented-component/index.html - const filePath = decodeURI(req.path.replace(/^\//, '')); + const filePath = lowerCaseEntityTripletInStoragePath(decodedUri); + // Files with different extensions (CSS, HTML) need to be served with different headers const fileExtension = platformPath.extname(filePath); const responseHeaders = getHeadersForFileExtension(fileExtension);