Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as functions from "firebase-functions/v1";
import { onRequest } from "firebase-functions/v2/https";
import { PNG } from "pngjs";
import { Canvas, Square } from "../../database/.types";
import { Color as PaletteColor, Palette } from "./palette";
Expand Down Expand Up @@ -37,9 +37,9 @@ function setColor(png: PNG, x: number, y: number, color: PaletteColor) {
png.data[index + 3] = color.a;
}

export const imagePng = functions
.runWith({ maxInstances: 1 })
.https.onRequest(async (request, response) => {
export const imagePng = onRequest(
{ maxInstances: 1, concurrency: 1 },
async (_request, response) => {
try {
const [depthSnapshot, canvasSnapshot] = await Promise.all([
database.ref("canvas").child(IMAGE_ID).child("depth").once("value"),
Expand All @@ -66,15 +66,22 @@ export const imagePng = functions
} catch (error) {
response.status(500).send(error);
}
});
}
);

export const historyGif = functions
.runWith({ memory: "2GB", timeoutSeconds: 540, maxInstances: 1 })
.https.onRequest(async (_request, response) => {
export const historyGif = onRequest(
{ memory: "4GiB", timeoutSeconds: 1080, maxInstances: 1, concurrency: 1 },
async (_request, response) => {
try {
const [depthSnapshot, historySnapshot] = await Promise.all([
database.ref("canvas").child(IMAGE_ID).child("depth").once("value"),
database.ref("canvas").child(IMAGE_ID).child("history").orderByChild("timestamp").limitToLast(100_000).once("value"),
database
.ref("canvas")
.child(IMAGE_ID)
.child("history")
.orderByChild("timestamp")
.limitToLast(100_000)
.once("value"),
]);
const depth = depthSnapshot.val() as Canvas["depth"];
const history = Object.values(
Expand All @@ -96,4 +103,5 @@ export const historyGif = functions
} catch (error) {
response.status(500).send(error);
}
});
}
);
Loading