Skip to content

nexscope-ai/nexscope-ecommerce-skills / ecommerce-maidalv-product-tro-detection

ecommerce.maidalv-product-tro-detection

Verified

Assess product imagery for TRO, trademark, patent, and copyright infringement risk. Use this skill when the user asks for this exact ecommerce workflow, analysis, data lookup, or deliverable.

FileKindSize
SKILL.mdskill md5.8 KB
manifest.jsonconfig653 B
references/api.jsonconfig1.1 KB
references/api.mdmarkdown3.8 KB
references/credentials.mdmarkdown943 B
references/testing.mdmarkdown1.0 KB
references/workflow.mdmarkdown1.2 KB
scripts/maidalv_check_api_flash.pyscript11.2 KB
scripts/upload_image.pyscript5.4 KB

scripts/upload_image.py

View on GitHub
#!/usr/bin/env python3

import sys as _nexscope_help_sys
if "--help" in _nexscope_help_sys.argv or "-h" in _nexscope_help_sys.argv:
    print('Usage: python upload_image.py [arguments]')
    raise SystemExit(0)

_nexscope_required_confirmations = {"--confirm", "--confirm-mutation"}
_nexscope_missing_confirmations = _nexscope_required_confirmations.difference(_nexscope_help_sys.argv)
if _nexscope_missing_confirmations:
    print("Mutation blocked: pass both --confirm and --confirm-mutation.", file=_nexscope_help_sys.stderr)
    raise SystemExit(2)
_nexscope_help_sys.argv = [arg for arg in _nexscope_help_sys.argv if arg not in _nexscope_required_confirmations]

"""
Upload Local Image - Nexscope Skill
Uploads a local image file to Nexscope OSS and returns a publicly accessible URL.

Steps:
  1. Request a presigned PUT URL from the Nexscope OSS gateway
  2. Upload the local file to the presigned URL
  3. Return the public URL (valid for 24 hours)

Usage:
  python upload_image.py /path/to/local/image.png
"""

import json
import os
import sys
from urllib.request import urlopen, Request
from urllib.error import HTTPError, URLError

_API_BASE = (os.environ.get("NEXSCOPE_PROXY_BASE") or "").rstrip("/")
PRESIGN_URL = f"{_API_BASE}/api/v1/tools/research/oss/file/presignedPut"

CONTENT_TYPE_MAP = {
    "jpg": "image/jpeg",
    "jpeg": "image/jpeg",
    "png": "image/png",
    "gif": "image/gif",
    "webp": "image/webp",
    "heic": "image/heic",
}


def get_api_key():
    """Provider-neutral implementation documentation."""
    key = os.environ.get("NEXSCOPE_API_KEY") or os.environ.get("NEXSCOPE_API_KEY")
    if not key:
        print(
            "API Key value",
            file=sys.stderr,
        )
        sys.exit(1)
    return key


def get_presigned_url(content_type: str, file_extension: str) -> str:
    """Request a presigned PUT URL from the OSS gateway."""
    api_key = get_api_key()
    data = json.dumps({
        "contentType": content_type,
        "fileExtension": file_extension,
    }).encode("utf-8")

    req = Request(
        PRESIGN_URL,
        data=data,
        headers={
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
            "User-Agent": "Nexscope-Skill/1.0",
        },
        method="POST",
    )

    try:
        with urlopen(req, timeout=30) as response:
            result = json.loads(response.read().decode("utf-8"))
    except HTTPError as e:
        body = e.read().decode("utf-8") if e.fp else ""
        print(f"Failed to get presigned URL: HTTP {e.code}: {e.reason}\n{body}", file=sys.stderr)
        sys.exit(1)
    except URLError as e:
        print(f"Connection failed: {e.reason}", file=sys.stderr)
        sys.exit(1)

    if not isinstance(result, dict) or type(result.get("code")) is not int:
        print("Invalid Nexscope response envelope", file=sys.stderr)
        sys.exit(1)
    if result["code"] != 0:
        print(f"API error: {result.get('msg') or 'unknown error'}", file=sys.stderr)
        sys.exit(1)
    business = result.get("data")
    url = business.get("url") if isinstance(business, dict) else None
    if not isinstance(url, str) or not url.startswith("https://"):
        print("Upload service response is missing a valid HTTPS URL", file=sys.stderr)
        sys.exit(1)
    return url


def upload_file(presigned_url: str, file_path: str, content_type: str):
    """Upload the local file to the presigned OSS URL via HTTP PUT."""
    with open(file_path, "rb") as f:
        file_data = f.read()

    req = Request(
        presigned_url,
        data=file_data,
        headers={
            "Content-Type": content_type,
            "x-oss-object-acl": "public-read",
        },
        method="PUT",
    )

    try:
        with urlopen(req, timeout=120) as response:
            if response.status not in (200, 201):
                print(f"Upload failed with status: {response.status}", file=sys.stderr)
                sys.exit(1)
    except HTTPError as e:
        body = e.read().decode("utf-8") if e.fp else ""
        print(f"Upload failed: HTTP {e.code}: {e.reason}\n{body}", file=sys.stderr)
        sys.exit(1)
    except URLError as e:
        print(f"Upload connection failed: {e.reason}", file=sys.stderr)
        sys.exit(1)


def extract_public_url(presigned_url: str) -> str:
    """Extract the base public URL by stripping query parameters."""
    return presigned_url.split("?")[0]


def main():
    if len(sys.argv) < 2:
        print(
            "Usage: upload_image.py <local_image_path>\n"
            "Example: upload_image.py /path/to/product.png",
            file=sys.stderr,
        )
        sys.exit(1)

    file_path = sys.argv[1]

    if not os.path.isfile(file_path):
        print(f"File not found: {file_path}", file=sys.stderr)
        sys.exit(1)

    extension = os.path.splitext(file_path)[1].lstrip(".").lower()
    content_type = CONTENT_TYPE_MAP.get(extension)
    if not content_type:
        print(
            f"Unsupported image format: .{extension}\n"
            f"Supported formats: {', '.join(CONTENT_TYPE_MAP.keys())}",
            file=sys.stderr,
        )
        sys.exit(1)

    # Step 1: Get presigned URL
    presigned_url = get_presigned_url(content_type, extension)

    # Step 2: Upload file
    upload_file(presigned_url, file_path, content_type)

    # Step 3: Output public URL
    public_url = extract_public_url(presigned_url)
    print(json.dumps({"url": public_url}, indent=2, ensure_ascii=False))


if __name__ == "__main__":
    main()
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall