Skip to content

Add Image.fromHash() factory method #89

Description

@bass9030

Description of problem

Before 9.0.0, Image and ImageResolver were separate. If you only had an image hash, you could resolve the image URL by passing the hash to ImageResolver:

let imageURI = await hitomi.ImageResolver.getImageUri({
    hash: hash,
    hasAvif: true,
    hasWebp: true,
    hasJxl: false,
}, "avif");

Since 9.0.0, ImageResolver has been merged into Image. URLs can now only be resolved through methods such as Image.resolveUrl() or Image.fetch(). However, the Image constructor is marked as @internal, so there is currently no public way to resolve an image URL when only the image hash is available.

Description of idea

It would be helpful to expose a public API such as Image.fromHash() (or an equivalent factory method) that creates an Image instance from only the image hash. This would restore the previous capability without exposing the internal constructor.

// example
let hash = "somthinghash1234";
let hasAvif = true;
let image = hitomi.Image.fromHash(hash, hasAvif);
let imageBuffer = await image.fetch(Extension.Avif, false);

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions