import { DatasourceAction, ReadShape } from "./action.js";

//#region src/record-image.d.ts

/**
 * Answers an app route with the image in one field of one record, for link
 * previews and search engines. An attachment URL stops working within hours,
 * and they keep an image URL for weeks. So a page's `og:image` and structured
 * data point to this route, while the page's own `<img>` keeps the URL its
 * loader read.
 *
 * The route's one path parameter is the record id, plain or as `recordSlug`
 * made it. The handler reads the record as a signed-out visitor and sends the
 * large thumbnail of the field's first image, else the image itself. It keeps
 * the image for a day. It answers 404 when the query is not open to signed-out
 * visitors, when they cannot read the record, when the field has no image, for
 * an image over 5 MB, and for an image that is not on a public host over HTTPS.
 * It keeps a 404 for an hour.
 *
 * @example
 * // src/routes/images/bikes/$bikeId.ts
 * export const Route = createFileRoute("/images/bikes/$bikeId")({
 *   server: { handlers: { GET: recordImage({ query: bikesQuery, field: "photo" }) } },
 * })
 */
declare function recordImage<TShape extends ReadShape>(source: {
  query: DatasourceAction<TShape>;
  field: keyof TShape["fields"] & string;
}): (ctx: {
  request: Request;
  params: Record<string, string>;
}) => Promise<Response>;
//#endregion
export { recordImage };