CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tns-platform-declarations

Platform-specific TypeScript declarations for NativeScript for accessing native objects

84

1.23x
Overview
Eval results
Files

task.mdevals/scenario-10/

Image Gallery Downloader

Build a simple image gallery downloader that fetches multiple images from URLs and saves them to the local file system with metadata tracking.

Requirements

Your task is to implement a utility that:

  1. Downloads multiple images from a list of URLs asynchronously
  2. Saves each downloaded image to a specified directory on the local file system
  3. Creates a metadata file (JSON format) that records:
    • Original URL for each image
    • Local file path where the image was saved
    • Download status (success/failure)
    • Error message if the download failed
  4. Handles errors gracefully for individual downloads without stopping the entire batch
  5. Notifies when all downloads are complete

Specifications

Input

  • An array of image URLs (strings)
  • A target directory path where images should be saved
  • A metadata file path where the results should be written

Output

  • Downloaded image files saved to the target directory with sequential names (image_1.jpg, image_2.jpg, etc.)
  • A JSON metadata file containing the results of all download operations

Behavior

  • Downloads should be performed asynchronously to avoid blocking
  • Each download should have appropriate error handling
  • Failed downloads should not stop other downloads from proceeding
  • The metadata file should be written only after all downloads complete (successful or failed)
  • The metadata JSON should be UTF-8 encoded

Test Cases

  • Given three valid image URLs, downloads all three images and creates a metadata file with three success entries @test
  • Given two URLs where one is invalid (returns 404), downloads the valid image successfully and records the failure for the invalid URL in metadata @test
  • Given an empty array of URLs, creates a metadata file with an empty results array @test

@generates

API

/**
 * Configuration for the image gallery downloader
 */
export interface DownloadConfig {
  /** Array of image URLs to download */
  imageUrls: string[];
  /** Directory path where images should be saved */
  targetDirectory: string;
  /** File path where metadata JSON should be written */
  metadataPath: string;
}

/**
 * Result for a single image download operation
 */
export interface DownloadResult {
  /** Original image URL */
  url: string;
  /** Local file path where image was saved (or attempted) */
  localPath: string;
  /** Whether the download succeeded */
  success: boolean;
  /** Error message if download failed */
  error?: string;
}

/**
 * Downloads multiple images and saves them with metadata
 * @param config - Download configuration
 * @param onComplete - Callback invoked when all downloads finish
 */
export function downloadImageGallery(
  config: DownloadConfig,
  onComplete: (results: DownloadResult[]) => void
): void;

Dependencies { .dependencies }

tns-platform-declarations { .dependency }

Provides Android platform declarations for NativeScript, including async operations for image downloads and file writes.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-tns-platform-declarations

tile.json