Skip to content

Commit 3448ee1

Browse files
committed
Endepunkt for content html
1 parent ffc6cd0 commit 3448ee1

File tree

4 files changed

+31
-50
lines changed

4 files changed

+31
-50
lines changed

server/src/cms/CmsArchiveContentService.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { CmsCategoryListItem } from '../../../common/cms-documents/category';
21
import { CmsContent, CmsContentDocument } from '../../../common/cms-documents/content';
32
import { CmsArchiveOpenSearchClient } from '../opensearch/CmsArchiveOpenSearchClient';
43
import { CmsBinaryDocument } from '../../../common/cms-documents/binary';
54
import { CmsArchiveSiteConfig } from './CmsArchiveSite';
65
import { sortVersions } from '../utils/sort';
7-
import { AssetDocument, CmsCategoryDocument } from '../opensearch/types';
8-
import { transformToCategoriesList } from './utils/transformToCategoriesList';
9-
import { CmsCategoryPath } from '../../../common/cms-documents/_common';
6+
import { AssetDocument } from '../opensearch/types';
107
import { ContentSearchParams, ContentSearchResult } from '../../../common/contentSearch';
118
import { buildContentSearchParams } from '../opensearch/queries/contentSearch';
129
import { CmsArchiveCategoriesService } from './CmsArchiveCategoriesService';

server/src/cms/CmsArchiveSite.ts

+29-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type ContructorProps = {
2222

2323
export class CmsArchiveSite {
2424
private readonly config: CmsArchiveSiteConfig;
25-
private readonly cmsArchiveService: CmsArchiveContentService;
25+
private readonly cmsArchiveContentService: CmsArchiveContentService;
2626
private readonly cmsArchiveCategoriesService: CmsArchiveCategoriesService;
2727

2828
constructor({ config, expressApp, dbClient, htmlRenderer }: ContructorProps) {
@@ -33,7 +33,7 @@ export class CmsArchiveSite {
3333
client: dbClient,
3434
});
3535

36-
this.cmsArchiveService = new CmsArchiveContentService({
36+
this.cmsArchiveContentService = new CmsArchiveContentService({
3737
client: dbClient,
3838
siteConfig: config,
3939
categoriesService: this.cmsArchiveCategoriesService,
@@ -73,7 +73,7 @@ export class CmsArchiveSite {
7373
router.get('/content/:contentKey', async (req, res) => {
7474
const { contentKey } = req.params;
7575

76-
const content = await this.cmsArchiveService.getContent(contentKey);
76+
const content = await this.cmsArchiveContentService.getContent(contentKey);
7777
if (!content) {
7878
return res.status(404).send(`Content with key ${contentKey} not found`);
7979
}
@@ -84,7 +84,8 @@ export class CmsArchiveSite {
8484
router.get('/version/:versionKey', async (req, res) => {
8585
const { versionKey } = req.params;
8686

87-
const contentVersion = await this.cmsArchiveService.getContentVersion(versionKey);
87+
const contentVersion =
88+
await this.cmsArchiveContentService.getContentVersion(versionKey);
8889
if (!contentVersion) {
8990
return res.status(404).send(`Content version with key ${versionKey} not found`);
9091
}
@@ -98,7 +99,7 @@ export class CmsArchiveSite {
9899
return res.status(400).send('Invalid parameters for search request');
99100
}
100101

101-
const result = await this.cmsArchiveService.contentSearch(params);
102+
const result = await this.cmsArchiveContentService.contentSearch(params);
102103

103104
return res.send(result);
104105
});
@@ -119,13 +120,30 @@ export class CmsArchiveSite {
119120

120121
return res.send(html);
121122
});
123+
124+
router.get('/html/:versionKey', async (req, res) => {
125+
const { versionKey } = req.params;
126+
127+
const version = await this.cmsArchiveContentService.getContentVersion(versionKey);
128+
if (!version) {
129+
return res.status(404).send(`Content with version key ${versionKey} not found`);
130+
}
131+
132+
if (!version.html) {
133+
return res
134+
.status(406)
135+
.send(`Content with version key ${versionKey} does not have html content`);
136+
}
137+
138+
return res.send(version.html);
139+
});
122140
}
123141

124142
private setupFileRoutes(router: Router) {
125143
router.get('/binary/file/:binaryKey', async (req, res) => {
126144
const { binaryKey } = req.params;
127145

128-
const binary = await this.cmsArchiveService.getBinary(binaryKey);
146+
const binary = await this.cmsArchiveContentService.getBinary(binaryKey);
129147
if (!binary) {
130148
return res.status(404).send(`Binary with key ${binaryKey} not found`);
131149
}
@@ -139,7 +157,7 @@ export class CmsArchiveSite {
139157
});
140158

141159
router.use('/_public', async (req, res, next) => {
142-
const file = await this.cmsArchiveService.getStaticAsset(req.path);
160+
const file = await this.cmsArchiveContentService.getStaticAsset(req.path);
143161
if (!file) {
144162
return next();
145163
}
@@ -148,7 +166,7 @@ export class CmsArchiveSite {
148166
});
149167

150168
router.use('/*/_image/:contentKey.:extension', async (req, res, next) => {
151-
const content = await this.cmsArchiveService.getContent(req.params.contentKey);
169+
const content = await this.cmsArchiveContentService.getContent(req.params.contentKey);
152170
if (!content) {
153171
return next();
154172
}
@@ -158,7 +176,7 @@ export class CmsArchiveSite {
158176
return next();
159177
}
160178

161-
const binary = await this.cmsArchiveService.getBinary(binaryKey);
179+
const binary = await this.cmsArchiveContentService.getBinary(binaryKey);
162180
if (!binary) {
163181
return next();
164182
}
@@ -167,7 +185,7 @@ export class CmsArchiveSite {
167185
});
168186

169187
router.use('/*/_image/:contentKey/label/:label.:extension', async (req, res, next) => {
170-
const content = await this.cmsArchiveService.getContent(req.params.contentKey);
188+
const content = await this.cmsArchiveContentService.getContent(req.params.contentKey);
171189
if (!content) {
172190
return next();
173191
}
@@ -179,7 +197,7 @@ export class CmsArchiveSite {
179197
return next();
180198
}
181199

182-
const binary = await this.cmsArchiveService.getBinary(binaryKey);
200+
const binary = await this.cmsArchiveContentService.getBinary(binaryKey);
183201
if (!binary) {
184202
return next();
185203
}

server/src/cms/utils/transformToCategoriesList.ts

-34
This file was deleted.

server/src/routing/site.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const archiveConfigs: CmsArchiveSiteConfig[] = [
1414
basePath: '/fss',
1515
indexPrefix: 'cmsfss',
1616
},
17-
];
17+
] as const;
1818

1919
export const setupCmsArchiveSites = async (expressApp: Express) => {
2020
const archiveClient = new CmsArchiveOpenSearchClient();

0 commit comments

Comments
 (0)