Fix bug in /api/readFromArchive
Well, two bugs: one with URL encoding, and another minor one where I forgot to return after ending the request with 404, oops lol :p
This commit is contained in:
parent
5e6939309a
commit
861f3ab881
1 changed files with 9 additions and 1 deletions
|
@ -47,7 +47,14 @@ async function handle(req, res) {
|
|||
// So basically, just the host, path, and query string; no protocol or hash.
|
||||
// (Most archive keys don't have a query string, but some do! And don't
|
||||
// worry, `parsedUrl.search` will just be empty if there's no query string.)
|
||||
const archiveKey = `${parsedUrl.host}${parsedUrl.pathname}${parsedUrl.search}`;
|
||||
//
|
||||
// The archive key doesn't include URL encoding (e.g. it has " " instead of
|
||||
// "%20"), but the URI object gives us encoded paths and queries for safety
|
||||
// by default, so we need to decode them when constructing the key!
|
||||
const archiveKey =
|
||||
parsedUrl.host +
|
||||
decodeURIComponent(parsedUrl.pathname) +
|
||||
decodeURIComponent(parsedUrl.search);
|
||||
let archiveRes;
|
||||
try {
|
||||
archiveRes = await fetchFromArchive(archiveKey);
|
||||
|
@ -55,6 +62,7 @@ async function handle(req, res) {
|
|||
if (error.Code === "NoSuchKey") {
|
||||
res.status(404);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
res.end(`Error loading file from archive: ${error.message}`);
|
||||
|
|
Loading…
Reference in a new issue