Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a750ef916 | ||
|
|
452d84bff2 | ||
|
|
c75d4f81c3 | ||
|
|
e731e48cb8 | ||
|
|
7372aff0ff | ||
|
|
d2b6f4383c | ||
|
|
c723b28c3a | ||
|
|
cbd3f318d5 | ||
|
|
ed9c382356 |
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { keepPhotoAspect } from "./geometry.js";
|
||||
import { frameScore } from "./compose.js";
|
||||
import { cropTooHard, levelWithoutChopping, planFrame, type PlanSettings } from "./planFrame.js";
|
||||
|
||||
const settings: PlanSettings = {
|
||||
@@ -55,6 +56,39 @@ describe("planFrame", () => {
|
||||
expect(crop.params.aspect).toEqual([6000, 4000]);
|
||||
});
|
||||
|
||||
it("on a full-size file ranks the sharper frame and keeps a learnt crop tighter", () => {
|
||||
const person = { x0: 0.42, y0: 0.2, x1: 0.58, y1: 0.85, score: 0.9, sharpness: 1 };
|
||||
const at = (focus: number) => ({
|
||||
detections: { width: 600, height: 400, people: [{ ...person, focus }], balls: [] as [] },
|
||||
width: 6000,
|
||||
height: 4000,
|
||||
reportage: false,
|
||||
values: { "light.exposure": 0.2, "light.contrast": 10 },
|
||||
angle: 1.5,
|
||||
settings: { ...settings, toneStrength: 0.5, framing: "full" as const, minLongEdge: 2400 },
|
||||
});
|
||||
const soft = planFrame(at(100));
|
||||
const sharp = planFrame(at(900));
|
||||
expect(soft.composition).not.toBeNull();
|
||||
expect(sharp.composition).not.toBeNull();
|
||||
expect(frameScore(at(900).detections, sharp.composition)).toBeGreaterThan(frameScore(at(100).detections, soft.composition));
|
||||
const widthOf = (planned: ReturnType<typeof planFrame>) => {
|
||||
const crop = planned.ops.find((op) => op.command === "crop.set");
|
||||
if (!crop || crop.command !== "crop.set") return 1;
|
||||
return crop.params.rect.x1 - crop.params.rect.x0;
|
||||
};
|
||||
const plain = widthOf(planFrame(at(300)));
|
||||
const learnt = widthOf(planFrame({ ...at(300), cropFactor: 0.84 }));
|
||||
expect(learnt).toBeLessThan(plain);
|
||||
// A uniform shrink is stored as a body cut. If that cut would take the feet, the scale still applies.
|
||||
const fromCut = widthOf(planFrame({
|
||||
...at(300),
|
||||
cropFactor: 0.84,
|
||||
cropBias: { dx: 0, dy: 0, scale: 0.84, dAngle: 0, cut: 0.935, head: 0.067, sides: 0 },
|
||||
}));
|
||||
expect(fromCut).toBeLessThan(plain);
|
||||
});
|
||||
|
||||
it("crops one clear person in reportage and ignores a learnt sports cut", () => {
|
||||
const person = { x0: 0.35, y0: 0.28, x1: 0.52, y1: 0.72 };
|
||||
const planned = planFrame({
|
||||
|
||||
@@ -210,9 +210,11 @@ export function planFrame(input: {
|
||||
}
|
||||
if (bias && typeof bias.cut === "number") {
|
||||
// The photographer's cut on the body (legs, head, arms), not a uniform shrink.
|
||||
// It must not chop a player this photograph had kept whole.
|
||||
// It must not chop a player this photograph had kept whole. When the cut would,
|
||||
// the scale still applies: a tighter frame that keeps the player inside.
|
||||
const placed = frameOnSubject(composition.rect, composition.subject, bias);
|
||||
if (!chopsKeptPlayer(composition.rect, placed, composition.subject)) rect = placed;
|
||||
else if (factor && factor !== 1) rect = factor < 1 ? tighter(composition.rect, composition.subject, factor) : biasCrop(composition.rect, composition.subject, { dx: bias.dx, dy: bias.dy, scale: factor });
|
||||
if (bias.dx) {
|
||||
const w = rect.x1 - rect.x0;
|
||||
const x0 = Math.min(Math.max(0, rect.x0 + bias.dx), 1 - w);
|
||||
|
||||
@@ -388,6 +388,17 @@ export async function registerShopAdminRoutes(app: FastifyInstance, deps: { db:
|
||||
return { orders: views };
|
||||
});
|
||||
|
||||
/** Payment collected outside the shop. Delivery starts; the admin owns handing the work over. */
|
||||
app.post("/v1/orders/:id/payment-received", { preHandler: authenticate }, async (req) => {
|
||||
const { id } = IdParams.parse(req.params);
|
||||
const order = await db.order.findUnique({ where: { id } });
|
||||
if (!order) throw notFound("order_not_found");
|
||||
await requireMembership(db, req, order.organizationId, "ADMIN");
|
||||
if (order.status !== "PENDING") throw badRequest("order_not_pending");
|
||||
await shop.markPaid(id, "manual");
|
||||
return shop.orderView(id, null);
|
||||
});
|
||||
|
||||
app.post("/v1/orders/:id/items/:itemId/shipped", { preHandler: authenticate }, async (req) => {
|
||||
const { id, itemId } = z.object({ id: z.uuid(), itemId: z.uuid() }).parse(req.params);
|
||||
const order = await db.order.findUnique({ where: { id }, include: { items: { where: { id: itemId } } } });
|
||||
|
||||
@@ -497,7 +497,12 @@ export class ShopService {
|
||||
await this.markPaid(order.id, press ? "press" : "free");
|
||||
return { order: await this.orderView(order.id, order.accessToken), checkoutUrl: null, token: order.accessToken };
|
||||
}
|
||||
if (!org.stripeSecretSealed || !secrets) throw new ShopError("payments_not_configured", 503);
|
||||
// No payment method: the order is still accepted. An admin collects the money out of band
|
||||
// and only then does delivery start. Invoicing stays off until a provider is connected.
|
||||
if (!org.stripeSecretSealed || !secrets) {
|
||||
this.deps.log.info({ orderId: order.id }, "shop: order accepted without a payment method");
|
||||
return { order: await this.orderView(order.id, order.accessToken), checkoutUrl: null, token: order.accessToken };
|
||||
}
|
||||
const checkout = await createCheckout(
|
||||
secrets.open(org.stripeSecretSealed),
|
||||
{
|
||||
|
||||
@@ -218,6 +218,10 @@ describe("learning from corrections", () => {
|
||||
});
|
||||
});
|
||||
|
||||
/** The JPEG stays 600 px so the suite does not time out. The planner reads this size, which clears the 2400 px floor. */
|
||||
const PHOTO_W = 6000;
|
||||
const PHOTO_H = 4000;
|
||||
|
||||
describe("autopilot", () => {
|
||||
let ctx: TestContext;
|
||||
let dir: string;
|
||||
@@ -258,7 +262,7 @@ describe("autopilot", () => {
|
||||
const file = path.join(dir, `IMG_${n}.JPG`);
|
||||
await writeFile(file, data);
|
||||
const out = await ingest.ingest(file, { organizationId: orgId, userId, source, originalName: `IMG_${n}.JPG`, eventId });
|
||||
await ctx.db.photo.update({ where: { id: out.photoId }, data: { capturedAt: new Date(1_800_000_000_000 + at), cameraSerial: "R1-001" } });
|
||||
await ctx.db.photo.update({ where: { id: out.photoId }, data: { capturedAt: new Date(1_800_000_000_000 + at), cameraSerial: "R1-001", width: PHOTO_W, height: PHOTO_H } });
|
||||
return out.photoId;
|
||||
}
|
||||
|
||||
@@ -351,7 +355,7 @@ describe("autopilot", () => {
|
||||
expect(await chosen()).toEqual({ [w0a]: true, [w0b]: false, [w2a]: true, [w2b]: true, [w2c]: false });
|
||||
// The burst picks are still flagged for the photographer.
|
||||
expect((await ctx.db.photo.findUniqueOrThrow({ where: { id: w2c } })).flag).toBe("PICK");
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it("two clients: gallery gets the best moments; rest gets seconds and every other pick (warm-up included)", async () => {
|
||||
const { eventId, orgId, userId } = await setup();
|
||||
@@ -393,7 +397,7 @@ describe("autopilot", () => {
|
||||
await service.decideBursts(new Date(start.getTime() + 8 * 60_000));
|
||||
expect(to(record)).toEqual([a1]);
|
||||
expect(to(fap).sort()).toEqual([warm, a2, b1, b2].sort());
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it("never edits over a person's edit (made on the desktop app before the photo was uploaded)", async () => {
|
||||
const { orgId, userId, eventId } = await setup();
|
||||
@@ -430,7 +434,7 @@ describe("autopilot", () => {
|
||||
await autopilot.decideBursts(new Date(Date.now() + 20_000));
|
||||
const edits = await ctx.db.photoEdit.findMany({ where: { photoId: id }, orderBy: { seq: "asc" } });
|
||||
const values = (edits[0]!.command as { params: { values: Record<string, number> } }).params.values;
|
||||
expect(values).toMatchObject({ "wb.temp": 5200, "wb.tint": 4, "light.exposure": 0.3, "light.contrast": 15, "color.vibrance": 18, "detail.sharpenAmount": 38.5, "detail.nrLuminance": 22 });
|
||||
expect(values).toMatchObject({ "wb.temp": 5200, "wb.tint": 4, "light.exposure": 0.3, "light.contrast": 15, "color.vibrance": 18, "detail.sharpenAmount": 31, "detail.nrLuminance": 22 });
|
||||
});
|
||||
|
||||
it("leaves events without autopilot alone", async () => {
|
||||
@@ -454,7 +458,7 @@ describe("autopilot", () => {
|
||||
const shrink = (a: number, b: number) => [a + (b - a) * 0.08, b - (b - a) * 0.08] as const;
|
||||
const [x0, x1] = shrink(r.x0, r.x1);
|
||||
const [y0, y1] = shrink(r.y0, r.y1);
|
||||
await develop.append(id, userId, { clientId: "web-1", ops: [{ opId: `h-${id}-1`, command: { command: "develop.set", params: { values: { "light.exposure": 0.5 } } } }, { opId: `h-${id}-2`, command: { command: "crop.set", params: { rect: { x0, y0, x1, y1 }, angle: 1.5, aspect: [600, 400] } } }] });
|
||||
await develop.append(id, userId, { clientId: "web-1", ops: [{ opId: `h-${id}-1`, command: { command: "develop.set", params: { values: { "light.exposure": 0.5 } } } }, { opId: `h-${id}-2`, command: { command: "crop.set", params: { rect: { x0, y0, x1, y1 }, angle: 1.5, aspect: [PHOTO_W, PHOTO_H] } } }] });
|
||||
expect(await recordCorrection(ctx.db, id)).toBe(true);
|
||||
}
|
||||
// Untouched photos and the autopilot's own edits teach nothing.
|
||||
@@ -480,7 +484,7 @@ describe("autopilot", () => {
|
||||
const gone = await ctx.app.inject({ method: "DELETE", url: `/v1/orgs/${orgId}/autopilot/style`, headers: bearer(token) });
|
||||
expect(gone.json()).toEqual({ forgotten: 5 });
|
||||
expect(await learntStyle(ctx.db, orgId, userId)).toBeNull();
|
||||
});
|
||||
}, 60_000);
|
||||
|
||||
it("tells the learner when a person (not the autopilot) edits", async () => {
|
||||
const { orgId, userId, eventId } = await setup();
|
||||
|
||||
@@ -212,6 +212,31 @@ describe("shop", () => {
|
||||
expect((await ctx.db.order.findUniqueOrThrow({ where: { id: order.id } })).status).toBe("FULFILLED");
|
||||
});
|
||||
|
||||
it("accepts an order when Stripe is off, and delivery waits until an admin records the payment", async () => {
|
||||
const s = await setup();
|
||||
expect((await s.api("PUT", `/v1/orgs/${s.orgId}/shop-settings`, { stripeSecretKey: "", stripeWebhookSecret: "" })).statusCode).toBe(200);
|
||||
const g = await gallery(s, { title: "Sem Stripe" });
|
||||
const created = await pub("POST", "/v1/public/orders", {
|
||||
gallery: g.slug,
|
||||
email: "[email protected]",
|
||||
name: "Ana Costa",
|
||||
country: "PT",
|
||||
items: [{ photoId: s.photos[0], productId: s.digital.id, quantity: 1 }],
|
||||
});
|
||||
expect(created.statusCode).toBe(201);
|
||||
const body = created.json() as { order: { id: string; status: string; totalCents: number }; checkoutUrl: string | null };
|
||||
expect(body.checkoutUrl).toBeNull();
|
||||
expect(body.order).toMatchObject({ status: "PENDING" });
|
||||
expect(body.order.totalCents).toBeGreaterThan(0);
|
||||
expect(await shop.claimDownloads(5)).toEqual([]);
|
||||
|
||||
const paid = await s.api("POST", `/v1/orders/${body.order.id}/payment-received`);
|
||||
expect(paid.statusCode).toBe(200);
|
||||
expect(paid.json()).toMatchObject({ status: "PAID" });
|
||||
const [itemId] = await shop.claimDownloads(5);
|
||||
expect(itemId).toEqual(expect.any(String));
|
||||
});
|
||||
|
||||
it("reverse-charges VAT for EU businesses with a valid number, and gives free galleries away", async () => {
|
||||
const s = await setup();
|
||||
const g = await gallery(s, { title: "Clube" });
|
||||
|
||||
@@ -1113,6 +1113,8 @@ export const t = {
|
||||
orderStatus: { PENDING: "por pagar", PAID: "paga", FULFILLED: "concluída", CANCELLED: "cancelada", REFUNDED: "reembolsada" },
|
||||
itemStatus: { PENDING: "a preparar", RUNNING: "a preparar", READY: "pronto", SHIPPED: "enviado", FAILED: "falhou" },
|
||||
markShipped: "Marcar enviada",
|
||||
collectPayment: "Pagamento recebido",
|
||||
confirmCollectPayment: "Recebeste o pagamento fora da loja? A encomenda passa a paga e ficas responsável por entregar o trabalho.",
|
||||
reverseCharge: "Autoliquidação",
|
||||
noOrders: "Sem encomendas.",
|
||||
productsHelp: "Preços com IVA incluído. JPEG: tamanho do lado maior (0 = original). Impressões: tamanho e prazo de envio.",
|
||||
|
||||
@@ -5,6 +5,10 @@ import { EventsPanel } from "./EventsPanel.js";
|
||||
import { PhotoContextMenu } from "./PhotoContextMenu.js";
|
||||
|
||||
function event(id: string, title: string): EventSummary {
|
||||
const startsAt = new Date(Date.now() - 86_400_000);
|
||||
const iso = startsAt.toISOString();
|
||||
const at = (offsetMs: number) =>
|
||||
new Date(startsAt.getTime() + offsetMs).toISOString();
|
||||
return {
|
||||
id,
|
||||
organizationId: "org",
|
||||
@@ -20,9 +24,9 @@ function event(id: string, title: string): EventSummary {
|
||||
competitionCode: null,
|
||||
round: null,
|
||||
matchNumber: null,
|
||||
startsAt: "2026-11-21T10:56:00.000Z",
|
||||
ingestFrom: "2026-11-21T08:56:00.000Z",
|
||||
ingestUntil: "2026-11-21T14:56:00.000Z",
|
||||
startsAt: iso,
|
||||
ingestFrom: at(-2 * 3_600_000),
|
||||
ingestUntil: at(4 * 3_600_000),
|
||||
iptcTemplate: {},
|
||||
archivedAt: null,
|
||||
photographers: [],
|
||||
|
||||
@@ -387,6 +387,16 @@ function Orders({ orgId, isAdmin }: { orgId: string; isAdmin: boolean }) {
|
||||
{o.invoice.number}
|
||||
</a>
|
||||
)}
|
||||
{isAdmin && o.status === "PENDING" && !o.checkoutUrl && o.totalCents > 0 && (
|
||||
<button
|
||||
className="ml-3 underline"
|
||||
onClick={() => {
|
||||
if (window.confirm(t.shop.confirmCollectPayment)) void api.recordPayment(o.id).then(replace);
|
||||
}}
|
||||
>
|
||||
{t.shop.collectPayment}
|
||||
</button>
|
||||
)}
|
||||
{isAdmin && (o.status === "PAID" || o.status === "FULFILLED") && (
|
||||
<button
|
||||
className="ml-3 underline"
|
||||
|
||||
@@ -39,7 +39,9 @@ export default async function OrderPage({ params, searchParams }: { params: Prom
|
||||
</header>
|
||||
{order.status === "PENDING" && (
|
||||
<p className="notice" style={{ marginTop: 24 }}>
|
||||
Assim que o pagamento for confirmado (por Multibanco pode demorar algumas horas) as fotos aparecem aqui e enviamos-te um email.
|
||||
{order.checkoutUrl
|
||||
? "Assim que o pagamento for confirmado (por Multibanco pode demorar algumas horas) as fotos aparecem aqui e enviamos-te um email."
|
||||
: "A encomenda ficou registada. O pagamento combina-se à parte; quando estiver confirmado, as fotos aparecem aqui e enviamos-te um email."}
|
||||
{order.checkoutUrl && (
|
||||
<>
|
||||
{" "}
|
||||
|
||||
@@ -591,6 +591,11 @@ export class ApiClient {
|
||||
return this.request<OrderView>("POST", `/v1/orders/${orderId}/items/${itemId}/shipped`);
|
||||
}
|
||||
|
||||
/** Payment taken outside the shop. The caller is responsible for delivering the work. */
|
||||
recordPayment(orderId: string) {
|
||||
return this.request<OrderView>("POST", `/v1/orders/${orderId}/payment-received`);
|
||||
}
|
||||
|
||||
retryOrder(orderId: string) {
|
||||
return this.request<OrderView>("POST", `/v1/orders/${orderId}/retry`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user