getPropertyFileUrl

image / file プロパティの値(ローカル絶対パス)から、壁紙 webview がロードできる URL を組み立てます。Fluxlay デスクトップアプリの GET /v1/file エンドポイントが配信を担当し、現在その壁紙の image / file プロパティに割り当てられているパスのみが許可されます。

インポート

import { getPropertyFileUrl } from "@fluxlay/react";

シグネチャ

function getPropertyFileUrl(path: string | null | undefined): string | null;

引数

引数説明
pathstring | null | undefineduseProperties() で取得した image / file プロパティ値。

戻り値

<img src><video src> 等で利用可能な URL 文字列。path が空 / null / undefined の場合は null を返します。

使い方

import { getPropertyFileUrl, useProperties } from "@fluxlay/react";
 
function Wallpaper() {
  const { customLogo } = useProperties<{ customLogo: string | null }>();
  const url = getPropertyFileUrl(customLogo);
  return url ? <img src={url} alt="logo" /> : null;
}

備考

  • 戻り値の URL は http://127.0.0.1:<port>/v1/file?window_label=<label>&path=<path> の形式で、現在の URL から fluxlay_portwindow_label のクエリを引き継ぎます。
  • バックエンドはこの壁紙の image / file プロパティに現在割り当てられているパスのみを 200 で返します。許可リスト外のパスを直接渡しても 403 になります。
  • 壁紙が Fluxlay デスクトップアプリ外で動いている場合 (例: 単体の Web プレビュー) はファイル取得不可能なので、URL は組み立てられても fetch 自体は失敗します。