-
Notifications
You must be signed in to change notification settings - Fork 211
/
GalleryRouter.ts
227 lines (193 loc) · 7.27 KB
/
GalleryRouter.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import {AuthenticationMWs} from '../middlewares/user/AuthenticationMWs';
import {Express} from 'express';
import {GalleryMWs} from '../middlewares/GalleryMWs';
import {RenderingMWs} from '../middlewares/RenderingMWs';
import {ThumbnailGeneratorMWs} from '../middlewares/thumbnail/ThumbnailGeneratorMWs';
import {UserRoles} from '../../common/entities/UserDTO';
import {ThumbnailSourceType} from '../model/threading/PhotoWorker';
import {VersionMWs} from '../middlewares/VersionMWs';
import {SupportedFormats} from '../../common/SupportedFormats';
import {PhotoConverterMWs} from '../middlewares/thumbnail/PhotoConverterMWs';
export class GalleryRouter {
public static route(app: Express): void {
this.addGetImageIcon(app);
this.addGetVideoIcon(app);
this.addGetPhotoThumbnail(app);
this.addGetVideoThumbnail(app);
this.addGetBestFitImage(app);
this.addGetImage(app);
this.addGetBestFitVideo(app);
this.addGetVideo(app);
this.addGetMetaFile(app);
this.addRandom(app);
this.addDirectoryList(app);
this.addDirectoryZip(app);
this.addSearch(app);
this.addAutoComplete(app);
}
protected static addDirectoryList(app: Express): void {
app.get(['/api/gallery/content/:directory(*)', '/api/gallery/', '/api/gallery//'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('directory'),
AuthenticationMWs.authorisePath('directory', true),
VersionMWs.injectGalleryVersion,
// specific part
GalleryMWs.listDirectory,
ThumbnailGeneratorMWs.addThumbnailInformation,
GalleryMWs.cleanUpGalleryResults,
RenderingMWs.renderResult
);
}
protected static addDirectoryZip(app: Express): void {
app.get(['/api/gallery/zip/:directory(*)'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('directory'),
AuthenticationMWs.authorisePath('directory', true),
// specific part
GalleryMWs.zipDirectory
);
}
protected static addGetImage(app: Express): void {
app.get(['/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Photos.join('|') + '))'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
RenderingMWs.renderFile
);
}
protected static addGetBestFitImage(app: Express): void {
app.get(['/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Photos.join('|') + '))/bestFit'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
PhotoConverterMWs.convertPhoto,
RenderingMWs.renderFile
);
}
protected static addGetVideo(app: Express): void {
app.get(['/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Videos.join('|') + '))'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
RenderingMWs.renderFile
);
}
protected static addGetBestFitVideo(app: Express): void {
app.get(['/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Videos.join('|') + '))/bestFit'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
GalleryMWs.loadBestFitVideo,
RenderingMWs.renderFile
);
}
protected static addGetMetaFile(app: Express): void {
app.get(['/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.MetaFiles.join('|') + '))'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
RenderingMWs.renderFile
);
}
protected static addRandom(app: Express): void {
app.get(['/api/gallery/random/:searchQueryDTO'],
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Guest),
VersionMWs.injectGalleryVersion,
// specific part
GalleryMWs.getRandomImage,
GalleryMWs.loadFile,
RenderingMWs.renderFile
);
}
protected static addGetPhotoThumbnail(app: Express): void {
app.get('/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Photos.join('|') + '))/thumbnail/:size?',
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Photo),
RenderingMWs.renderFile
);
}
protected static addGetVideoThumbnail(app: Express): void {
app.get('/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Videos.join('|') + '))/thumbnail/:size?',
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
ThumbnailGeneratorMWs.generateThumbnailFactory(ThumbnailSourceType.Video),
RenderingMWs.renderFile
);
}
protected static addGetVideoIcon(app: Express): void {
app.get('/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Videos.join('|') + '))/icon',
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
ThumbnailGeneratorMWs.generateIconFactory(ThumbnailSourceType.Video),
RenderingMWs.renderFile
);
}
protected static addGetImageIcon(app: Express): void {
app.get('/api/gallery/content/:mediaPath(*\.(' + SupportedFormats.Photos.join('|') + '))/icon',
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.normalizePathParam('mediaPath'),
AuthenticationMWs.authorisePath('mediaPath', false),
// specific part
GalleryMWs.loadFile,
ThumbnailGeneratorMWs.generateIconFactory(ThumbnailSourceType.Photo),
RenderingMWs.renderFile
);
}
protected static addSearch(app: Express): void {
app.get('/api/search/:searchQueryDTO(*)',
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Guest),
VersionMWs.injectGalleryVersion,
// specific part
GalleryMWs.search,
ThumbnailGeneratorMWs.addThumbnailInformation,
GalleryMWs.cleanUpGalleryResults,
RenderingMWs.renderResult
);
}
protected static addAutoComplete(app: Express): void {
app.get('/api/autocomplete/:text(*)',
// common part
AuthenticationMWs.authenticate,
AuthenticationMWs.authorise(UserRoles.Guest),
VersionMWs.injectGalleryVersion,
// specific part
GalleryMWs.autocomplete,
RenderingMWs.renderResult
);
}
}