Skip to content

Commit

Permalink
simpler scene zip generation iterator. Ensure fix #27
Browse files Browse the repository at this point in the history
  • Loading branch information
sdumetz committed Jun 12, 2024
1 parent dde9027 commit fb609f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions source/server/routes/api/v1/scenes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { HTTPError } from "../../../../utils/errors.js";
import { getHost, getUser, getVfs } from "../../../../utils/locals.js";
import { wrapFormat } from "../../../../utils/wrapAsync.js";
import { ZipEntry, zip } from "../../../../utils/zip/index.js";
import { once } from "events";

export default async function getScenes(req :Request, res :Response){
let vfs = getVfs(req);
Expand Down Expand Up @@ -130,11 +131,8 @@ export default async function getScenes(req :Request, res :Response){
// It would also allow for strong ETag generation, which would be desirable
res.status(200);
for await (let data of zip(getFiles())){
await new Promise<void>(resolve=>{
let again = res.write(data);
if(again) resolve();
else res.once("drain", resolve);
});
let again = res.write(data);
if(!again) await once(res, "drain");
}
res.end();
}
Expand Down
8 changes: 3 additions & 5 deletions source/server/routes/api/v1/scenes/scene/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getUserId, getVfs } from "../../../../../utils/locals.js";
import { wrapFormat } from "../../../../../utils/wrapAsync.js";
import { ZipEntry, zip } from "../../../../../utils/zip/index.js";
import { HTTPError } from "../../../../../utils/errors.js";
import { once } from "events";



Expand Down Expand Up @@ -56,11 +57,8 @@ export default async function getScene(req :Request, res :Response){

res.status(200);
for await (let data of zip(getFiles())){
await new Promise<void>(resolve=>{
let again = res.write(data);
if(again) resolve();
else res.once("drain", resolve);
});
let again = res.write(data);
if(!again) once(res, "drain");
}
res.end();
}
Expand Down

0 comments on commit fb609f9

Please sign in to comment.