tangled
alpha
login
or
join now
ptr.pet
/
wisp.place-monorepo
forked from
nekomimi.pet/wisp.place-monorepo
0
fork
atom
Monorepo for Wisp.place. A static site hosting service built on top of the AT Protocol.
0
fork
atom
overview
issues
pulls
pipelines
on the hosting service, unzip compressed types
@nekomimi.pet
4 months ago
dc0c0bd8
7693734e
+47
-1
1 changed file
expand all
collapse all
unified
split
hosting-service
src
server.ts
+47
-1
hosting-service/src/server.ts
···
51
51
}
52
52
53
53
if (meta.encoding === 'gzip' && meta.mimeType) {
54
54
-
// Serve gzipped content with proper headers
54
54
+
// Don't serve already-compressed media formats with Content-Encoding: gzip
55
55
+
// These formats (video, audio, images) are already compressed and the browser
56
56
+
// can't decode them if we add another layer of compression
57
57
+
const alreadyCompressedTypes = [
58
58
+
'video/', 'audio/', 'image/jpeg', 'image/jpg', 'image/png',
59
59
+
'image/gif', 'image/webp', 'application/pdf'
60
60
+
];
61
61
+
62
62
+
const isAlreadyCompressed = alreadyCompressedTypes.some(type =>
63
63
+
meta.mimeType.toLowerCase().startsWith(type)
64
64
+
);
65
65
+
66
66
+
if (isAlreadyCompressed) {
67
67
+
// Decompress the file before serving
68
68
+
console.log(`[DEBUG SERVE] ${requestPath}: decompressing already-compressed media type`);
69
69
+
const { gunzipSync } = await import('zlib');
70
70
+
const decompressed = gunzipSync(content);
71
71
+
console.log(`[DEBUG SERVE] ${requestPath}: decompressed from ${content.length} to ${decompressed.length} bytes`);
72
72
+
return new Response(decompressed, {
73
73
+
headers: {
74
74
+
'Content-Type': meta.mimeType,
75
75
+
},
76
76
+
});
77
77
+
}
78
78
+
79
79
+
// Serve gzipped content with proper headers (for HTML, CSS, JS, etc.)
55
80
console.log(`[DEBUG SERVE] ${requestPath}: serving as gzipped with Content-Encoding header`);
56
81
return new Response(content, {
57
82
headers: {
···
154
179
// Non-HTML files: serve gzipped content as-is with proper headers
155
180
const content = readFileSync(cachedFile);
156
181
if (isGzipped) {
182
182
+
// Don't serve already-compressed media formats with Content-Encoding: gzip
183
183
+
const alreadyCompressedTypes = [
184
184
+
'video/', 'audio/', 'image/jpeg', 'image/jpg', 'image/png',
185
185
+
'image/gif', 'image/webp', 'application/pdf'
186
186
+
];
187
187
+
188
188
+
const isAlreadyCompressed = alreadyCompressedTypes.some(type =>
189
189
+
mimeType.toLowerCase().startsWith(type)
190
190
+
);
191
191
+
192
192
+
if (isAlreadyCompressed) {
193
193
+
// Decompress the file before serving
194
194
+
const { gunzipSync } = await import('zlib');
195
195
+
const decompressed = gunzipSync(content);
196
196
+
return new Response(decompressed, {
197
197
+
headers: {
198
198
+
'Content-Type': mimeType,
199
199
+
},
200
200
+
});
201
201
+
}
202
202
+
157
203
return new Response(content, {
158
204
headers: {
159
205
'Content-Type': mimeType,