import { z } from "zod";
|
import type { ProviderConfig } from "@humansignal/app-common/blocks/StorageProviderForm/types/provider";
|
import { IconFolderOpen } from "@humansignal/icons";
|
import { Alert, AlertDescription, AlertTitle } from "@humansignal/shad/components/ui/alert";
|
|
const localFilesDocumentRoot =
|
typeof window === "undefined" ? undefined : window.APP_SETTINGS?.local_files_document_root;
|
const localFilesServingEnabled =
|
typeof window === "undefined" ? true : window.APP_SETTINGS?.local_files_serving_enabled !== false;
|
const isCommunityEdition =
|
typeof window === "undefined" ? false : window.APP_SETTINGS?.version?.edition === "Community";
|
const trimTrailingSeparators = (value?: string) => value?.replace(/[/\\]+$/, "");
|
const defaultPathExample = localFilesDocumentRoot
|
? `${trimTrailingSeparators(localFilesDocumentRoot)}/your-subdirectory`
|
: undefined;
|
|
const pathSchema = defaultPathExample
|
? z.string().min(1, "Path is required").default(defaultPathExample)
|
: z.string().min(1, "Path is required");
|
|
const LocalFilesServingWarning = () => {
|
if (localFilesServingEnabled) return null;
|
return (
|
<>
|
<Alert variant="destructive">
|
<AlertTitle>Local file serving is disabled</AlertTitle>
|
<AlertDescription>
|
Set the "LOCAL_FILES_SERVING_ENABLED" environment variable to "true" and restart Label Studio to enable Local
|
Files storage. See the documentation for details:{" "}
|
<a href="https://labelstud.io/guide/storage.html#Local-storage" target="_blank" rel="noreferrer">
|
Local Storage documentation
|
</a>
|
{isCommunityEdition && (
|
<Alert variant="info">
|
<AlertDescription>
|
<p>
|
Tip: Create a "mydata" or "label-studio-data" directory next to the command you use to run Label
|
Studio and local file serving will be enabled automatically.
|
</p>
|
<p>
|
If you run the Docker image, the app starts in "/label-studio", so you can bind-mount your host folder
|
to "/label-studio/mydata" or "/label-studio/label-studio-data" inside the container to enable local
|
file serving without extra configuration.
|
</p>
|
</AlertDescription>
|
</Alert>
|
)}
|
</AlertDescription>
|
</Alert>
|
</>
|
);
|
};
|
|
export const localFilesProvider: ProviderConfig = {
|
name: "localfiles",
|
title: "本地文件",
|
description: "配置您的本地文件存储连接以及所有必需的 Label Studio 设置",
|
icon: () => (
|
<IconFolderOpen
|
width={40}
|
height={40}
|
style={{
|
color: "var(--color-accent-canteloupe-base)",
|
filter: "drop-shadow(0px 0px 12px var(--color-accent-canteloupe-base))",
|
}}
|
/>
|
),
|
fields: [
|
{
|
name: "serving_warning",
|
type: "message",
|
content: LocalFilesServingWarning,
|
},
|
{
|
name: "path",
|
type: "text",
|
label: "绝对本地路径",
|
required: true,
|
placeholder: defaultPathExample || "/data/my-folder/subdirectory",
|
schema: pathSchema,
|
defaultValue: defaultPathExample,
|
description: `此路径必须是 Label Studio 运行所在的宿主机上的绝对路径,并且必须以 \n"${localFilesDocumentRoot}" (LOCAL_FILES_DOCUMENT_ROOT) 开头。`,
|
},
|
],
|
layout: [{ fields: ["serving_warning"] }, { fields: ["path"] }],
|
};
|
|
export default localFilesProvider;
|