import { type Ref, ref } from "vue"; import { getRemoteEntriesAt } from "@/components/Upload/utils"; import type { ListUriResponse, RemoteDirectory, RemoteFile } from "./types"; export function useFileSetSources(isBusy: Ref) { const pasteData = ref([] as string[][]); const tabularDatasetContents = ref([] as string[][]); const uris = ref([]); async function setRemoteFilesFolder(uri: string) { isBusy.value = true; const rawFiles = await getRemoteEntriesAt(uri); if (rawFiles) { const files: RemoteFile[] = (rawFiles as ListUriResponse).filter( (file: RemoteFile | RemoteDirectory) => file["class"] == "File", ) as RemoteFile[]; uris.value = files; } isBusy.value = false; } async function onFtp() { setRemoteFilesFolder("gxftp://"); } function setDatasetContents(contents: string[][]) { tabularDatasetContents.value = contents; } function setPasteTable(newValue: string[][]) { pasteData.value = newValue; } return { pasteData, tabularDatasetContents, uris, setRemoteFilesFolder, onFtp, setDatasetContents, setPasteTable, }; }