@@ -22,7 +22,7 @@ type ContructorProps = {
22
22
23
23
export class CmsArchiveSite {
24
24
private readonly config : CmsArchiveSiteConfig ;
25
- private readonly cmsArchiveService : CmsArchiveContentService ;
25
+ private readonly cmsArchiveContentService : CmsArchiveContentService ;
26
26
private readonly cmsArchiveCategoriesService : CmsArchiveCategoriesService ;
27
27
28
28
constructor ( { config, expressApp, dbClient, htmlRenderer } : ContructorProps ) {
@@ -33,7 +33,7 @@ export class CmsArchiveSite {
33
33
client : dbClient ,
34
34
} ) ;
35
35
36
- this . cmsArchiveService = new CmsArchiveContentService ( {
36
+ this . cmsArchiveContentService = new CmsArchiveContentService ( {
37
37
client : dbClient ,
38
38
siteConfig : config ,
39
39
categoriesService : this . cmsArchiveCategoriesService ,
@@ -73,7 +73,7 @@ export class CmsArchiveSite {
73
73
router . get ( '/content/:contentKey' , async ( req , res ) => {
74
74
const { contentKey } = req . params ;
75
75
76
- const content = await this . cmsArchiveService . getContent ( contentKey ) ;
76
+ const content = await this . cmsArchiveContentService . getContent ( contentKey ) ;
77
77
if ( ! content ) {
78
78
return res . status ( 404 ) . send ( `Content with key ${ contentKey } not found` ) ;
79
79
}
@@ -84,7 +84,8 @@ export class CmsArchiveSite {
84
84
router . get ( '/version/:versionKey' , async ( req , res ) => {
85
85
const { versionKey } = req . params ;
86
86
87
- const contentVersion = await this . cmsArchiveService . getContentVersion ( versionKey ) ;
87
+ const contentVersion =
88
+ await this . cmsArchiveContentService . getContentVersion ( versionKey ) ;
88
89
if ( ! contentVersion ) {
89
90
return res . status ( 404 ) . send ( `Content version with key ${ versionKey } not found` ) ;
90
91
}
@@ -98,7 +99,7 @@ export class CmsArchiveSite {
98
99
return res . status ( 400 ) . send ( 'Invalid parameters for search request' ) ;
99
100
}
100
101
101
- const result = await this . cmsArchiveService . contentSearch ( params ) ;
102
+ const result = await this . cmsArchiveContentService . contentSearch ( params ) ;
102
103
103
104
return res . send ( result ) ;
104
105
} ) ;
@@ -119,13 +120,30 @@ export class CmsArchiveSite {
119
120
120
121
return res . send ( html ) ;
121
122
} ) ;
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
+ } ) ;
122
140
}
123
141
124
142
private setupFileRoutes ( router : Router ) {
125
143
router . get ( '/binary/file/:binaryKey' , async ( req , res ) => {
126
144
const { binaryKey } = req . params ;
127
145
128
- const binary = await this . cmsArchiveService . getBinary ( binaryKey ) ;
146
+ const binary = await this . cmsArchiveContentService . getBinary ( binaryKey ) ;
129
147
if ( ! binary ) {
130
148
return res . status ( 404 ) . send ( `Binary with key ${ binaryKey } not found` ) ;
131
149
}
@@ -139,7 +157,7 @@ export class CmsArchiveSite {
139
157
} ) ;
140
158
141
159
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 ) ;
143
161
if ( ! file ) {
144
162
return next ( ) ;
145
163
}
@@ -148,7 +166,7 @@ export class CmsArchiveSite {
148
166
} ) ;
149
167
150
168
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 ) ;
152
170
if ( ! content ) {
153
171
return next ( ) ;
154
172
}
@@ -158,7 +176,7 @@ export class CmsArchiveSite {
158
176
return next ( ) ;
159
177
}
160
178
161
- const binary = await this . cmsArchiveService . getBinary ( binaryKey ) ;
179
+ const binary = await this . cmsArchiveContentService . getBinary ( binaryKey ) ;
162
180
if ( ! binary ) {
163
181
return next ( ) ;
164
182
}
@@ -167,7 +185,7 @@ export class CmsArchiveSite {
167
185
} ) ;
168
186
169
187
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 ) ;
171
189
if ( ! content ) {
172
190
return next ( ) ;
173
191
}
@@ -179,7 +197,7 @@ export class CmsArchiveSite {
179
197
return next ( ) ;
180
198
}
181
199
182
- const binary = await this . cmsArchiveService . getBinary ( binaryKey ) ;
200
+ const binary = await this . cmsArchiveContentService . getBinary ( binaryKey ) ;
183
201
if ( ! binary ) {
184
202
return next ( ) ;
185
203
}
0 commit comments